libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
AbstractMenu.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
hid/disp/display.h
"
4
#include "
util/MappedValue.h
"
5
#include "
UI.h
"
6
7
namespace
daisy
8
{
55
class
AbstractMenu
:
public
UiPage
56
{
57
public
:
64
enum class
Orientation
65
{
67
leftRightSelectUpDownModify
,
69
upDownSelectLeftRightModify
,
70
};
71
73
enum class
ItemType
74
{
76
callbackFunctionItem
,
79
checkboxItem
,
83
valueItem
,
85
openUiPageItem
,
88
closeMenuItem
,
90
customItem
,
91
};
92
94
class
CustomItem
95
{
96
public
:
97
virtual
~CustomItem
() {}
98
106
virtual
void
Draw
(
OneBitGraphicsDisplay
& display,
107
int
currentIndex
,
108
int
numItemsTotal
,
109
Rectangle
boundsToDrawIn
,
110
bool
isEditing
)
111
= 0;
112
114
virtual
bool
CanBeEnteredForEditing
()
const
{
return
false
; }
115
117
virtual
void
ModifyValue
(
int16_t
increments
,
118
uint16_t
stepsPerRevolution
,
119
bool
isFunctionButtonPressed
)
120
{
121
(
void
)(
increments
);
// silence unused variable warnings
122
(
void
)(
stepsPerRevolution
);
// silence unused variable warnings
123
(
void
)(
isFunctionButtonPressed
);
// silence unused variable warnings
124
};
125
127
virtual
void
ModifyValue
(
float
valueSliderPosition0To1
,
128
bool
isFunctionButtonPressed
)
129
{
130
(
void
)(
valueSliderPosition0To1
);
// silence unused variable warnings
131
(
void
)(
isFunctionButtonPressed
);
// silence unused variable warnings
132
};
133
135
virtual
void
OnOkayButton
(){};
136
};
137
138
struct
ItemConfig
139
{
141
ItemType
type
=
ItemType::closeMenuItem
;
143
const
char
*
text
=
""
;
144
146
union
147
{
149
struct
150
{
151
void
(*
callbackFunction
)(
void
*
context
);
152
void
*
context
;
153
}
asCallbackFunctionItem
;
154
156
struct
157
{
159
bool
*
valueToModify
;
160
}
asCheckboxItem
;
161
163
struct
164
{
166
MappedValue
*
valueToModify
;
167
}
asMappedValueItem
;
168
170
struct
171
{
175
UiPage
*
pageToOpen
;
176
}
asOpenUiPageItem
;
177
179
struct
180
{
183
CustomItem
*
itemObject
;
184
}
asCustomItem
;
185
};
186
};
187
188
AbstractMenu
() =
default
;
189
virtual
~AbstractMenu
()
override
{}
190
191
uint16_t
GetNumItems
()
const
{
return
numItems_
; }
192
const
ItemConfig
&
GetItem
(
uint16_t
itemIdx
)
const
193
{
194
return
items_
[
itemIdx
];
195
}
196
void
SelectItem
(
uint16_t
itemIdx
);
197
int16_t
GetSelectedItemIdx
()
const
{
return
selectedItemIdx_
; }
198
199
// inherited from UiPage
200
bool
OnOkayButton
(
uint8_t
numberOfPresses
,
bool
isRetriggering
)
override
;
201
bool
OnCancelButton
(
uint8_t
numberOfPresses
,
bool
isRetriggering
)
override
;
202
bool
OnArrowButton
(
ArrowButtonType
arrowType
,
203
uint8_t
numberOfPresses
,
204
bool
isRetriggering
)
override
;
205
bool
OnFunctionButton
(
uint8_t
numberOfPresses
,
206
bool
isRetriggering
)
override
;
207
bool
OnMenuEncoderTurned
(
int16_t
turns
,
208
uint16_t
stepsPerRevolution
)
override
;
209
bool
OnValueEncoderTurned
(
int16_t
turns
,
210
uint16_t
stepsPerRevolution
)
override
;
211
bool
OnValuePotMoved
(
float
newPosition
)
override
;
212
void
OnShow
()
override
;
213
214
protected
:
230
void
Init
(
const
ItemConfig
*
items
,
231
uint16_t
numItems
,
232
Orientation
orientation
,
233
bool
allowEntering
);
234
236
bool
IsFunctionButtonDown
()
const
{
return
isFuncButtonDown_; }
237
240
Orientation
orientation_
=
Orientation::upDownSelectLeftRightModify
;
242
const
ItemConfig
*
items_
=
nullptr
;
244
uint16_t
numItems_
= 0;
246
int16_t
selectedItemIdx_
= -1;
249
bool
allowEntering_
=
true
;
253
bool
isEditing_
=
false
;
254
255
private
:
256
AbstractMenu
(
const
AbstractMenu
&
other
) =
delete
;
257
AbstractMenu
& operator=(
const
AbstractMenu
&
other
) =
delete
;
258
259
bool
CanItemBeEnteredForEditing(
uint16_t
itemIdx
);
260
void
ModifyItemValue(
uint16_t
itemIdx
,
261
int16_t
increments
,
262
uint16_t
stepsPerRevolution
,
263
bool
isFunctionButtonPressed
);
264
void
ModifyItemValue(
uint16_t
itemIdx
,
265
float
valueSliderPosition0To1
,
266
bool
isFunctionButtonPressed
);
267
void
TriggerItemAction(
uint16_t
itemIdx
);
268
269
bool
isFuncButtonDown_ =
false
;
270
};
271
272
273
}
// namespace daisy
MappedValue.h
UI.h
daisy::AbstractMenu::CustomItem
Definition
AbstractMenu.h:95
daisy::AbstractMenu::CustomItem::~CustomItem
virtual ~CustomItem()
Definition
AbstractMenu.h:97
daisy::AbstractMenu::CustomItem::ModifyValue
virtual void ModifyValue(int16_t increments, uint16_t stepsPerRevolution, bool isFunctionButtonPressed)
Definition
AbstractMenu.h:117
daisy::AbstractMenu::CustomItem::ModifyValue
virtual void ModifyValue(float valueSliderPosition0To1, bool isFunctionButtonPressed)
Definition
AbstractMenu.h:127
daisy::AbstractMenu::CustomItem::OnOkayButton
virtual void OnOkayButton()
Definition
AbstractMenu.h:135
daisy::AbstractMenu::CustomItem::Draw
virtual void Draw(OneBitGraphicsDisplay &display, int currentIndex, int numItemsTotal, Rectangle boundsToDrawIn, bool isEditing)=0
daisy::AbstractMenu::CustomItem::CanBeEnteredForEditing
virtual bool CanBeEnteredForEditing() const
Definition
AbstractMenu.h:114
daisy::AbstractMenu
Base class for complex menus.
Definition
AbstractMenu.h:56
daisy::AbstractMenu::OnShow
void OnShow() override
daisy::AbstractMenu::OnCancelButton
bool OnCancelButton(uint8_t numberOfPresses, bool isRetriggering) override
daisy::AbstractMenu::SelectItem
void SelectItem(uint16_t itemIdx)
daisy::AbstractMenu::AbstractMenu
AbstractMenu()=default
daisy::AbstractMenu::numItems_
uint16_t numItems_
Definition
AbstractMenu.h:244
daisy::AbstractMenu::~AbstractMenu
virtual ~AbstractMenu() override
Definition
AbstractMenu.h:189
daisy::AbstractMenu::isEditing_
bool isEditing_
Definition
AbstractMenu.h:253
daisy::AbstractMenu::GetItem
const ItemConfig & GetItem(uint16_t itemIdx) const
Definition
AbstractMenu.h:192
daisy::AbstractMenu::GetNumItems
uint16_t GetNumItems() const
Definition
AbstractMenu.h:191
daisy::AbstractMenu::selectedItemIdx_
int16_t selectedItemIdx_
Definition
AbstractMenu.h:246
daisy::AbstractMenu::ItemType
ItemType
Definition
AbstractMenu.h:74
daisy::AbstractMenu::ItemType::openUiPageItem
@ openUiPageItem
daisy::AbstractMenu::ItemType::closeMenuItem
@ closeMenuItem
daisy::AbstractMenu::ItemType::checkboxItem
@ checkboxItem
daisy::AbstractMenu::ItemType::customItem
@ customItem
daisy::AbstractMenu::ItemType::callbackFunctionItem
@ callbackFunctionItem
daisy::AbstractMenu::ItemType::valueItem
@ valueItem
daisy::AbstractMenu::Init
void Init(const ItemConfig *items, uint16_t numItems, Orientation orientation, bool allowEntering)
daisy::AbstractMenu::OnValuePotMoved
bool OnValuePotMoved(float newPosition) override
daisy::AbstractMenu::orientation_
Orientation orientation_
Definition
AbstractMenu.h:240
daisy::AbstractMenu::OnOkayButton
bool OnOkayButton(uint8_t numberOfPresses, bool isRetriggering) override
daisy::AbstractMenu::Orientation
Orientation
Definition
AbstractMenu.h:65
daisy::AbstractMenu::Orientation::leftRightSelectUpDownModify
@ leftRightSelectUpDownModify
daisy::AbstractMenu::Orientation::upDownSelectLeftRightModify
@ upDownSelectLeftRightModify
daisy::AbstractMenu::OnValueEncoderTurned
bool OnValueEncoderTurned(int16_t turns, uint16_t stepsPerRevolution) override
daisy::AbstractMenu::items_
const ItemConfig * items_
Definition
AbstractMenu.h:242
daisy::AbstractMenu::GetSelectedItemIdx
int16_t GetSelectedItemIdx() const
Definition
AbstractMenu.h:197
daisy::AbstractMenu::OnArrowButton
bool OnArrowButton(ArrowButtonType arrowType, uint8_t numberOfPresses, bool isRetriggering) override
daisy::AbstractMenu::OnMenuEncoderTurned
bool OnMenuEncoderTurned(int16_t turns, uint16_t stepsPerRevolution) override
daisy::AbstractMenu::OnFunctionButton
bool OnFunctionButton(uint8_t numberOfPresses, bool isRetriggering) override
daisy::AbstractMenu::allowEntering_
bool allowEntering_
Definition
AbstractMenu.h:249
daisy::AbstractMenu::IsFunctionButtonDown
bool IsFunctionButtonDown() const
Definition
AbstractMenu.h:236
daisy::LedDriverPca9685
Definition
leddriver.h:33
daisy::MappedValue
Definition
MappedValue.h:12
daisy::OneBitGraphicsDisplay
Definition
display.h:20
daisy::Rectangle
Definition
graphics_common.h:22
daisy::UiPage
The base class for a page in the UI system.
Definition
UI.h:75
display.h
daisy::ArrowButtonType
ArrowButtonType
The type of arrow button in the UI system.
Definition
UI.h:15
daisy
Hardware defines and helpers for daisy field platform.
Definition
index.h:2
daisy::AbstractMenu::ItemConfig
Definition
AbstractMenu.h:139
daisy::AbstractMenu::ItemConfig::type
ItemType type
Definition
AbstractMenu.h:141
daisy::AbstractMenu::ItemConfig::pageToOpen
UiPage * pageToOpen
Definition
AbstractMenu.h:175
daisy::AbstractMenu::ItemConfig::callbackFunction
void(* callbackFunction)(void *context)
Definition
AbstractMenu.h:151
daisy::AbstractMenu::ItemConfig::asMappedValueItem
struct daisy::AbstractMenu::ItemConfig::@21::@25 asMappedValueItem
daisy::AbstractMenu::ItemConfig::asCheckboxItem
struct daisy::AbstractMenu::ItemConfig::@21::@24 asCheckboxItem
daisy::AbstractMenu::ItemConfig::asOpenUiPageItem
struct daisy::AbstractMenu::ItemConfig::@21::@26 asOpenUiPageItem
daisy::AbstractMenu::ItemConfig::valueToModify
bool * valueToModify
Definition
AbstractMenu.h:159
daisy::AbstractMenu::ItemConfig::text
const char * text
Definition
AbstractMenu.h:143
daisy::AbstractMenu::ItemConfig::asCustomItem
struct daisy::AbstractMenu::ItemConfig::@21::@27 asCustomItem
daisy::AbstractMenu::ItemConfig::valueToModify
MappedValue * valueToModify
Definition
AbstractMenu.h:166
daisy::AbstractMenu::ItemConfig::itemObject
CustomItem * itemObject
Definition
AbstractMenu.h:183
daisy::AbstractMenu::ItemConfig::asCallbackFunctionItem
struct daisy::AbstractMenu::ItemConfig::@21::@23 asCallbackFunctionItem
daisy::AbstractMenu::ItemConfig::context
void * context
Definition
AbstractMenu.h:152
src
ui
AbstractMenu.h