libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
UI.h
Go to the documentation of this file.
1#pragma once
2#include <initializer_list>
3#include "UiEventQueue.h"
4#include "../util/Stack.h"
5
6namespace daisy
7{
8class UI;
9
15{
17 left = 0,
19 right,
21 up,
23 down
24};
25
67
69
74class UiPage
75{
76 public:
77 UiPage() : parent_(nullptr) {}
78
79 virtual ~UiPage() {}
80
86 virtual bool IsOpaque(const UiCanvasDescriptor& display)
87 {
88 (void)(display); // silence unused variable warnings
89 return true;
90 }
91
93 bool IsActive() { return parent_ != nullptr; }
94
98 virtual void OnUserInteraction() {}
99
103 void Close();
104
115 {
116 (void)(numberOfPresses); // silence unused variable warnings
117 (void)(isRetriggering); // silence unused variable warnings
118 return true;
119 }
120
131 {
132 (void)(numberOfPresses); // silence unused variable warnings
133 (void)(isRetriggering); // silence unused variable warnings
134 return true;
135 }
136
149 bool isRetriggering)
150 {
151 (void)(arrowType); // silence unused variable warnings
152 (void)(numberOfPresses); // silence unused variable warnings
153 (void)(isRetriggering); // silence unused variable warnings
154 return true;
155 }
156
167 {
168 (void)(numberOfPresses); // silence unused variable warnings
169 (void)(isRetriggering); // silence unused variable warnings
170 return true;
171 }
172
184 virtual bool
186 {
187 (void)(buttonID); // silence unused variable warnings
188 (void)(numberOfPresses); // silence unused variable warnings
189 (void)(isRetriggering); // silence unused variable warnings
190 return true;
191 }
192
199 {
200 (void)(turns); // silence unused variable warnings
201 (void)(stepsPerRevolution); // silence unused variable warnings
202 return true;
203 }
204
212 {
213 (void)(turns); // silence unused variable warnings
214 (void)(stepsPerRevolution); // silence unused variable warnings
215 return true;
216 }
217
227 {
228 (void)(encoderID); // silence unused variable warnings
229 (void)(turns); // silence unused variable warnings
230 (void)(stepsPerRevolution); // silence unused variable warnings
231 return true;
232 }
233
239 {
240 (void)(isCurrentlyActive); // silence unused variable warnings
241 return true;
242 }
243
249 {
250 (void)(isCurrentlyActive); // silence unused variable warnings
251 return true;
252 }
253
262 {
263 (void)(encoderID); // silence unused variable warnings
264 (void)(isCurrentlyActive); // silence unused variable warnings
265 return true;
266 }
267
272 virtual bool OnValuePotMoved(float newPosition)
273 {
274 (void)(newPosition); // silence unused variable warnings
275 return true;
276 }
277
285 {
286 (void)(potID); // silence unused variable warnings
287 (void)(newPosition); // silence unused variable warnings
288 return true;
289 }
290
296 {
297 (void)(isCurrentlyActive); // silence unused variable warnings
298 return true;
299 }
300
308 {
309 (void)(potID); // silence unused variable warnings
310 (void)(isCurrentlyActive); // silence unused variable warnings
311 return true;
312 }
313
315 virtual void OnShow(){};
316
318 virtual void OnHide(){};
319
321 virtual void OnFocusGained(){};
322
324 virtual void OnFocusLost(){};
325
330 virtual void Draw(const UiCanvasDescriptor& canvas) = 0;
331
333 UI* GetParentUI() { return parent_; }
335 const UI* GetParentUI() const { return parent_; }
336
337 private:
338 friend class UI;
339 UI* parent_;
340};
341
361class UI
362{
363 public:
364 UI();
366
390
392 static constexpr uint16_t invalidCanvasId = uint16_t(-1);
393
406 std::initializer_list<UiCanvasDescriptor> canvases,
408
413 void Process();
414
421 void Mute(bool shouldBeMuted, bool queueEvents = false);
422
429
432
438 {
439 return primaryOneBitGraphicsDisplayId_;
440 }
441
444 {
445 return specialControlIds_;
446 }
447
448 private:
449 bool isMuted_;
450 bool queueEvents_;
451 static constexpr int kMaxNumPages = 32;
452 static constexpr int kMaxNumCanvases = 8;
455 uint32_t lastUpdateTimes_[kMaxNumCanvases];
456 uint32_t lastEventTime_;
457 UiEventQueue* eventQueue_;
458 SpecialControlIds specialControlIds_;
459 uint16_t primaryOneBitGraphicsDisplayId_ = invalidCanvasId;
460
461 // internal
462 void RemovePage(UiPage* page);
463 void AddPage(UiPage* p);
464 void ProcessEvent(const UiEventQueue::Event& m);
465 void RedrawCanvas(uint8_t index, uint32_t currentTimeInMs);
466 void ForwardToButtonHandler(uint16_t buttonID,
468 bool isRetriggering);
469 void RebuildPageVisibilities();
470};
471
472} // namespace daisy
Definition leddriver.h:33
A generic UI system.
Definition UI.h:362
void Mute(bool shouldBeMuted, bool queueEvents=false)
SpecialControlIds GetSpecialControlIds() const
Definition UI.h:443
void Init(UiEventQueue &inputQueue, const SpecialControlIds &specialControlIds, std::initializer_list< UiCanvasDescriptor > canvases, uint16_t primaryOneBitGraphicsDisplayId=invalidCanvasId)
uint16_t GetPrimaryOneBitGraphicsDisplayId() const
Definition UI.h:437
void Process()
void OpenPage(UiPage &page)
void ClosePage(UiPage &page)
static constexpr uint16_t invalidCanvasId
Definition UI.h:392
A queue that holds user input events in the UI system.
Definition UiEventQueue.h:18
static constexpr uint16_t invalidPotId
Definition UiEventQueue.h:27
static constexpr uint16_t invalidEncoderId
Definition UiEventQueue.h:24
static constexpr uint16_t invalidButtonId
Definition UiEventQueue.h:21
The base class for a page in the UI system.
Definition UI.h:75
virtual void Draw(const UiCanvasDescriptor &canvas)=0
virtual bool OnMenuEncoderActivityChanged(bool isCurrentlyActive)
Definition UI.h:238
virtual bool IsOpaque(const UiCanvasDescriptor &display)
Definition UI.h:86
virtual bool OnButton(uint16_t buttonID, uint8_t numberOfPresses, bool isRetriggering)
Definition UI.h:185
virtual bool OnEncoderTurned(uint16_t encoderID, int16_t turns, uint16_t stepsPerRevolution)
Definition UI.h:224
virtual void OnFocusLost()
Definition UI.h:324
const UI * GetParentUI() const
Definition UI.h:335
virtual bool OnValuePotMoved(float newPosition)
Definition UI.h:272
UiPage()
Definition UI.h:77
virtual bool OnValueEncoderTurned(int16_t turns, uint16_t stepsPerRevolution)
Definition UI.h:210
virtual bool OnEncoderActivityChanged(uint16_t encoderID, bool isCurrentlyActive)
Definition UI.h:260
UI * GetParentUI()
Definition UI.h:333
virtual ~UiPage()
Definition UI.h:79
virtual void OnHide()
Definition UI.h:318
virtual bool OnOkayButton(uint8_t numberOfPresses, bool isRetriggering)
Definition UI.h:114
virtual bool OnMenuEncoderTurned(int16_t turns, uint16_t stepsPerRevolution)
Definition UI.h:198
virtual bool OnCancelButton(uint8_t numberOfPresses, bool isRetriggering)
Definition UI.h:130
virtual void OnFocusGained()
Definition UI.h:321
bool IsActive()
Definition UI.h:93
virtual void OnShow()
Definition UI.h:315
virtual bool OnFunctionButton(uint8_t numberOfPresses, bool isRetriggering)
Definition UI.h:166
virtual bool OnValueEncoderActivityChanged(bool isCurrentlyActive)
Definition UI.h:248
virtual bool OnValuePotActivityChanged(bool isCurrentlyActive)
Definition UI.h:295
virtual bool OnPotActivityChanged(uint16_t potID, bool isCurrentlyActive)
Definition UI.h:307
virtual void OnUserInteraction()
Definition UI.h:98
virtual bool OnPotMoved(uint16_t potID, float newPosition)
Definition UI.h:284
virtual bool OnArrowButton(ArrowButtonType arrowType, uint8_t numberOfPresses, bool isRetriggering)
Definition UI.h:147
ArrowButtonType
The type of arrow button in the UI system.
Definition UI.h:15
Hardware defines and helpers for daisy field platform.
Definition index.h:2
Definition UI.h:375
uint16_t cancelBttnId
Definition UI.h:378
uint16_t leftBttnId
Definition UI.h:381
uint16_t downBttnId
Definition UI.h:380
uint16_t funcBttnId
Definition UI.h:376
uint16_t rightBttnId
Definition UI.h:382
uint16_t valuePotId
Definition UI.h:388
uint16_t valueEncoderId
Definition UI.h:386
uint16_t menuEncoderId
Definition UI.h:384
uint16_t upBttnId
Definition UI.h:379
uint16_t okBttnId
Definition UI.h:377
A descriptor for a canvas in the UI system.
Definition UI.h:34
uint8_t id_
Definition UI.h:37
uint32_t screenSaverTimeOut
Definition UI.h:53
bool screenSaverOn
Definition UI.h:55
FlushFuncPtr flushFunction_
Definition UI.h:65
void * handle_
Definition UI.h:43
uint32_t updateRateMs_
Definition UI.h:46
ClearFuncPtr clearFunction_
Definition UI.h:59