themes: show active theme is listbox
This commit is contained in:
committed by
Raphael Coeffic
parent
a9f297273b
commit
b448913743
@@ -115,6 +115,19 @@ int ListBase::getSelected() const
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ListBase::setActiveItem(int item)
|
||||||
|
{
|
||||||
|
if (item != activeItem) {
|
||||||
|
activeItem = item;
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int ListBase::getActiveItem() const
|
||||||
|
{
|
||||||
|
return activeItem;
|
||||||
|
}
|
||||||
|
|
||||||
void ListBase::onPress(uint16_t row, uint16_t col)
|
void ListBase::onPress(uint16_t row, uint16_t col)
|
||||||
{
|
{
|
||||||
if (row == LV_TABLE_CELL_NONE) return;
|
if (row == LV_TABLE_CELL_NONE) return;
|
||||||
@@ -148,3 +161,21 @@ void ListBase::onCancel()
|
|||||||
TableField::onCancel();
|
TableField::onCancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ListBase::onDrawEnd(uint16_t row, uint16_t col, lv_obj_draw_part_dsc_t* dsc)
|
||||||
|
{
|
||||||
|
if (row != activeItem) return;
|
||||||
|
|
||||||
|
lv_area_t coords;
|
||||||
|
lv_coord_t area_h = lv_area_get_height(dsc->draw_area);
|
||||||
|
|
||||||
|
lv_coord_t cell_right = lv_obj_get_style_pad_right(lvobj, LV_PART_ITEMS);
|
||||||
|
lv_coord_t font_h = getFontHeight(FONT(STD));
|
||||||
|
|
||||||
|
coords.x1 = dsc->draw_area->x2 - cell_right - font_h;
|
||||||
|
coords.x2 = coords.x1 + font_h;
|
||||||
|
coords.y1 = dsc->draw_area->y1 + (area_h - font_h) / 2;
|
||||||
|
coords.y2 = coords.y1 + font_h - 1;
|
||||||
|
|
||||||
|
lv_draw_label(dsc->draw_ctx, dsc->label_dsc, &coords, LV_SYMBOL_OK, nullptr);
|
||||||
|
}
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ class ListBase : public TableField
|
|||||||
virtual void setSelected(int selected);
|
virtual void setSelected(int selected);
|
||||||
int getSelected() const;
|
int getSelected() const;
|
||||||
|
|
||||||
|
virtual void setActiveItem(int item);
|
||||||
|
int getActiveItem() const;
|
||||||
|
|
||||||
void setLongPressHandler(std::function<void()> handler)
|
void setLongPressHandler(std::function<void()> handler)
|
||||||
{
|
{
|
||||||
longPressHandler = std::move(handler);
|
longPressHandler = std::move(handler);
|
||||||
@@ -67,12 +70,15 @@ class ListBase : public TableField
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void event_cb(lv_event_t* e);
|
static void event_cb(lv_event_t* e);
|
||||||
|
int activeItem = -1;
|
||||||
|
|
||||||
void onPress(uint16_t row, uint16_t col) override;
|
void onPress(uint16_t row, uint16_t col) override;
|
||||||
void onLongPressed();
|
void onLongPressed();
|
||||||
|
|
||||||
void onClicked() override;
|
void onClicked() override;
|
||||||
void onCancel() override;
|
void onCancel() override;
|
||||||
|
|
||||||
|
void onDrawEnd(uint16_t row, uint16_t col, lv_obj_draw_part_dsc_t* dsc) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ListBox : public ListBase
|
class ListBox : public ListBase
|
||||||
|
|||||||
@@ -431,10 +431,12 @@ void ThemeSetupPage::displayThemeMenu(Window *window, ThemePersistance *tp)
|
|||||||
// you cant activate the active theme
|
// you cant activate the active theme
|
||||||
if (listBox->getSelected() != tp->getThemeIndex()) {
|
if (listBox->getSelected() != tp->getThemeIndex()) {
|
||||||
menu->addLine(STR_ACTIVATE, [=]() {
|
menu->addLine(STR_ACTIVATE, [=]() {
|
||||||
tp->applyTheme(listBox->getSelected());
|
auto idx = listBox->getSelected();
|
||||||
tp->setDefaultTheme(listBox->getSelected());
|
tp->applyTheme(idx);
|
||||||
|
tp->setDefaultTheme(idx);
|
||||||
nameText->setTextFlags(COLOR_THEME_PRIMARY1);
|
nameText->setTextFlags(COLOR_THEME_PRIMARY1);
|
||||||
authorText->setTextFlags(COLOR_THEME_PRIMARY1);
|
authorText->setTextFlags(COLOR_THEME_PRIMARY1);
|
||||||
|
listBox->setActiveItem(idx);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -508,6 +510,7 @@ void ThemeSetupPage::setupListbox(FormWindow *window, rect_t r, ThemePersistance
|
|||||||
listBox = new ListBox(window, r, tp->getNames());
|
listBox = new ListBox(window, r, tp->getNames());
|
||||||
listBox->setAutoEdit(true);
|
listBox->setAutoEdit(true);
|
||||||
listBox->setSelected(currentTheme);
|
listBox->setSelected(currentTheme);
|
||||||
|
listBox->setActiveItem(tp->getThemeIndex());
|
||||||
listBox->setTitle(STR_THEME + std::string("s")); // TODO: fix this!
|
listBox->setTitle(STR_THEME + std::string("s")); // TODO: fix this!
|
||||||
listBox->setLongPressHandler([=] () { displayThemeMenu(window, tp); });
|
listBox->setLongPressHandler([=] () { displayThemeMenu(window, tp); });
|
||||||
listBox->setPressHandler([=] () {
|
listBox->setPressHandler([=] () {
|
||||||
|
|||||||
Reference in New Issue
Block a user