flex layout and various fixes

This commit is contained in:
Raphael Coeffic
2022-06-11 15:38:08 +02:00
committed by Raphael Coeffic
parent 415c20657f
commit 49f8a3752c
11 changed files with 154 additions and 116 deletions
+4 -3
View File
@@ -196,7 +196,6 @@ static lv_style_t generic_style;
static lv_style_t btn_style; static lv_style_t btn_style;
static lv_style_t btn_checked_style; static lv_style_t btn_checked_style;
static lv_style_t btn_focused_style; static lv_style_t btn_focused_style;
static lv_style_t btn_checked_focused_style;
static lv_style_t menu_line_style; static lv_style_t menu_line_style;
static lv_style_t menu_checked_style; static lv_style_t menu_checked_style;
static lv_style_t textedit_style_main; static lv_style_t textedit_style_main;
@@ -217,6 +216,10 @@ static void theme_apply_cb(lv_theme_t * th, lv_obj_t * obj)
{ {
LV_UNUSED(th); LV_UNUSED(th);
if (lv_obj_check_type(obj, &lv_switch_class)) {
return;
}
lv_obj_add_style(obj, &generic_style, LV_PART_MAIN); lv_obj_add_style(obj, &generic_style, LV_PART_MAIN);
lv_obj_add_style(obj, &focus_key_style, LV_STATE_FOCUS_KEY); lv_obj_add_style(obj, &focus_key_style, LV_STATE_FOCUS_KEY);
@@ -286,7 +289,6 @@ static void init_theme()
lv_style_set_border_color(&numberedit_style_main, makeLvColor(COLOR_THEME_SECONDARY2)); lv_style_set_border_color(&numberedit_style_main, makeLvColor(COLOR_THEME_SECONDARY2));
lv_style_set_bg_color(&numberedit_style_main, makeLvColor(COLOR_THEME_PRIMARY2)); lv_style_set_bg_color(&numberedit_style_main, makeLvColor(COLOR_THEME_PRIMARY2));
lv_style_set_bg_opa(&numberedit_style_main, LV_OPA_COVER); lv_style_set_bg_opa(&numberedit_style_main, LV_OPA_COVER);
lv_style_set_text_font(&numberedit_style_main, &lv_font_roboto_13);
lv_style_set_text_color(&numberedit_style_main, makeLvColor(COLOR_THEME_SECONDARY1)); lv_style_set_text_color(&numberedit_style_main, makeLvColor(COLOR_THEME_SECONDARY1));
lv_style_set_pad_left(&numberedit_style_main, FIELD_PADDING_LEFT); lv_style_set_pad_left(&numberedit_style_main, FIELD_PADDING_LEFT);
lv_style_set_pad_top(&numberedit_style_main, FIELD_PADDING_TOP); lv_style_set_pad_top(&numberedit_style_main, FIELD_PADDING_TOP);
@@ -313,7 +315,6 @@ static void init_theme()
lv_style_set_border_color(&textedit_style_main, makeLvColor(COLOR_THEME_SECONDARY2)); lv_style_set_border_color(&textedit_style_main, makeLvColor(COLOR_THEME_SECONDARY2));
lv_style_set_bg_color(&textedit_style_main, makeLvColor(COLOR_THEME_PRIMARY2)); lv_style_set_bg_color(&textedit_style_main, makeLvColor(COLOR_THEME_PRIMARY2));
lv_style_set_bg_opa(&textedit_style_main, LV_OPA_COVER); lv_style_set_bg_opa(&textedit_style_main, LV_OPA_COVER);
lv_style_set_text_font(&textedit_style_main, &lv_font_roboto_13);
lv_style_set_text_color(&textedit_style_main, makeLvColor(COLOR_THEME_SECONDARY1)); lv_style_set_text_color(&textedit_style_main, makeLvColor(COLOR_THEME_SECONDARY1));
lv_style_set_pad_left(&textedit_style_main, FIELD_PADDING_LEFT); lv_style_set_pad_left(&textedit_style_main, FIELD_PADDING_LEFT);
lv_style_set_pad_top(&textedit_style_main, FIELD_PADDING_TOP); lv_style_set_pad_top(&textedit_style_main, FIELD_PADDING_TOP);
+47 -28
View File
@@ -25,56 +25,75 @@
#define SET_DIRTY() storageDirty(EE_MODEL) #define SET_DIRTY() storageDirty(EE_MODEL)
static const lv_coord_t line_col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(2),
LV_GRID_TEMPLATE_LAST};
static const lv_coord_t line_row_dsc[] = {LV_GRID_CONTENT,
LV_GRID_TEMPLATE_LAST};
ModelHeliPage::ModelHeliPage(): ModelHeliPage::ModelHeliPage():
PageTab(STR_MENUHELISETUP, ICON_MODEL_HELI) PageTab(STR_MENUHELISETUP, ICON_MODEL_HELI)
{ {
} }
void ModelHeliPage::build(FormWindow * window) void ModelHeliPage::build(FormWindow* form)
{ {
FormGridLayout grid; FlexGridLayout grid(line_col_dsc, line_row_dsc, 2);
grid.spacer(PAGE_PADDING); form->setFlexLayout();
// Swash type // Swash type
new StaticText(window, grid.getLabelSlot(), STR_SWASHTYPE, 0, COLOR_THEME_PRIMARY1); auto line = form->newLine(&grid);
new Choice(window, grid.getFieldSlot(), STR_VSWASHTYPE, 0, SWASH_TYPE_MAX, GET_SET_DEFAULT(g_model.swashR.type)); new StaticText(line, rect_t{}, STR_SWASHTYPE, 0, COLOR_THEME_PRIMARY1);
grid.nextLine(); new Choice(line, rect_t{}, STR_VSWASHTYPE, 0, SWASH_TYPE_MAX,
GET_SET_DEFAULT(g_model.swashR.type));
// Swash ring // Swash ring
new StaticText(window, grid.getLabelSlot(), STR_SWASHRING, 0, COLOR_THEME_PRIMARY1); line = form->newLine(&grid);
new NumberEdit(window, grid.getFieldSlot(), 0, 100, GET_SET_DEFAULT(g_model.swashR.value)); new StaticText(line, rect_t{}, STR_SWASHRING, 0, COLOR_THEME_PRIMARY1);
grid.nextLine(); new NumberEdit(line, rect_t{}, 0, 100, GET_SET_DEFAULT(g_model.swashR.value));
// Elevator source // Elevator source
new StaticText(window, grid.getLabelSlot(), STR_ELEVATOR, 0, COLOR_THEME_PRIMARY1); line = form->newLine(&grid);
new SourceChoice(window, grid.getFieldSlot(), 0, MIXSRC_LAST_CH, GET_SET_DEFAULT(g_model.swashR.elevatorSource)); new StaticText(line, rect_t{}, STR_ELEVATOR, 0, COLOR_THEME_PRIMARY1);
grid.nextLine(); new SourceChoice(line, rect_t{}, 0, MIXSRC_LAST_CH,
GET_SET_DEFAULT(g_model.swashR.elevatorSource));
// Elevator weight // Elevator weight
new StaticText(window, grid.getLabelSlot(), STR_WEIGHT, 0, COLOR_THEME_PRIMARY1); line = form->newLine(&grid);
new NumberEdit(window, grid.getFieldSlot(), -100, 100, GET_SET_DEFAULT(g_model.swashR.elevatorWeight)); new StaticText(line, rect_t{}, STR_WEIGHT, 0, COLOR_THEME_PRIMARY1);
grid.nextLine(); new NumberEdit(line, rect_t{}, -100, 100,
GET_SET_DEFAULT(g_model.swashR.elevatorWeight));
// Aileron source // Aileron source
new StaticText(window, grid.getLabelSlot(), STR_AILERON, 0, COLOR_THEME_PRIMARY1); line = form->newLine(&grid);
new SourceChoice(window, grid.getFieldSlot(), 0, MIXSRC_LAST_CH, GET_SET_DEFAULT(g_model.swashR.aileronSource)); new StaticText(line, rect_t{}, STR_AILERON, 0, COLOR_THEME_PRIMARY1);
grid.nextLine(); new SourceChoice(line, rect_t{}, 0, MIXSRC_LAST_CH,
GET_SET_DEFAULT(g_model.swashR.aileronSource));
// Aileron weight // Aileron weight
new StaticText(window, grid.getLabelSlot(), STR_WEIGHT, 0, COLOR_THEME_PRIMARY1); line = form->newLine(&grid);
new NumberEdit(window, grid.getFieldSlot(), -100, 100, GET_SET_DEFAULT(g_model.swashR.aileronWeight)); new StaticText(line, rect_t{}, STR_WEIGHT, 0, COLOR_THEME_PRIMARY1);
grid.nextLine(); new NumberEdit(line, rect_t{}, -100, 100,
GET_SET_DEFAULT(g_model.swashR.aileronWeight));
// Collective source // Collective source
new StaticText(window, grid.getLabelSlot(), STR_COLLECTIVE, 0, COLOR_THEME_PRIMARY1); line = form->newLine(&grid);
new SourceChoice(window, grid.getFieldSlot(), 0, MIXSRC_LAST_CH, GET_SET_DEFAULT(g_model.swashR.collectiveSource)); new StaticText(line, rect_t{}, STR_COLLECTIVE, 0, COLOR_THEME_PRIMARY1);
grid.nextLine(); new SourceChoice(line, rect_t{}, 0, MIXSRC_LAST_CH,
GET_SET_DEFAULT(g_model.swashR.collectiveSource));
// Collective weight // Collective weight
new StaticText(window, grid.getLabelSlot(), STR_WEIGHT, 0, COLOR_THEME_PRIMARY1); line = form->newLine(&grid);
new NumberEdit(window, grid.getFieldSlot(), -100, 100, GET_SET_DEFAULT(g_model.swashR.collectiveWeight)); new StaticText(line, rect_t{}, STR_WEIGHT, 0, COLOR_THEME_PRIMARY1);
new NumberEdit(line, rect_t{}, -100, 100,
GET_SET_DEFAULT(g_model.swashR.collectiveWeight));
grid.nextLine();
window->setInnerHeight(grid.getWindowHeight()); auto obj = form->getLvObj();
lv_obj_update_layout(obj);
lv_coord_t h =
lv_obj_get_height(obj)
+ lv_obj_get_scroll_top(obj)
+ lv_obj_get_scroll_bottom(obj);
form->setInnerHeight(h);
} }
@@ -27,7 +27,6 @@ SelectFabCarousel::SelectFabCarousel(Window* parent) :
setPageWidth(FAB_BUTTON_SIZE + SELECT_BUTTON_BORDER); setPageWidth(FAB_BUTTON_SIZE + SELECT_BUTTON_BORDER);
setHeight(FAB_BUTTON_SIZE + 2 * PAGE_LINE_HEIGHT + SELECT_BUTTON_BORDER / 2); setHeight(FAB_BUTTON_SIZE + 2 * PAGE_LINE_HEIGHT + SELECT_BUTTON_BORDER / 2);
lv_obj_set_scroll_snap_x(lvobj, LV_SCROLL_SNAP_START);
} }
void SelectFabCarousel::setMaxButtons(uint8_t max) void SelectFabCarousel::setMaxButtons(uint8_t max)
+1 -1
View File
@@ -59,7 +59,7 @@ class SourceChoiceMenuToolbar : public MenuToolbar<SourceChoice>
// defined in gui/gui_common.cpp // defined in gui/gui_common.cpp
uint8_t switchToMix(uint8_t source); uint8_t switchToMix(uint8_t source);
SourceChoice::SourceChoice(FormGroup *parent, const rect_t &rect, int16_t vmin, SourceChoice::SourceChoice(Window* parent, const rect_t &rect, int16_t vmin,
int16_t vmax, std::function<int16_t()> getValue, int16_t vmax, std::function<int16_t()> getValue,
std::function<void(int16_t)> setValue, std::function<void(int16_t)> setValue,
WindowFlags windowFlags, LcdFlags textFlags) : WindowFlags windowFlags, LcdFlags textFlags) :
+1 -1
View File
@@ -33,7 +33,7 @@ class SourceChoice : public ChoiceEx
friend class MenuToolbar; friend class MenuToolbar;
public: public:
SourceChoice(FormGroup* parent, const rect_t& rect, int16_t vmin, SourceChoice(Window* parent, const rect_t& rect, int16_t vmin,
int16_t vmax, std::function<int16_t()> getValue, int16_t vmax, std::function<int16_t()> getValue,
std::function<void(int16_t)> setValue, std::function<void(int16_t)> setValue,
WindowFlags windowFlags = 0, LcdFlags textFlags = 0); WindowFlags windowFlags = 0, LcdFlags textFlags = 0);
+1 -1
View File
@@ -41,7 +41,7 @@ class SwitchChoiceMenuToolbar : public MenuToolbar<SwitchChoice>
} }
}; };
SwitchChoice::SwitchChoice(FormGroup* parent, const rect_t& rect, int vmin, SwitchChoice::SwitchChoice(Window* parent, const rect_t& rect, int vmin,
int vmax, std::function<int16_t()> getValue, int vmax, std::function<int16_t()> getValue,
std::function<void(int16_t)> setValue) : std::function<void(int16_t)> setValue) :
ChoiceEx(parent, rect, vmin, vmax, getValue, setValue) ChoiceEx(parent, rect, vmin, vmax, getValue, setValue)
+1 -1
View File
@@ -30,7 +30,7 @@ class SwitchChoice : public ChoiceEx
template <class T> friend class MenuToolbar; template <class T> friend class MenuToolbar;
public: public:
SwitchChoice(FormGroup* parent, const rect_t& rect, int vmin, int vmax, SwitchChoice(Window* parent, const rect_t& rect, int vmin, int vmax,
std::function<int16_t()> getValue, std::function<int16_t()> getValue,
std::function<void(int16_t)> setValue); std::function<void(int16_t)> setValue);
+1 -1
View File
@@ -34,7 +34,7 @@
#include "view_text.h" #include "view_text.h"
ViewMainMenu::ViewMainMenu(Window* parent) : ViewMainMenu::ViewMainMenu(Window* parent) :
Window(parent->getFullScreenWindow(), {}) Window(parent->getFullScreenWindow(), rect_t{})
{ {
// Save focus // Save focus
Layer::push(this); Layer::push(this);
+93 -72
View File
@@ -20,9 +20,10 @@
*/ */
#include "opentx.h" #include "opentx.h"
#include "libopenui.h"
#include "widget_settings.h" #include "widget_settings.h"
#include "libopenui.h" #include "view_main.h"
#define SET_DIRTY() storageDirty(EE_MODEL) #define SET_DIRTY() storageDirty(EE_MODEL)
@@ -33,125 +34,145 @@ static const rect_t widgetSettingsDialogRect = {
LCD_H - 2 * LCD_H / 5 // height LCD_H - 2 * LCD_H / 5 // height
}; };
WidgetSettings::WidgetSettings(Window * parent, Widget * widget) : static const lv_coord_t line_col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(2),
Dialog(parent, TR_WIDGET_SETTINGS, widgetSettingsDialogRect) LV_GRID_TEMPLATE_LAST};
static const lv_coord_t line_row_dsc[] = {LV_GRID_CONTENT,
LV_GRID_TEMPLATE_LAST};
WidgetSettings::WidgetSettings(Window* parent, Widget* widget) :
Dialog(ViewMain::instance(), STR_WIDGET_SETTINGS, widgetSettingsDialogRect)
{ {
auto lv_content = content->getLvObj();
lv_obj_set_flex_flow(lv_content, LV_FLEX_FLOW_COLUMN);
setCloseWhenClickOutside(true); setCloseWhenClickOutside(true);
auto form = &content->form; auto form = &content->form;
FormGridLayout grid(content->form.width(), 10); form->setFlexLayout();
grid.setLabelWidth(width() / 3);
form->clear(); FlexGridLayout grid(line_col_dsc, line_row_dsc);
uint8_t optIdx = 0; uint8_t optIdx = 0;
auto optPtr = widget->getOptions(); auto optPtr = widget->getOptions();
while (optPtr && optPtr->name != nullptr) { while (optPtr && optPtr->name != nullptr) {
auto line = form->newLine(&grid);
auto option = *optPtr; auto option = *optPtr;
new StaticText(form, grid.getLabelSlot(), option.name, 0, COLOR_THEME_PRIMARY1); new StaticText(line, rect_t{}, option.name, 0, COLOR_THEME_PRIMARY1);
switch (option.type) { switch (option.type) {
case ZoneOption::Integer: case ZoneOption::Integer:
new NumberEdit(form, grid.getFieldSlot(), option.min.signedValue, option.max.signedValue, new NumberEdit(
[=]() -> int { line, rect_t{}, option.min.signedValue,
return widget->getOptionValue(optIdx)->signedValue; option.max.signedValue,
}, [=]() -> int {
[=](int32_t newValue) { return widget->getOptionValue(optIdx)->signedValue;
widget->getOptionValue(optIdx)->signedValue = newValue; },
}); [=](int32_t newValue) {
widget->getOptionValue(optIdx)->signedValue = newValue;
});
break; break;
case ZoneOption::Source: case ZoneOption::Source:
new SourceChoice(form, grid.getFieldSlot(), 0, MIXSRC_LAST_TELEM, new SourceChoice(
[=]() -> int16_t { line, rect_t{}, 0, MIXSRC_LAST_TELEM,
return (int16_t) widget->getOptionValue(optIdx)->unsignedValue; [=]() -> int16_t {
}, return (int16_t)widget->getOptionValue(optIdx)->unsignedValue;
[=](int16_t newValue) { },
widget->getOptionValue(optIdx)->unsignedValue = (uint32_t)newValue; [=](int16_t newValue) {
}); widget->getOptionValue(optIdx)->unsignedValue =
(uint32_t)newValue;
});
break; break;
case ZoneOption::Bool: case ZoneOption::Bool:
new CheckBox(form, grid.getFieldSlot(), new CheckBox(
[=]() -> uint8_t { line, rect_t{},
return (uint8_t) widget->getOptionValue(optIdx)->boolValue; [=]() -> uint8_t {
}, return (uint8_t)widget->getOptionValue(optIdx)->boolValue;
[=](int8_t newValue) { },
widget->getOptionValue(optIdx)->boolValue = newValue; [=](int8_t newValue) {
SET_DIRTY(); widget->getOptionValue(optIdx)->boolValue = newValue;
}); SET_DIRTY();
});
break; break;
case ZoneOption::String: case ZoneOption::String:
new ModelTextEdit(form, grid.getFieldSlot(), widget->getOptionValue(optIdx)->stringValue, sizeof( widget->getOptionValue(optIdx)->stringValue)); new ModelTextEdit(line, rect_t{},
widget->getOptionValue(optIdx)->stringValue,
sizeof(widget->getOptionValue(optIdx)->stringValue));
break; break;
case ZoneOption::File: case ZoneOption::File:
break; break;
case ZoneOption::TextSize: { case ZoneOption::TextSize: {
new Choice(form, grid.getFieldSlot(), STR_FONT_SIZES, 0, FONTS_COUNT - 1, new Choice(
[=]() -> int { // getValue line, rect_t{}, STR_FONT_SIZES, 0, FONTS_COUNT - 1,
return (int) widget->getOptionValue(optIdx)->unsignedValue; [=]() -> int { // getValue
}, return (int)widget->getOptionValue(optIdx)->unsignedValue;
[=](int newValue) { // setValue },
widget->getOptionValue(optIdx)->unsignedValue = (uint32_t) newValue; [=](int newValue) { // setValue
SET_DIRTY(); widget->getOptionValue(optIdx)->unsignedValue =
}); (uint32_t)newValue;
SET_DIRTY();
});
break; break;
} }
case ZoneOption::Timer: // Unsigned case ZoneOption::Timer: // Unsigned
{ {
auto tmChoice = new Choice(form, grid.getFieldSlot(), 0, TIMERS - 1, auto tmChoice = new Choice(
[=]() -> int { // getValue line, rect_t{}, 0, TIMERS - 1,
return (int) widget->getOptionValue(optIdx)->unsignedValue; [=]() -> int { // getValue
}, return (int)widget->getOptionValue(optIdx)->unsignedValue;
[=](int newValue) { // setValue },
widget->getOptionValue(optIdx)->unsignedValue = (uint32_t) newValue; [=](int newValue) { // setValue
}); widget->getOptionValue(optIdx)->unsignedValue =
(uint32_t)newValue;
});
tmChoice->setTextHandler([](int value) { tmChoice->setTextHandler([](int value) {
return std::string(STR_TIMER) + std::to_string(value + 1); return std::string(STR_TIMER) + std::to_string(value + 1);
}); });
} } break;
break;
case ZoneOption::Switch: case ZoneOption::Switch:
new SwitchChoice(form, grid.getFieldSlot(), new SwitchChoice(
option.min.unsignedValue, // min line, rect_t{},
option.max.unsignedValue, // max option.min.unsignedValue, // min
[=]() -> int16_t { // getValue option.max.unsignedValue, // max
return (uint8_t) widget->getOptionValue(optIdx)->unsignedValue; [=]() -> int16_t { // getValue
}, return (uint8_t)widget->getOptionValue(optIdx)->unsignedValue;
[=](int16_t newValue) { // setValue },
widget->getOptionValue(optIdx)->unsignedValue = (uint32_t) newValue; [=](int16_t newValue) { // setValue
}); widget->getOptionValue(optIdx)->unsignedValue =
(uint32_t)newValue;
});
break; break;
case ZoneOption::Color: case ZoneOption::Color:
new ColorEdit(form, grid.getFieldSlot(), new ColorEdit(
[=]() -> int { // getValue line, rect_t{},
return (int) widget->getOptionValue(optIdx)->unsignedValue; [=]() -> int { // getValue
}, return (int)widget->getOptionValue(optIdx)->unsignedValue;
[=](int newValue) { // setValue },
widget->getOptionValue(optIdx)->unsignedValue = (uint32_t) newValue; [=](int newValue) { // setValue
SET_DIRTY(); widget->getOptionValue(optIdx)->unsignedValue =
}); (uint32_t)newValue;
SET_DIRTY();
});
break; break;
} }
optIdx++; optIdx++;
optPtr++; optPtr++;
grid.nextLine();
} }
setCloseHandler([widget]() { content->updateSize();
widget->update(); setCloseHandler([=]() { widget->update(); });
});
} }
#if defined(HARDWARE_KEYS) #if defined(HARDWARE_KEYS)
void WidgetSettings::onEvent(event_t event) void WidgetSettings::onEvent(event_t event)
+4 -6
View File
@@ -24,14 +24,12 @@
#include "dialog.h" #include "dialog.h"
#include "widget.h" #include "widget.h"
class WidgetSettings: public Dialog class WidgetSettings : public Dialog
{ {
std::function<void(void)> confirmHandler; public:
WidgetSettings(Window* parent, Widget* widget);
public:
WidgetSettings(Window * parent, Widget * widget);
#if defined(HARDWARE_KEYS) #if defined(HARDWARE_KEYS)
void onEvent(event_t event) override; void onEvent(event_t event) override;
#endif #endif
}; };