IconView and ListView

IconView and ListView are complete IApplication implementations. Applications derive from them directly.

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 whose targets cover the IconView lifetime. AppLauncher is a ready-made use of IconView.

IconView computes its three visible slots, selector, scrolling, and progress bar from getDisplayWidth() and getDisplayHeight() using integer layout. The same layout adapts to display sizes beyond 128x64. The status text is composed through the shared fixed-buffer integer writer.

ListView

ListView suits settings, Boolean switches, integer 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
9
10
11
12
bool soundEnabled = true;
bool notificationsEnabled = false;
int32_t brightness = 60;
char modeText[] = "Auto";

ListItem items[] = {
{.title = "Sound", .accessory = ListItemAccessory::toggle(soundEnabled)},
{.title = "Notifications", .accessory = ListItemAccessory::check(notificationsEnabled)},
{.title = "Brightness", .accessory = ListItemAccessory::value(PixelUIValue::Binding::integer(brightness))},
{.title = "Mode", .accessory = ListItemAccessory::text(modeText)},
{.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, accessory target, and callback capture must outlive the ListView. toggle() lets ListView update a Boolean value directly. check() displays a Boolean value while the item callback owns its mutation. value() formats numeric state through PixelUIValue::Binding.

ListView keeps at most one active switch Animation, identified by its stable ListItem*. Inactive switch positions come directly from their Boolean values. Equal row numbers in a parent and child menu therefore maintain independent state. Item arrays remain at stable addresses throughout the ListView lifetime.

Long selected titles scroll automatically when the available width is insufficient, and accessories reserve layout space on the right. The array API requires a positive length and stable storage for the array, titles, and accessory targets throughout the ListView lifetime.

avatar
Link0327
汪🐱me0w, but furry wolf. 尝试变得毛茸茸
Link's Github
最新文章
网站信息
文章数目 :
3
本站访客数 :
本站总浏览量 :
最后更新时间 :