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_checked_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_checked_style;
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);
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, &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_bg_color(&numberedit_style_main, makeLvColor(COLOR_THEME_PRIMARY2));
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_pad_left(&numberedit_style_main, FIELD_PADDING_LEFT);
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_bg_color(&textedit_style_main, makeLvColor(COLOR_THEME_PRIMARY2));
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_pad_left(&textedit_style_main, FIELD_PADDING_LEFT);
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)
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():
PageTab(STR_MENUHELISETUP, ICON_MODEL_HELI)
{
}
void ModelHeliPage::build(FormWindow * window)
void ModelHeliPage::build(FormWindow* form)
{
FormGridLayout grid;
grid.spacer(PAGE_PADDING);
FlexGridLayout grid(line_col_dsc, line_row_dsc, 2);
form->setFlexLayout();
// Swash type
new StaticText(window, grid.getLabelSlot(), STR_SWASHTYPE, 0, COLOR_THEME_PRIMARY1);
new Choice(window, grid.getFieldSlot(), STR_VSWASHTYPE, 0, SWASH_TYPE_MAX, GET_SET_DEFAULT(g_model.swashR.type));
grid.nextLine();
auto line = form->newLine(&grid);
new StaticText(line, rect_t{}, STR_SWASHTYPE, 0, COLOR_THEME_PRIMARY1);
new Choice(line, rect_t{}, STR_VSWASHTYPE, 0, SWASH_TYPE_MAX,
GET_SET_DEFAULT(g_model.swashR.type));
// Swash ring
new StaticText(window, grid.getLabelSlot(), STR_SWASHRING, 0, COLOR_THEME_PRIMARY1);
new NumberEdit(window, grid.getFieldSlot(), 0, 100, GET_SET_DEFAULT(g_model.swashR.value));
grid.nextLine();
line = form->newLine(&grid);
new StaticText(line, rect_t{}, STR_SWASHRING, 0, COLOR_THEME_PRIMARY1);
new NumberEdit(line, rect_t{}, 0, 100, GET_SET_DEFAULT(g_model.swashR.value));
// Elevator source
new StaticText(window, grid.getLabelSlot(), STR_ELEVATOR, 0, COLOR_THEME_PRIMARY1);
new SourceChoice(window, grid.getFieldSlot(), 0, MIXSRC_LAST_CH, GET_SET_DEFAULT(g_model.swashR.elevatorSource));
grid.nextLine();
line = form->newLine(&grid);
new StaticText(line, rect_t{}, STR_ELEVATOR, 0, COLOR_THEME_PRIMARY1);
new SourceChoice(line, rect_t{}, 0, MIXSRC_LAST_CH,
GET_SET_DEFAULT(g_model.swashR.elevatorSource));
// Elevator weight
new StaticText(window, grid.getLabelSlot(), STR_WEIGHT, 0, COLOR_THEME_PRIMARY1);
new NumberEdit(window, grid.getFieldSlot(), -100, 100, GET_SET_DEFAULT(g_model.swashR.elevatorWeight));
grid.nextLine();
line = form->newLine(&grid);
new StaticText(line, rect_t{}, STR_WEIGHT, 0, COLOR_THEME_PRIMARY1);
new NumberEdit(line, rect_t{}, -100, 100,
GET_SET_DEFAULT(g_model.swashR.elevatorWeight));
// Aileron source
new StaticText(window, grid.getLabelSlot(), STR_AILERON, 0, COLOR_THEME_PRIMARY1);
new SourceChoice(window, grid.getFieldSlot(), 0, MIXSRC_LAST_CH, GET_SET_DEFAULT(g_model.swashR.aileronSource));
grid.nextLine();
line = form->newLine(&grid);
new StaticText(line, rect_t{}, STR_AILERON, 0, COLOR_THEME_PRIMARY1);
new SourceChoice(line, rect_t{}, 0, MIXSRC_LAST_CH,
GET_SET_DEFAULT(g_model.swashR.aileronSource));
// Aileron weight
new StaticText(window, grid.getLabelSlot(), STR_WEIGHT, 0, COLOR_THEME_PRIMARY1);
new NumberEdit(window, grid.getFieldSlot(), -100, 100, GET_SET_DEFAULT(g_model.swashR.aileronWeight));
grid.nextLine();
line = form->newLine(&grid);
new StaticText(line, rect_t{}, STR_WEIGHT, 0, COLOR_THEME_PRIMARY1);
new NumberEdit(line, rect_t{}, -100, 100,
GET_SET_DEFAULT(g_model.swashR.aileronWeight));
// Collective source
new StaticText(window, grid.getLabelSlot(), STR_COLLECTIVE, 0, COLOR_THEME_PRIMARY1);
new SourceChoice(window, grid.getFieldSlot(), 0, MIXSRC_LAST_CH, GET_SET_DEFAULT(g_model.swashR.collectiveSource));
grid.nextLine();
line = form->newLine(&grid);
new StaticText(line, rect_t{}, STR_COLLECTIVE, 0, COLOR_THEME_PRIMARY1);
new SourceChoice(line, rect_t{}, 0, MIXSRC_LAST_CH,
GET_SET_DEFAULT(g_model.swashR.collectiveSource));
// Collective weight
new StaticText(window, grid.getLabelSlot(), STR_WEIGHT, 0, COLOR_THEME_PRIMARY1);
new NumberEdit(window, grid.getFieldSlot(), -100, 100, GET_SET_DEFAULT(g_model.swashR.collectiveWeight));
line = form->newLine(&grid);
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);
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)
+1 -1
View File
@@ -59,7 +59,7 @@ class SourceChoiceMenuToolbar : public MenuToolbar<SourceChoice>
// defined in gui/gui_common.cpp
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,
std::function<void(int16_t)> setValue,
WindowFlags windowFlags, LcdFlags textFlags) :
+1 -1
View File
@@ -33,7 +33,7 @@ class SourceChoice : public ChoiceEx
friend class MenuToolbar;
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,
std::function<void(int16_t)> setValue,
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,
std::function<void(int16_t)> 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;
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<void(int16_t)> setValue);
+1 -1
View File
@@ -34,7 +34,7 @@
#include "view_text.h"
ViewMainMenu::ViewMainMenu(Window* parent) :
Window(parent->getFullScreenWindow(), {})
Window(parent->getFullScreenWindow(), rect_t{})
{
// Save focus
Layer::push(this);
+93 -72
View File
@@ -20,9 +20,10 @@
*/
#include "opentx.h"
#include "libopenui.h"
#include "widget_settings.h"
#include "libopenui.h"
#include "view_main.h"
#define SET_DIRTY() storageDirty(EE_MODEL)
@@ -33,125 +34,145 @@ static const rect_t widgetSettingsDialogRect = {
LCD_H - 2 * LCD_H / 5 // height
};
WidgetSettings::WidgetSettings(Window * parent, Widget * widget) :
Dialog(parent, TR_WIDGET_SETTINGS, widgetSettingsDialogRect)
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};
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);
auto form = &content->form;
FormGridLayout grid(content->form.width(), 10);
grid.setLabelWidth(width() / 3);
form->clear();
form->setFlexLayout();
FlexGridLayout grid(line_col_dsc, line_row_dsc);
uint8_t optIdx = 0;
auto optPtr = widget->getOptions();
while (optPtr && optPtr->name != nullptr) {
auto line = form->newLine(&grid);
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) {
case ZoneOption::Integer:
new NumberEdit(form, grid.getFieldSlot(), option.min.signedValue, option.max.signedValue,
[=]() -> int {
return widget->getOptionValue(optIdx)->signedValue;
},
[=](int32_t newValue) {
widget->getOptionValue(optIdx)->signedValue = newValue;
});
new NumberEdit(
line, rect_t{}, option.min.signedValue,
option.max.signedValue,
[=]() -> int {
return widget->getOptionValue(optIdx)->signedValue;
},
[=](int32_t newValue) {
widget->getOptionValue(optIdx)->signedValue = newValue;
});
break;
case ZoneOption::Source:
new SourceChoice(form, grid.getFieldSlot(), 0, MIXSRC_LAST_TELEM,
[=]() -> int16_t {
return (int16_t) widget->getOptionValue(optIdx)->unsignedValue;
},
[=](int16_t newValue) {
widget->getOptionValue(optIdx)->unsignedValue = (uint32_t)newValue;
});
new SourceChoice(
line, rect_t{}, 0, MIXSRC_LAST_TELEM,
[=]() -> int16_t {
return (int16_t)widget->getOptionValue(optIdx)->unsignedValue;
},
[=](int16_t newValue) {
widget->getOptionValue(optIdx)->unsignedValue =
(uint32_t)newValue;
});
break;
case ZoneOption::Bool:
new CheckBox(form, grid.getFieldSlot(),
[=]() -> uint8_t {
return (uint8_t) widget->getOptionValue(optIdx)->boolValue;
},
[=](int8_t newValue) {
widget->getOptionValue(optIdx)->boolValue = newValue;
SET_DIRTY();
});
new CheckBox(
line, rect_t{},
[=]() -> uint8_t {
return (uint8_t)widget->getOptionValue(optIdx)->boolValue;
},
[=](int8_t newValue) {
widget->getOptionValue(optIdx)->boolValue = newValue;
SET_DIRTY();
});
break;
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;
case ZoneOption::File:
break;
case ZoneOption::TextSize: {
new Choice(form, grid.getFieldSlot(), STR_FONT_SIZES, 0, FONTS_COUNT - 1,
[=]() -> int { // getValue
return (int) widget->getOptionValue(optIdx)->unsignedValue;
},
[=](int newValue) { // setValue
widget->getOptionValue(optIdx)->unsignedValue = (uint32_t) newValue;
SET_DIRTY();
});
new Choice(
line, rect_t{}, STR_FONT_SIZES, 0, FONTS_COUNT - 1,
[=]() -> int { // getValue
return (int)widget->getOptionValue(optIdx)->unsignedValue;
},
[=](int newValue) { // setValue
widget->getOptionValue(optIdx)->unsignedValue =
(uint32_t)newValue;
SET_DIRTY();
});
break;
}
case ZoneOption::Timer: // Unsigned
case ZoneOption::Timer: // Unsigned
{
auto tmChoice = new Choice(form, grid.getFieldSlot(), 0, TIMERS - 1,
[=]() -> int { // getValue
return (int) widget->getOptionValue(optIdx)->unsignedValue;
},
[=](int newValue) { // setValue
widget->getOptionValue(optIdx)->unsignedValue = (uint32_t) newValue;
});
auto tmChoice = new Choice(
line, rect_t{}, 0, TIMERS - 1,
[=]() -> int { // getValue
return (int)widget->getOptionValue(optIdx)->unsignedValue;
},
[=](int newValue) { // setValue
widget->getOptionValue(optIdx)->unsignedValue =
(uint32_t)newValue;
});
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:
new SwitchChoice(form, grid.getFieldSlot(),
option.min.unsignedValue, // min
option.max.unsignedValue, // max
[=]() -> int16_t { // getValue
return (uint8_t) widget->getOptionValue(optIdx)->unsignedValue;
},
[=](int16_t newValue) { // setValue
widget->getOptionValue(optIdx)->unsignedValue = (uint32_t) newValue;
});
new SwitchChoice(
line, rect_t{},
option.min.unsignedValue, // min
option.max.unsignedValue, // max
[=]() -> int16_t { // getValue
return (uint8_t)widget->getOptionValue(optIdx)->unsignedValue;
},
[=](int16_t newValue) { // setValue
widget->getOptionValue(optIdx)->unsignedValue =
(uint32_t)newValue;
});
break;
case ZoneOption::Color:
new ColorEdit(form, grid.getFieldSlot(),
[=]() -> int { // getValue
return (int) widget->getOptionValue(optIdx)->unsignedValue;
},
[=](int newValue) { // setValue
widget->getOptionValue(optIdx)->unsignedValue = (uint32_t) newValue;
SET_DIRTY();
});
new ColorEdit(
line, rect_t{},
[=]() -> int { // getValue
return (int)widget->getOptionValue(optIdx)->unsignedValue;
},
[=](int newValue) { // setValue
widget->getOptionValue(optIdx)->unsignedValue =
(uint32_t)newValue;
SET_DIRTY();
});
break;
}
optIdx++;
optPtr++;
grid.nextLine();
}
setCloseHandler([widget]() {
widget->update();
});
content->updateSize();
setCloseHandler([=]() { widget->update(); });
}
#if defined(HARDWARE_KEYS)
void WidgetSettings::onEvent(event_t event)
+4 -6
View File
@@ -24,14 +24,12 @@
#include "dialog.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)
void onEvent(event_t event) override;
void onEvent(event_t event) override;
#endif
};