fix(gui): Outline, more padding, wider buttons for menu toolbars (#70)
This commit is contained in:
+13
-2
@@ -207,8 +207,8 @@ void MenuBody::onEvent(event_t event)
|
|||||||
else {
|
else {
|
||||||
TableField::onEvent(event);
|
TableField::onEvent(event);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void MenuBody::onCancel()
|
void MenuBody::onCancel()
|
||||||
{
|
{
|
||||||
@@ -254,12 +254,22 @@ void Menu::setToolbar(Window * window)
|
|||||||
toolbar->setHeight(content->height());
|
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()
|
void Menu::updatePosition()
|
||||||
{
|
{
|
||||||
coord_t height = content->body.getContentHeight();
|
coord_t height = content->body.getContentHeight();
|
||||||
|
|
||||||
if (toolbar) {
|
if (toolbar) {
|
||||||
content->setLeft((LCD_W - content->width() + toolbar->width())/2);
|
content->setLeft((LCD_W - content->width() + toolbar->width())/2);
|
||||||
|
setOutline(toolbar);
|
||||||
} else {
|
} else {
|
||||||
content->setLeft((LCD_W - content->width())/2);
|
content->setLeft((LCD_W - content->width())/2);
|
||||||
auto headerHeight = content->getHeaderHeight();
|
auto headerHeight = content->getHeaderHeight();
|
||||||
@@ -267,8 +277,9 @@ void Menu::updatePosition()
|
|||||||
content->setTop((LCD_H - headerHeight - bodyHeight) / 2);
|
content->setTop((LCD_H - headerHeight - bodyHeight) / 2);
|
||||||
content->setHeight(headerHeight + bodyHeight);
|
content->setHeight(headerHeight + bodyHeight);
|
||||||
content->body.setTop(headerHeight);
|
content->body.setTop(headerHeight);
|
||||||
content->body.setHeight(bodyHeight);
|
content->body.setHeight(bodyHeight);
|
||||||
}
|
}
|
||||||
|
setOutline(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::setTitle(std::string text)
|
void Menu::setTitle(std::string text)
|
||||||
|
|||||||
+2
@@ -221,6 +221,8 @@ class Menu: public ModalWindow
|
|||||||
Window * toolbar = nullptr;
|
Window * toolbar = nullptr;
|
||||||
std::function<void()> waitHandler;
|
std::function<void()> waitHandler;
|
||||||
void updatePosition();
|
void updatePosition();
|
||||||
|
|
||||||
|
void setOutline(Window* obj);
|
||||||
};
|
};
|
||||||
|
|
||||||
Menu * MenuBody::getParentMenu()
|
Menu * MenuBody::getParentMenu()
|
||||||
|
|||||||
+12
-9
@@ -31,17 +31,18 @@ MenuToolbarButton::MenuToolbarButton(Window* parent, const rect_t& rect,
|
|||||||
|
|
||||||
void MenuToolbarButton::paint(BitmapBuffer * dc)
|
void MenuToolbarButton::paint(BitmapBuffer * dc)
|
||||||
{
|
{
|
||||||
|
lv_coord_t width = lv_obj_get_content_width(lvobj);
|
||||||
if (checked()) {
|
if (checked()) {
|
||||||
dc->drawSolidFilledRect(
|
dc->drawSolidFilledRect(
|
||||||
MENUS_TOOLBAR_BUTTON_PADDING, MENUS_TOOLBAR_BUTTON_PADDING,
|
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,
|
MENUS_TOOLBAR_BUTTON_WIDTH - 2 * MENUS_TOOLBAR_BUTTON_PADDING,
|
||||||
COLOR_THEME_FOCUS);
|
COLOR_THEME_FOCUS);
|
||||||
dc->drawText(rect.w / 2, (rect.h - getFontHeight(FONT(STD))) / 2 + 1,
|
dc->drawText(width / 2, (rect.h - getFontHeight(FONT(L))) / 2 + 2,
|
||||||
picto, CENTERED | COLOR_THEME_PRIMARY2);
|
picto, FONT(L) | CENTERED | COLOR_THEME_PRIMARY2);
|
||||||
} else {
|
} else {
|
||||||
dc->drawText(rect.w / 2, (rect.h - getFontHeight(FONT(STD))) / 2 + 1,
|
dc->drawText(width / 2, (rect.h - getFontHeight(FONT(L))) / 2 + 2,
|
||||||
picto, CENTERED | COLOR_THEME_PRIMARY1);
|
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;
|
coord_t y = buttons * (MENUS_TOOLBAR_BUTTON_WIDTH + MENUS_TOOLBAR_BUTTON_PADDING);
|
||||||
return {0, y, MENUS_TOOLBAR_BUTTON_WIDTH, MENUS_TOOLBAR_BUTTON_WIDTH};
|
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,
|
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)
|
getFirstAvailable(filtermin, filtermax, choice->isValueAvailable) == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
rect_t r = _get_button_rect(children.size());
|
rect_t r = getButtonRect(children.size());
|
||||||
auto button = new MenuToolbarButton(this, r, picto);
|
auto button = new MenuToolbarButton(this, r, picto);
|
||||||
|
|
||||||
button->setPressHandler(
|
button->setPressHandler(
|
||||||
|
|||||||
@@ -52,4 +52,6 @@ class MenuToolbar : public Window
|
|||||||
|
|
||||||
void addButton(const char* picto, int16_t filtermin, int16_t filtermax);
|
void addButton(const char* picto, int16_t filtermin, int16_t filtermax);
|
||||||
bool filterMenu(MenuToolbarButton* btn, int16_t filtermin, int16_t filtermax);
|
bool filterMenu(MenuToolbarButton* btn, int16_t filtermin, int16_t filtermax);
|
||||||
|
|
||||||
|
rect_t getButtonRect(size_t buttons);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user