fixed widget and layout menu

This commit is contained in:
Raphael Coeffic
2022-06-11 15:38:08 +02:00
committed by Raphael Coeffic
parent 8e30661eaa
commit d175a86bac
5 changed files with 17 additions and 16 deletions
+2
View File
@@ -50,6 +50,8 @@ class LayoutFactory
const char* getId() const { return id; } const char* getId() const { return id; }
const char* getName() const { return name; } const char* getName() const { return name; }
virtual const uint8_t* getBitmap() const = 0;
virtual void drawThumb(BitmapBuffer* dc, uint16_t x, uint16_t y, virtual void drawThumb(BitmapBuffer* dc, uint16_t x, uint16_t y,
LcdFlags flags) const = 0; LcdFlags flags) const = 0;
@@ -122,6 +122,8 @@ class BaseLayoutFactory: public LayoutFactory
{ {
} }
const uint8_t* getBitmap() const override { return bitmap; }
void drawThumb(BitmapBuffer * dc, uint16_t x, uint16_t y, uint32_t flags) const override void drawThumb(BitmapBuffer * dc, uint16_t x, uint16_t y, uint32_t flags) const override
{ {
dc->drawBitmapPattern(x, y, bitmap, flags); dc->drawBitmapPattern(x, y, bitmap, flags);
+7 -10
View File
@@ -91,21 +91,18 @@ class LayoutChoice: public FormField
{ {
auto menu = new Menu(parent); auto menu = new Menu(parent);
for (auto layout: getRegisteredLayouts()) { for (auto layout : getRegisteredLayouts()) {
menu->addCustomLine([=](BitmapBuffer * dc, coord_t x, coord_t y, LcdFlags flags) { menu->addLine(layout->getBitmap(), layout->getName(),
layout->drawThumb(dc, x + 2, y + 2, flags); [=]() { setValue(layout); });
dc->drawText(65, y + 5, layout->getName(), flags);
}, [=]() {
setValue(layout);
});
} }
auto it = std::find(getRegisteredLayouts().begin(), getRegisteredLayouts().end(), getValue()); auto it = std::find(getRegisteredLayouts().begin(),
getRegisteredLayouts().end(), getValue());
menu->select(std::distance(getRegisteredLayouts().begin(), it)); menu->select(std::distance(getRegisteredLayouts().begin(), it));
menu->setCloseHandler([=]() { menu->setCloseHandler([=]() {
editMode = false; editMode = false;
setFocus(SET_FOCUS_DEFAULT); setFocus(SET_FOCUS_DEFAULT);
}); });
} }
+5 -5
View File
@@ -38,7 +38,7 @@ static void openWidgetMenu(Widget * parent)
menu->addLine("Full screen", [=]() { menu->addLine("Full screen", [=]() {
parent->setFullscreen(true); parent->setFullscreen(true);
}); });
if(parent->getOptions() && parent->getOptions()->name) if(parent->getOptions() && parent->getOptions()->name)
menu->addLine(TR_WIDGET_SETTINGS, [=]() { menu->addLine(TR_WIDGET_SETTINGS, [=]() {
new WidgetSettings(parent, parent); new WidgetSettings(parent, parent);
}); });
@@ -78,11 +78,11 @@ bool Widget::onTouchEnd(coord_t x, coord_t y)
if (hasFocus()) { if (hasFocus()) {
// TODO: find a better way // TODO: find a better way
if (touchState.tapCount == 0) // if (touchState.tapCount == 0)
onPress(); // onPress();
else if (touchState.tapCount > 1) // else
if (touchState.tapCount > 1)
setFullscreen(true); setFullscreen(true);
} }
else { else {