fix(gui): Outline, more padding, wider buttons for menu toolbars (#70)

This commit is contained in:
Malte Langermann
2022-10-01 21:23:18 +10:00
committed by GitHub
parent bb447ea493
commit fa59524ebd
4 changed files with 29 additions and 11 deletions
+13 -2
View File
@@ -207,8 +207,8 @@ void MenuBody::onEvent(event_t event)
else {
TableField::onEvent(event);
}
}
#endif
}
void MenuBody::onCancel()
{
@@ -254,12 +254,22 @@ void Menu::setToolbar(Window * window)
toolbar->setHeight(content->height());
}
void Menu::setOutline(Window* obj)
{
lv_obj_set_style_outline_width(obj->getLvObj(), 4, LV_PART_MAIN);
lv_obj_set_style_outline_color(obj->getLvObj(), makeLvColor(COLOR_THEME_SECONDARY2), LV_PART_MAIN);
lv_obj_set_style_outline_opa(obj->getLvObj(), LV_OPA_100, LV_PART_MAIN);
lv_obj_set_style_outline_pad(obj->getLvObj(), 1, LV_PART_MAIN);
}
void Menu::updatePosition()
{
coord_t height = content->body.getContentHeight();
if (toolbar) {
content->setLeft((LCD_W - content->width() + toolbar->width())/2);
setOutline(toolbar);
} else {
content->setLeft((LCD_W - content->width())/2);
auto headerHeight = content->getHeaderHeight();
@@ -267,8 +277,9 @@ void Menu::updatePosition()
content->setTop((LCD_H - headerHeight - bodyHeight) / 2);
content->setHeight(headerHeight + bodyHeight);
content->body.setTop(headerHeight);
content->body.setHeight(bodyHeight);
content->body.setHeight(bodyHeight);
}
setOutline(content);
}
void Menu::setTitle(std::string text)
+2
View File
@@ -221,6 +221,8 @@ class Menu: public ModalWindow
Window * toolbar = nullptr;
std::function<void()> waitHandler;
void updatePosition();
void setOutline(Window* obj);
};
Menu * MenuBody::getParentMenu()
+12 -9
View File
@@ -31,17 +31,18 @@ MenuToolbarButton::MenuToolbarButton(Window* parent, const rect_t& rect,
void MenuToolbarButton::paint(BitmapBuffer * dc)
{
lv_coord_t width = lv_obj_get_content_width(lvobj);
if (checked()) {
dc->drawSolidFilledRect(
MENUS_TOOLBAR_BUTTON_PADDING, MENUS_TOOLBAR_BUTTON_PADDING,
MENUS_TOOLBAR_BUTTON_WIDTH - 2 * MENUS_TOOLBAR_BUTTON_PADDING,
width - 2 * MENUS_TOOLBAR_BUTTON_PADDING,
MENUS_TOOLBAR_BUTTON_WIDTH - 2 * MENUS_TOOLBAR_BUTTON_PADDING,
COLOR_THEME_FOCUS);
dc->drawText(rect.w / 2, (rect.h - getFontHeight(FONT(STD))) / 2 + 1,
picto, CENTERED | COLOR_THEME_PRIMARY2);
dc->drawText(width / 2, (rect.h - getFontHeight(FONT(L))) / 2 + 2,
picto, FONT(L) | CENTERED | COLOR_THEME_PRIMARY2);
} else {
dc->drawText(rect.w / 2, (rect.h - getFontHeight(FONT(STD))) / 2 + 1,
picto, CENTERED | COLOR_THEME_PRIMARY1);
dc->drawText(width / 2, (rect.h - getFontHeight(FONT(L))) / 2 + 2,
picto, FONT(L) | CENTERED | COLOR_THEME_PRIMARY1);
}
}
@@ -83,10 +84,12 @@ void MenuToolbar::onEvent(event_t event)
}
}
static rect_t _get_button_rect(size_t buttons)
rect_t MenuToolbar::getButtonRect(size_t buttons)
{
coord_t y = buttons * MENUS_TOOLBAR_BUTTON_WIDTH;
return {0, y, MENUS_TOOLBAR_BUTTON_WIDTH, MENUS_TOOLBAR_BUTTON_WIDTH};
coord_t y = buttons * (MENUS_TOOLBAR_BUTTON_WIDTH + MENUS_TOOLBAR_BUTTON_PADDING);
coord_t width = std::max<coord_t>(MENUS_TOOLBAR_BUTTON_WIDTH, lv_obj_get_content_width(lvobj));
return {0, y, LV_PCT(100), MENUS_TOOLBAR_BUTTON_WIDTH};
}
bool MenuToolbar::filterMenu(MenuToolbarButton* btn, int16_t filtermin,
@@ -131,7 +134,7 @@ void MenuToolbar::addButton(const char* picto, int16_t filtermin,
getFirstAvailable(filtermin, filtermax, choice->isValueAvailable) == 0)
return;
rect_t r = _get_button_rect(children.size());
rect_t r = getButtonRect(children.size());
auto button = new MenuToolbarButton(this, r, picto);
button->setPressHandler(
+2
View File
@@ -52,4 +52,6 @@ class MenuToolbar : public Window
void addButton(const char* picto, int16_t filtermin, int16_t filtermax);
bool filterMenu(MenuToolbarButton* btn, int16_t filtermin, int16_t filtermax);
rect_t getButtonRect(size_t buttons);
};