main menu: better fill the screen (flex layout)
This commit is contained in:
committed by
Raphael Coeffic
parent
5ceea0df0a
commit
52e10c74de
@@ -44,6 +44,13 @@ FabButton::FabButton(FormGroup* parent, coord_t x, coord_t y, uint8_t icon,
|
||||
{
|
||||
}
|
||||
|
||||
FabButton::FabButton(FormGroup* parent, uint8_t icon,
|
||||
std::function<uint8_t(void)> pressHandler,
|
||||
WindowFlags windowFlags) :
|
||||
Button(parent, {}, pressHandler, windowFlags), icon(icon)
|
||||
{
|
||||
}
|
||||
|
||||
void FabButton::paint(BitmapBuffer * dc)
|
||||
{
|
||||
auto bitmap = checked() ? &ALPHA_BUTTON_ON : &ALPHA_BUTTON_OFF;
|
||||
|
||||
@@ -28,7 +28,13 @@ constexpr coord_t FAB_BUTTON_SIZE = 68;
|
||||
|
||||
class FabButton: public Button {
|
||||
public:
|
||||
FabButton(FormGroup * parent, coord_t x, coord_t y, uint8_t icon, std::function<uint8_t(void)> pressHandler, WindowFlags windowFlags = 0);
|
||||
FabButton(FormGroup * parent, coord_t x, coord_t y,
|
||||
uint8_t icon, std::function<uint8_t(void)> pressHandler,
|
||||
WindowFlags windowFlags = 0);
|
||||
|
||||
FabButton(FormGroup * parent, uint8_t icon,
|
||||
std::function<uint8_t(void)> pressHandler,
|
||||
WindowFlags windowFlags = 0);
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() const override
|
||||
|
||||
@@ -21,13 +21,12 @@
|
||||
|
||||
#include "select_fab_button.h"
|
||||
|
||||
SelectFabButton::SelectFabButton(FormGroup* parent, coord_t x, coord_t y,
|
||||
SelectFabButton::SelectFabButton(FormGroup* parent,
|
||||
uint8_t icon, const char* title,
|
||||
std::function<uint8_t(void)> pressHandler,
|
||||
WindowFlags windowFlags) :
|
||||
// FabButton uses center coordinates, we want top left corner:
|
||||
FabButton(parent, x, y, icon,
|
||||
pressHandler, windowFlags),
|
||||
FabButton(parent, icon, pressHandler, windowFlags),
|
||||
title(title)
|
||||
{
|
||||
// Add some space on either side on the button
|
||||
|
||||
@@ -28,8 +28,8 @@ constexpr coord_t SELECT_BUTTON_BORDER = 12;
|
||||
class SelectFabButton : public FabButton
|
||||
{
|
||||
public:
|
||||
SelectFabButton(FormGroup* parent, coord_t x, coord_t y, uint8_t icon,
|
||||
const char* title, std::function<uint8_t(void)> pressHandler,
|
||||
SelectFabButton(FormGroup* parent, uint8_t icon, const char* title,
|
||||
std::function<uint8_t(void)> pressHandler,
|
||||
WindowFlags windowFlags = 0);
|
||||
|
||||
void paint(BitmapBuffer* dc) override;
|
||||
|
||||
@@ -24,21 +24,17 @@
|
||||
SelectFabCarousel::SelectFabCarousel(Window* parent) :
|
||||
FormGroup(parent, {}, FORM_FORWARD_FOCUS | NO_SCROLLBAR)
|
||||
{
|
||||
setHeight(FAB_BUTTON_SIZE + 2 * PAGE_LINE_HEIGHT + SELECT_BUTTON_BORDER / 2);
|
||||
}
|
||||
setFlexLayout(LV_FLEX_FLOW_ROW_WRAP);
|
||||
|
||||
void SelectFabCarousel::setMaxButtons(uint8_t max)
|
||||
{
|
||||
maxButtons = max;
|
||||
setWidth(maxButtons * (FAB_BUTTON_SIZE + SELECT_BUTTON_BORDER));
|
||||
coord_t w = parent->width() * 0.8;
|
||||
w -= w % (FAB_BUTTON_SIZE + SELECT_BUTTON_BORDER);
|
||||
lv_obj_set_width(lvobj, w);
|
||||
|
||||
lv_obj_set_style_max_height(lvobj, lv_pct(85), 0);
|
||||
}
|
||||
|
||||
void SelectFabCarousel::addButton(uint8_t icon, const char* title,
|
||||
std::function<uint8_t(void)> pressHandler)
|
||||
{
|
||||
coord_t y_pos = 0;
|
||||
coord_t x_pos = (FAB_BUTTON_SIZE + SELECT_BUTTON_BORDER) * buttons;
|
||||
buttons++;
|
||||
|
||||
new SelectFabButton(this, x_pos, y_pos, icon, title, pressHandler);
|
||||
new SelectFabButton(this, icon, title, pressHandler);
|
||||
}
|
||||
|
||||
@@ -44,15 +44,6 @@ ViewMainMenu::ViewMainMenu(Window* parent) :
|
||||
setHeight(parent->height());
|
||||
|
||||
auto carousel = new SelectFabCarousel(this);
|
||||
carousel->setMaxButtons(4);
|
||||
|
||||
// Disabled Title
|
||||
//
|
||||
// auto title = new StaticText(this,
|
||||
// {0, pos, width(), getFontHeight(FONT(XL))},
|
||||
// "Tasks", 0, COLOR_THEME_PRIMARY2 | FONT(XL) | CENTERED);
|
||||
// pos += title->height() + PAGE_LINE_SPACING;
|
||||
|
||||
carousel->addButton(ICON_MODEL_SELECT, STR_MAIN_MENU_SELECT_MODEL, [=]() -> uint8_t {
|
||||
deleteLater();
|
||||
new ModelSelectMenu();
|
||||
@@ -114,8 +105,14 @@ ViewMainMenu::ViewMainMenu(Window* parent) :
|
||||
return 0;
|
||||
});
|
||||
|
||||
carousel->setWindowCentered();
|
||||
carouselRect = carousel->getRect();
|
||||
auto carousel_obj = carousel->getLvObj();
|
||||
lv_obj_center(carousel_obj);
|
||||
|
||||
lv_obj_update_layout(carousel_obj);
|
||||
carouselRect.x = lv_obj_get_x(carousel_obj);
|
||||
carouselRect.y = lv_obj_get_y(carousel_obj);
|
||||
carouselRect.w = lv_obj_get_width(carousel_obj);
|
||||
carouselRect.h = lv_obj_get_height(carousel_obj);
|
||||
|
||||
carousel->setCloseHandler([=]() { deleteLater(); });
|
||||
carousel->setFocus();
|
||||
@@ -128,6 +125,7 @@ void ViewMainMenu::paint(BitmapBuffer* dc)
|
||||
rect_t zone = carouselRect;
|
||||
zone.x -= 8; zone.y -= 8;
|
||||
zone.w += 16; zone.h += 16;
|
||||
|
||||
dc->drawFilledRect(zone.x, zone.y, zone.w, zone.h, SOLID, BLACK, OPACITY(4));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user