IconView and ListView

IconView and ListView are complete IApplication implementations, not Widgets placed inside another App.

IconView

IconView suits a small number of items with XBM icons. A concrete derived class supplies its configuration:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class ToolMenu final : public IconView {
public:
ToolMenu(PixelUI& ui, void*) : IconView(ui) {
IconItemList items;
items.emplace_back("Clock", clockBits, nullptr);
items.emplace_back("Counter", counterBits, nullptr);
setItems(items);
setTitle("< Tools >");
enableProgressBar(true);
enableStatusText(true);
enableSelectedItemTitle(true);

setSelectionCallback([this](int index, const IconItem&) {
selected_ = index;
});
}

private:
int selected_ = 0;
};

IconItemList is etl::vector<IconItem, MAX_ICONVIEW_ITEMS>. title, bitmap, and userData are non-owning pointers and must not refer to short-lived local data. AppLauncher is a ready-made use of IconView.

ListView

ListView suits settings, Boolean switches, integer or floating-point values, and nested submenus. It is abstract; a derived class must implement onLoad() and onSave():

1
2
3
4
5
6
7
8
9
10
11
12
13
class SettingsView final : public ListView {
public:
SettingsView(PixelUI& ui, ListItem* items, int count)
: ListView(ui, items, count) {}

void onLoad() override {
// Load storage values into the state referenced by ListItemExtra.
}

void onSave() override {
// Write changed state back to storage.
}
};
1
2
3
4
5
6
7
8
bool soundEnabled = true;
int32_t brightness = 60;

ListItem items[] = {
{.title = "Sound", .extra = {.switchValue = &soundEnabled}},
{.title = "Brightness", .extra = {.intValue = &brightness}},
{.title = "About", .pFunc = []() { open_about(); }},
};

A ListItem may point to a submenu through nextList and nextListLength. PIXELUI_MAX_LISTVIEW_DEPTH limits the history stack. Every ListItem, submenu, title string, and object referenced through an extra pointer must outlive the ListView.

The current ListView array API is intentionally low level. Consult examples/ListViewDemo1.cpp in the main repository before using it. Length must be greater than zero; do not construct it with an empty array.

最新文章
网站信息
文章数目 :
1
本站访客数 :
本站总浏览量 :
最后更新时间 :