refactor(color): UI code cleanup, speed up loading of complex pages (#5031)

This commit is contained in:
philmoz
2024-06-06 20:08:13 +10:00
committed by GitHub
parent 65e05085a4
commit 97f9884639
176 changed files with 3747 additions and 3534 deletions
@@ -154,7 +154,7 @@ void BitmapBuffer::drawGPSPosition(coord_t x, coord_t y, int32_t longitude,
{
if (flags & PREC1) {
drawGPSCoord(x, y, latitude, "NS", flags, true);
drawGPSCoord(x, y + FH, longitude, "EW", flags, true);
drawGPSCoord(x, y + EdgeTxStyles::PAGE_LINE_HEIGHT, longitude, "EW", flags, true);
} else {
if (flags & RIGHT) {
x = drawGPSCoord(x, y, longitude, "EW", flags, true);
@@ -181,7 +181,7 @@ void BitmapBuffer::drawDate(coord_t x, coord_t y, TelemetryItem &telemetryItem,
x = drawText(x, y, s.c_str(), att);
if (doTwoLines) {
y += FH;
y += EdgeTxStyles::PAGE_LINE_HEIGHT;
x = ox;
} else {
x += 11;
+8 -6
View File
@@ -34,7 +34,7 @@ const lv_obj_class_t button_class = {
.user_data = nullptr,
.event_cb = nullptr,
.width_def = LV_SIZE_CONTENT,
.height_def = 32,
.height_def = EdgeTxStyles::UI_ELEMENT_HEIGHT,
.editable = LV_OBJ_CLASS_EDITABLE_INHERIT,
.group_def = LV_OBJ_CLASS_GROUP_DEF_TRUE,
.instance_size = sizeof(lv_btn_t),
@@ -54,7 +54,8 @@ Button::Button(Window* parent, const rect_t& rect,
ButtonBase::ButtonBase(Window* parent, const rect_t& rect,
std::function<uint8_t(void)> pressHandler,
LvglCreate objConstruct) :
FormField(parent, rect, 0, objConstruct ? objConstruct : lv_btn_create),
FormField(parent, rect, 0,
objConstruct ? objConstruct : lv_btn_create),
pressHandler(std::move(pressHandler))
{
lv_obj_add_event_cb(lvobj, ButtonBase::long_pressed, LV_EVENT_LONG_PRESSED,
@@ -106,20 +107,21 @@ void ButtonBase::long_pressed(lv_event_t* e)
TextButton::TextButton(Window* parent, const rect_t& rect, std::string text,
std::function<uint8_t(void)> pressHandler) :
ButtonBase(parent, rect, pressHandler, button_create), text(std::move(text))
ButtonBase(parent, rect, pressHandler, button_create),
text(std::move(text))
{
label = lv_label_create(lvobj);
lv_label_set_text(label, this->text.c_str());
lv_obj_center(label);
}
IconButton::IconButton(Window* parent, EdgeTxIcon icon,
IconButton::IconButton(Window* parent, EdgeTxIcon icon, coord_t x, coord_t y,
std::function<uint8_t(void)> pressHandler) :
ButtonBase(parent, {0, 0, 32, 32}, pressHandler, button_create)
ButtonBase(parent, {x, y, EdgeTxStyles::UI_ELEMENT_HEIGHT, EdgeTxStyles::UI_ELEMENT_HEIGHT}, pressHandler, button_create)
{
padAll(PAD_ZERO);
iconImage = new StaticIcon(this, 0, 0, icon, COLOR_THEME_SECONDARY1);
iconImage->center(28, 28);
iconImage->center(EdgeTxStyles::UI_ELEMENT_HEIGHT - 4, EdgeTxStyles::UI_ELEMENT_HEIGHT - 4);
}
void IconButton::setIcon(EdgeTxIcon icon) { iconImage->setIcon(icon); }
+8 -1
View File
@@ -96,6 +96,13 @@ class TextButton : public ButtonBase
}
}
void setWrap()
{
lv_obj_set_width(label, lv_pct(100));
etx_obj_add_style(label, styles->text_align_center, LV_PART_MAIN);
lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP);
}
protected:
lv_obj_t* label = nullptr;
@@ -105,7 +112,7 @@ class TextButton : public ButtonBase
class IconButton : public ButtonBase
{
public:
IconButton(Window* parent, EdgeTxIcon icon,
IconButton(Window* parent, EdgeTxIcon icon, coord_t x, coord_t y,
std::function<uint8_t(void)> pressHandler = nullptr);
void setIcon(EdgeTxIcon icon);
+12 -15
View File
@@ -36,7 +36,7 @@ static const lv_obj_class_t choice_class = {
.user_data = nullptr,
.event_cb = nullptr,
.width_def = LV_SIZE_CONTENT,
.height_def = 32,
.height_def = EdgeTxStyles::UI_ELEMENT_HEIGHT,
.editable = LV_OBJ_CLASS_EDITABLE_INHERIT,
.group_def = LV_OBJ_CLASS_GROUP_DEF_INHERIT,
.instance_size = sizeof(lv_obj_t),
@@ -66,23 +66,19 @@ void choice_changed_cb(lv_event_t* e)
ChoiceBase::ChoiceBase(Window* parent, const rect_t& rect, ChoiceType type) :
FormField(parent, rect, 0, choice_create), type(type)
{
lv_obj_set_layout(lvobj, LV_LAYOUT_FLEX);
lv_obj_set_flex_flow(lvobj, LV_FLEX_FLOW_ROW);
lv_obj_set_flex_align(lvobj, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER,
LV_FLEX_ALIGN_SPACE_AROUND);
lv_obj_add_event_cb(lvobj, choice_changed_cb, LV_EVENT_VALUE_CHANGED, lvobj);
label = lv_label_create(lvobj);
lv_group_t* def_group = lv_group_get_default();
if (def_group) {
lv_group_add_obj(def_group, lvobj);
}
// add the image
lv_obj_t* img = lv_img_create(lvobj);
lv_img_set_src(
img, type == CHOICE_TYPE_DROPOWN ? LV_SYMBOL_DOWN : LV_SYMBOL_DIRECTORY);
lv_obj_set_pos(img, 0, PAD_TINY);
lv_obj_add_event_cb(lvobj, choice_changed_cb, LV_EVENT_VALUE_CHANGED, lvobj);
label = lv_label_create(lvobj);
lv_obj_set_pos(label, ICON_W, PAD_TINY);
lv_group_t* def_group = lv_group_get_default();
if (def_group)
lv_group_add_obj(def_group, lvobj);
}
std::string Choice::getLabelText()
@@ -188,7 +184,8 @@ void Choice::onClicked()
void Choice::fillMenu(Menu* menu, const FilterFct& filter)
{
menu->removeLines();
if (menu->count() > 0)
menu->removeLines();
auto value = getIntValue();
int count = 0;
+2 -2
View File
@@ -32,8 +32,6 @@ typedef struct {
class Menu;
constexpr int CHOICE_LABEL_MARGIN_RIGHT = 10;
enum ChoiceType {
CHOICE_TYPE_DROPOWN,
CHOICE_TYPE_FOLDER,
@@ -47,6 +45,8 @@ class ChoiceBase : public FormField
void setChoiceType(ChoiceType t) { type = t; }
static LAYOUT_VAL(ICON_W, 18, 18)
protected:
ChoiceType type;
lv_obj_t *label;
+49
View File
@@ -165,3 +165,52 @@ void ConfirmDialog::onCancel()
deleteLater();
if (cancelHandler) cancelHandler();
}
//-----------------------------------------------------------------------------
LabelDialog::LabelDialog(Window *parent, const char *label, int length, const char* title,
std::function<void(std::string)> _saveHandler) :
ModalWindow(parent, false), saveHandler(std::move(_saveHandler))
{
assert(length <= MAX_LABEL_LENGTH);
strncpy(this->label, label, length);
this->label[length] = '\0';
auto form = new Window(this, rect_t{});
form->padAll(PAD_ZERO);
form->setFlexLayout(LV_FLEX_FLOW_COLUMN, PAD_ZERO, LCD_W * 0.8,
LV_SIZE_CONTENT);
etx_solid_bg(form->getLvObj());
lv_obj_center(form->getLvObj());
auto hdr = new StaticText(form, {0, 0, LV_PCT(100), 0}, title,
COLOR_THEME_PRIMARY2);
etx_solid_bg(hdr->getLvObj(), COLOR_THEME_SECONDARY1_INDEX);
hdr->padAll(PAD_MEDIUM);
auto box = new Window(form, rect_t{});
box->padAll(PAD_MEDIUM);
box->setFlexLayout(LV_FLEX_FLOW_ROW, 40, LV_PCT(100), LV_SIZE_CONTENT);
lv_obj_set_flex_align(box->getLvObj(), LV_FLEX_ALIGN_CENTER,
LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_SPACE_BETWEEN);
new TextEdit(box, rect_t{0, 0, LV_PCT(100), 0}, this->label, length);
box = new Window(form, rect_t{});
box->padAll(PAD_MEDIUM);
box->setFlexLayout(LV_FLEX_FLOW_ROW, 40, LV_PCT(100), LV_SIZE_CONTENT);
lv_obj_set_flex_align(box->getLvObj(), LV_FLEX_ALIGN_CENTER,
LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_SPACE_BETWEEN);
new TextButton(box, rect_t{0, 0, 96, 0}, STR_CANCEL, [=]() {
deleteLater();
return 0;
});
new TextButton(box, rect_t{0, 0, 96, 0}, STR_SAVE, [=]() {
if (saveHandler != nullptr) saveHandler(this->label);
deleteLater();
return 0;
});
}
+18 -1
View File
@@ -97,7 +97,7 @@ class DynamicMessageDialog : public BaseDialog
DynamicMessageDialog(Window* parent, const char* title,
std::function<std::string()> textHandler,
const char* message = "",
const int lineHeight = PAGE_LINE_HEIGHT,
const int lineHeight = EdgeTxStyles::PAGE_LINE_HEIGHT,
const LcdFlags textFlags = CENTERED);
// Attn.: FONT(XXL) is not supported by DynamicMessageDialog
@@ -127,3 +127,20 @@ class ConfirmDialog : public BaseDialog
void onCancel() override;
};
//-----------------------------------------------------------------------------
class LabelDialog : public ModalWindow
{
public:
LabelDialog(Window *parent, const char *label, int length, const char* title,
std::function<void(std::string)> _saveHandler = nullptr);
static constexpr int MAX_LABEL_LENGTH = 255;
void onCancel() override { deleteLater(); }
protected:
std::function<void(std::string)> saveHandler;
char label[MAX_LABEL_LENGTH + 1];
};
-12
View File
@@ -39,12 +39,6 @@ void FlexGridLayout::add(Window* w)
}
}
FormField::FormField(const rect_t& rect, LcdFlags textFlags) :
Window(rect)
{
setTextFlag(textFlags);
}
FormField::FormField(Window* parent, const rect_t& rect, LcdFlags textFlags,
LvglCreate objConstruct) :
Window(parent, rect, objConstruct)
@@ -53,12 +47,6 @@ FormField::FormField(Window* parent, const rect_t& rect, LcdFlags textFlags,
lv_obj_add_flag(lvobj, LV_OBJ_FLAG_SCROLL_ON_FOCUS);
}
void FormField::setupLVGL()
{
Window::setupLVGL();
lv_obj_add_flag(lvobj, LV_OBJ_FLAG_SCROLL_ON_FOCUS);
}
void FormField::setEditMode(bool newEditMode)
{
editMode = newEditMode;
-3
View File
@@ -77,12 +77,9 @@ class FlexGridLayout
class FormField : public Window
{
public:
FormField(const rect_t& rect, LcdFlags textFlags);
FormField(Window* parent, const rect_t& rect, LcdFlags textFlags = 0,
LvglCreate objConstruct = nullptr);
void setupLVGL() override;
virtual void changeEnd(bool forceChanged = false)
{
if (changeHandler) {
+1 -1
View File
@@ -155,7 +155,7 @@ NumberKeyboard::NumberKeyboard() : Keyboard(KEYBOARD_HEIGHT)
NumberKeyboard::~NumberKeyboard() { _instance = nullptr; }
void NumberKeyboard::show(NumberEdit* field)
void NumberKeyboard::show(FormField* field)
{
if (!_instance) _instance = new NumberKeyboard();
+1 -3
View File
@@ -20,8 +20,6 @@
#include "keyboard_base.h"
class NumberEdit;
class NumberKeyboard : public Keyboard
{
public:
@@ -32,7 +30,7 @@ class NumberKeyboard : public Keyboard
std::string getName() const override { return "NumberKeyboard"; }
#endif
static void show(NumberEdit* field);
static void show(FormField* field);
void handleEvent(const char* btn);
-25
View File
@@ -24,23 +24,6 @@
#include "keys.h"
#include "opentx_types.h"
constexpr uint32_t MENU_HEADER_BUTTON_WIDTH = 33;
constexpr uint32_t MENU_HEADER_BUTTONS_LEFT = 47;
constexpr uint32_t MENU_HEADER_HEIGHT = 45;
constexpr uint32_t MENU_TITLE_TOP = 48;
constexpr uint32_t MENU_TITLE_HEIGHT = 21;
constexpr uint32_t MENU_BODY_TOP = MENU_TITLE_TOP + MENU_TITLE_HEIGHT;
constexpr uint32_t MENU_BODY_HEIGHT = LCD_H - MENU_BODY_TOP;
constexpr uint32_t MENUS_MARGIN_LEFT = 6;
constexpr uint32_t PAGE_LINE_HEIGHT = 20;
constexpr uint32_t FH = PAGE_LINE_HEIGHT;
constexpr uint32_t NUM_BODY_LINES = MENU_BODY_HEIGHT / PAGE_LINE_HEIGHT;
constexpr uint32_t PAGE_TITLE_TOP = 2;
constexpr uint32_t PAGE_TITLE_LEFT = 50;
// Used by Lua API
#define INVERS 0x01u
#define BLINK 0x1000u
@@ -65,11 +48,3 @@ constexpr uint32_t PAGE_TITLE_LEFT = 50;
#define NO_UNIT 0x40u
#define LV_OBJ_FLAG_ENCODER_ACCEL LV_OBJ_FLAG_USER_1
constexpr coord_t MENUS_LINE_HEIGHT = 35;
#if LCD_W > LCD_H
constexpr coord_t MENUS_MAX_HEIGHT = (MENUS_LINE_HEIGHT * 7) + 8;
#else
constexpr coord_t MENUS_MAX_HEIGHT = (MENUS_LINE_HEIGHT * 10);
#endif
+1 -1
View File
@@ -65,7 +65,7 @@ MenuToolbarButton::MenuToolbarButton(Window* parent, const rect_t& rect,
}
MenuToolbar::MenuToolbar(Choice* choice, Menu* menu, const int columns) :
Window(menu, {0, 0, 76, MENUS_MAX_HEIGHT}),
Window(menu, {0, 0, 0, MENUS_MAX_HEIGHT}),
choice(choice),
menu(menu),
filterColumns(columns),
+9
View File
@@ -20,6 +20,7 @@
#include "button.h"
#include "choice.h"
#include "listbox.h"
class Menu;
@@ -44,6 +45,14 @@ class MenuToolbar : public Window
virtual void longPress() {}
static LAYOUT_VAL(MENUS_TOOLBAR_BUTTON_WIDTH, 32, 32)
#if PORTRAIT_LCD
static constexpr coord_t MENUS_MAX_HEIGHT = (ListBox::MENUS_LINE_HEIGHT * 10);
#else
static constexpr coord_t MENUS_MAX_HEIGHT = (ListBox::MENUS_LINE_HEIGHT * 7) + 8;
#endif
protected:
Choice* choice;
Choice::FilterFct filter;
+322 -148
View File
@@ -23,170 +23,353 @@
#include "strhelpers.h"
#include "themes/etx_lv_theme.h"
static void numberedit_cb(lv_event_t* e)
class NumberArea : public FormField
{
NumberEdit* numEdit = (NumberEdit*)lv_event_get_user_data(e);
if (!numEdit || numEdit->deleted()) return;
public:
NumberArea(Window* parent, const rect_t& rect, int vmin, int vmax,
std::function<int()> getValue,
std::function<void(int)> setValue = nullptr,
LcdFlags textFlags = 0) :
FormField(parent, rect, textFlags, etx_textarea_create),
vmin(vmin),
vmax(vmax),
_getValue(std::move(getValue)),
_setValue(std::move(setValue))
{
if (rect.w == 0) setWidth(DEF_W);
uint32_t key = lv_event_get_key(e);
switch (key) {
case LV_KEY_LEFT:
numEdit->onEvent(EVT_ROTARY_LEFT);
break;
case LV_KEY_RIGHT:
numEdit->onEvent(EVT_ROTARY_RIGHT);
break;
etx_obj_add_style(lvobj, styles->text_align_right, LV_PART_MAIN);
// Allow encoder acceleration
lv_obj_add_flag(lvobj, LV_OBJ_FLAG_ENCODER_ACCEL);
lv_obj_add_event_cb(lvobj, NumberArea::numberedit_cb, LV_EVENT_KEY, this);
update();
}
}
NumberEdit::NumberEdit(Window* parent, const rect_t& rect, int vmin, int vmax,
std::function<int()> getValue,
std::function<void(int)> setValue, LcdFlags textFlags) :
FormField(rect, textFlags),
vmin(vmin),
vmax(vmax),
_getValue(std::move(getValue)),
_setValue(std::move(setValue))
{
lv_obj_enable_style_refresh(false);
#if defined(DEBUG_WINDOWS)
std::string getName() const override
{
return "NumberArea(" + std::to_string(getValue()) + ")";
}
#endif
// Workaround for performance issues with lv_textarea - create on top layer
// not this window then reparent to this window after setup finished
this->parent = parent;
lvobj = lv_textarea_create(lv_layer_top());
void onEvent(event_t event) override
{
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(),
event);
// Do this first - before any styles are applied, otherwise it is very slow
update();
etx_textarea_style(lvobj);
etx_obj_add_style(lvobj, styles->text_align_right, LV_PART_MAIN);
// Allow encoder acceleration
lv_obj_add_flag(lvobj, LV_OBJ_FLAG_ENCODER_ACCEL);
lv_obj_add_event_cb(lvobj, numberedit_cb, LV_EVENT_KEY, this);
lv_obj_set_parent(lvobj, parent->getLvObj());
setupLVGL();
if (rect.w == 0) setWidth(100);
lv_obj_enable_style_refresh(true);
lv_obj_refresh_style(lvobj, LV_PART_ANY, LV_STYLE_PROP_ANY);
}
void NumberEdit::onEvent(event_t event)
{
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(),
event);
if (editMode) {
switch (event) {
if (editMode) {
switch (event) {
#if defined(HARDWARE_KEYS)
case EVT_ROTARY_RIGHT: {
int value = getValue();
auto step = getStep();
step += (rotaryEncoderGetAccel() * getAccelFactor()) / 8;
do {
case EVT_ROTARY_RIGHT: {
int value = getValue();
auto step = vstep;
step += (rotaryEncoderGetAccel() * accelFactor) / 8;
do {
#if defined(USE_HATS_AS_KEYS)
value -= step;
value -= step;
#else
value += step;
value += step;
#endif
} while (isValueAvailable && !isValueAvailable(value) && value <= vmax);
if (value <= vmax) {
setValue(value);
} else {
} while (isValueAvailable && !isValueAvailable(value) &&
value <= vmax);
if (value <= vmax) {
setValue(value);
} else {
setValue(vmax);
onKeyError();
}
return;
}
case EVT_ROTARY_LEFT: {
int value = getValue();
auto step = vstep;
step += (rotaryEncoderGetAccel() * accelFactor) / 8;
do {
#if defined(USE_HATS_AS_KEYS)
value += step;
#else
value -= step;
#endif
} while (isValueAvailable && !isValueAvailable(value) &&
value >= vmin);
if (value >= vmin) {
setValue(value);
} else {
setValue(vmin);
onKeyError();
}
return;
}
#endif
case EVT_VIRTUAL_KEY_PLUS:
setValue(getValue() + vstep);
break;
case EVT_VIRTUAL_KEY_MINUS:
setValue(getValue() - vstep);
break;
case EVT_VIRTUAL_KEY_FORWARD:
setValue(getValue() + fastStep * vstep);
break;
case EVT_VIRTUAL_KEY_BACKWARD:
setValue(getValue() - fastStep * vstep);
break;
case EVT_VIRTUAL_KEY_DEFAULT:
setValue(vdefault);
break;
case EVT_VIRTUAL_KEY_MAX:
setValue(vmax);
onKeyError();
}
return;
}
break;
case EVT_ROTARY_LEFT: {
int value = getValue();
auto step = getStep();
step += (rotaryEncoderGetAccel() * getAccelFactor()) / 8;
do {
#if defined(USE_HATS_AS_KEYS)
value += step;
#else
value -= step;
#endif
} while (isValueAvailable && !isValueAvailable(value) && value >= vmin);
if (value >= vmin) {
setValue(value);
} else {
case EVT_VIRTUAL_KEY_MIN:
setValue(vmin);
onKeyError();
}
return;
break;
case EVT_VIRTUAL_KEY_SIGN:
setValue(-getValue());
break;
}
#endif
}
case EVT_VIRTUAL_KEY_PLUS:
setValue(getValue() + getStep());
break;
FormField::onEvent(event);
}
case EVT_VIRTUAL_KEY_MINUS:
setValue(getValue() - getStep());
break;
case EVT_VIRTUAL_KEY_FORWARD:
setValue(getValue() + getFastStep() * getStep());
break;
case EVT_VIRTUAL_KEY_BACKWARD:
setValue(getValue() - getFastStep() * getStep());
break;
case EVT_VIRTUAL_KEY_DEFAULT:
setValue(getDefault());
break;
case EVT_VIRTUAL_KEY_MAX:
setValue(getMax());
break;
case EVT_VIRTUAL_KEY_MIN:
setValue(getMin());
break;
case EVT_VIRTUAL_KEY_SIGN:
setValue(-getValue());
break;
void onClicked() override
{
lv_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act());
if (indev_type == LV_INDEV_TYPE_POINTER) {
setEditMode(true);
} else {
FormField::onClicked();
}
}
FormField::onEvent(event);
}
void NumberEdit::onClicked()
{
lv_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act());
if (indev_type == LV_INDEV_TYPE_POINTER) {
NumberKeyboard::show(this);
return;
void setMin(int value) { vmin = value; }
void setMax(int value) { vmax = value; }
void setDefault(int value) { vdefault = value; }
void setStep(int value) { vstep = value; }
void setFastStep(int value) { fastStep = value; }
void setAccelFactor(int value) { accelFactor = value; }
void setValue(int value)
{
auto newValue = limit(vmin, value, vmax);
if (newValue != currentValue) {
currentValue = newValue;
if (_setValue != nullptr) {
_setValue(currentValue);
}
}
updateDisplay();
}
FormField::onClicked();
int32_t getValue() const { return _getValue != nullptr ? _getValue() : 0; }
void setPrefix(std::string value) { prefix = std::move(value); }
void setSuffix(std::string value) { suffix = std::move(value); }
void setZeroText(std::string value) { zeroText = std::move(value); }
void setAvailableHandler(std::function<bool(int)> handler)
{
isValueAvailable = std::move(handler);
}
void setSetValueHandler(std::function<void(int)> handler)
{
_setValue = std::move(handler);
}
void setGetValueHandler(std::function<int()> handler)
{
_getValue = std::move(handler);
}
void setDisplayHandler(std::function<std::string(int value)> function)
{
displayFunction = std::move(function);
}
void setCancelHandler(std::function<void(void)> handler)
{
cancelHandler = std::move(handler);
}
void openKeyboard() { NumberKeyboard::show(this); }
void directEdit() { FormField::onClicked(); }
void update()
{
if (_getValue == nullptr) return;
currentValue = _getValue();
updateDisplay();
}
static LAYOUT_VAL(DEF_W, 100, 100)
protected:
int vdefault = 0;
int vmin;
int vmax;
int vstep = 1;
int fastStep = 10;
int accelFactor = 4;
int currentValue;
std::string prefix;
std::string suffix;
std::string zeroText;
std::function<int()> _getValue;
std::function<void(int)> _setValue;
std::function<std::string(int)> displayFunction;
std::function<bool(int)> isValueAvailable;
std::function<void(void)> cancelHandler = nullptr;
void updateDisplay()
{
if (lvobj != nullptr) {
std::string str;
if (displayFunction != nullptr) {
str = displayFunction(currentValue);
} else if (!zeroText.empty() && currentValue == 0) {
str = zeroText;
} else {
str = formatNumberAsString(currentValue, textFlags, 0, prefix.c_str(),
suffix.c_str());
}
lv_textarea_set_text(lvobj, str.c_str());
}
}
void onCancel() override
{
if (cancelHandler)
cancelHandler();
else
FormField::onCancel();
}
static void numberedit_cb(lv_event_t* e)
{
NumberArea* numEdit = (NumberArea*)lv_event_get_user_data(e);
if (!numEdit || numEdit->deleted()) return;
uint32_t key = lv_event_get_key(e);
switch (key) {
case LV_KEY_LEFT:
numEdit->onEvent(EVT_ROTARY_LEFT);
break;
case LV_KEY_RIGHT:
numEdit->onEvent(EVT_ROTARY_RIGHT);
break;
}
}
};
/*
The lv_textarea object is slow. To avoid too much overhead on views with multiple
edit fields, the text area is initially displayed as a button. When the button
is pressed, a text area object is created over the top of the button in order
to edit the value.
*/
NumberEdit::NumberEdit(Window* parent, const rect_t& rect, int vmin, int vmax,
std::function<int()> getValue,
std::function<void(int)> setValue, LcdFlags textFlags) :
TextButton(parent, rect, "",
[=]() {
openEdit();
return 0;
}),
_getValue(std::move(getValue)),
_setValue(std::move(setValue)),
vmin(vmin),
vmax(vmax)
{
if (rect.w == 0) setWidth(NumberArea::DEF_W);
setTextFlag(textFlags);
lv_obj_set_width(label, width() - PAD_MEDIUM * 2 - 2);
if (textFlags & CENTERED)
etx_obj_add_style(label, styles->text_align_center, LV_PART_MAIN);
else
etx_obj_add_style(label, styles->text_align_right, LV_PART_MAIN);
update();
}
void NumberEdit::openEdit()
{
if (edit == nullptr) {
edit = new NumberArea(
this,
{-(PAD_MEDIUM + 2), -(PAD_TINY + 2),
lv_obj_get_width(lvobj), lv_obj_get_height(lvobj)},
this->vmin, this->vmax, _getValue, _setValue, textFlags);
edit->setChangeHandler([=]() {
update();
lv_group_focus_obj(lvobj);
edit->hide();
});
edit->setCancelHandler([=]() {
lv_group_focus_obj(lvobj);
edit->hide();
});
}
edit->setTextFlag(textFlags);
edit->setSetValueHandler(_setValue);
edit->setGetValueHandler(_getValue);
edit->setAvailableHandler(isValueAvailable);
edit->setDisplayHandler(displayFunction);
edit->setDefault(vdefault);
edit->setMin(vmin);
edit->setMax(vmax);
edit->setStep(step);
edit->setFastStep(fastStep);
edit->setAccelFactor(accelFactor);
edit->setPrefix(prefix);
edit->setSuffix(suffix);
edit->setZeroText(zeroText);
edit->update();
edit->show();
lv_group_focus_obj(edit->getLvObj());
lv_indev_type_t indev_type =
lv_indev_get_type(lv_indev_get_act());
if (indev_type == LV_INDEV_TYPE_POINTER) {
edit->openKeyboard();
} else {
edit->directEdit();
}
lv_obj_add_state(lvobj, LV_STATE_FOCUSED);
}
void NumberEdit::update()
{
if (_getValue == nullptr) return;
currentValue = _getValue();
updateDisplay();
}
void NumberEdit::updateDisplay()
{
if (lvobj != nullptr) {
std::string str;
if (displayFunction != nullptr) {
str = displayFunction(currentValue);
} else if (!zeroText.empty() && currentValue == 0) {
str = zeroText;
} else {
str = formatNumberAsString(currentValue, textFlags, 0, prefix.c_str(),
suffix.c_str());
}
lv_textarea_set_text(lvobj, str.c_str());
std::string str;
if (displayFunction != nullptr) {
str = displayFunction(currentValue);
} else if (!zeroText.empty() && currentValue == 0) {
str = zeroText;
} else {
str = formatNumberAsString(currentValue, textFlags, 0, prefix.c_str(),
suffix.c_str());
}
setText(str);
}
void NumberEdit::setValue(int value)
@@ -199,14 +382,5 @@ void NumberEdit::setValue(int value)
}
}
updateDisplay();
}
void NumberEdit::update()
{
if (_getValue == nullptr) return;
auto newValue = _getValue();
if (newValue != currentValue) {
currentValue = newValue;
}
updateDisplay();
if (edit) edit->setValue(value);
}
+73 -126
View File
@@ -19,148 +19,95 @@
#pragma once
#include "form.h"
#include "button.h"
class NumberEdit: public FormField
class NumberArea;
class NumberEdit : public TextButton
{
public:
NumberEdit(Window* parent, const rect_t& rect, int vmin, int vmax,
std::function<int()> getValue,
std::function<void(int)> setValue = nullptr,
LcdFlags textFlags = 0);
public:
NumberEdit(Window* parent, const rect_t& rect, int vmin, int vmax,
std::function<int()> getValue,
std::function<void(int)> setValue = nullptr,
LcdFlags textFlags = 0);
#if defined(DEBUG_WINDOWS)
std::string getName() const override
{
return "NumberEdit(" + std::to_string(getValue()) + ")";
}
std::string getName() const override
{
return "NumberEdit";
}
#endif
void setAvailableHandler(std::function<bool(int)> handler)
{
isValueAvailable = std::move(handler);
}
virtual void update();
void onEvent(event_t event) override;
void onClicked() override;
int32_t getMax() const { return vmax; }
void setMin(int value)
{
vmin = value;
}
void setMin(int value) { vmin = value; }
void setMax(int value) { vmax = value; }
void setDefault(int value) { vdefault = value; }
void setStep(int value) { step = value; }
void setFastStep(int value) { fastStep = value; }
void setAccelFactor(int value) { accelFactor = value; }
void setValue(int value);
void setMax(int value)
{
vmax = value;
}
void setPrefix(std::string value)
{
prefix = std::move(value);
update();
}
void setDefault(int value)
{
vdefault = value;
}
void setSuffix(std::string value)
{
suffix = std::move(value);
update();
}
int32_t getMin() const
{
return vmin;
}
void setZeroText(std::string value)
{
zeroText = std::move(value);
update();
}
int32_t getMax() const
{
return vmax;
}
void setAvailableHandler(std::function<bool(int)> handler)
{
isValueAvailable = std::move(handler);
}
int32_t getDefault() const
{
return vdefault;
}
void setDisplayHandler(std::function<std::string(int value)> function)
{
displayFunction = std::move(function);
update();
}
void setStep(int value)
{
step = value;
}
void setSetValueHandler(std::function<void(int)> handler)
{
_setValue = std::move(handler);
}
int32_t getStep() const
{
return step;
}
void setGetValueHandler(std::function<int()> handler)
{
_getValue = std::move(handler);
}
void setFastStep(int value)
{
fastStep = value;
}
int32_t getValue() const { return _getValue != nullptr ? _getValue() : 0; }
int32_t getFastStep() const
{
return fastStep;
}
protected:
NumberArea* edit = nullptr;
std::function<int()> _getValue;
std::function<void(int)> _setValue;
int vdefault = 0;
int vmin;
int vmax;
int step = 1;
int fastStep = 10;
int accelFactor = 4;
int currentValue;
std::string prefix;
std::string suffix;
std::string zeroText;
std::function<std::string(int)> displayFunction;
std::function<bool(int)> isValueAvailable;
void setAccelFactor(int value)
{
accelFactor = value;
}
int32_t getAccelFactor() const
{
return accelFactor;
}
void setValue(int value);
void setPrefix(std::string value)
{
prefix = std::move(value);
update();
}
void setSuffix(std::string value)
{
suffix = std::move(value);
update();
}
void setZeroText(std::string value)
{
zeroText = std::move(value);
update();
}
void setSetValueHandler(std::function<void(int)> handler)
{
_setValue = std::move(handler);
}
void setGetValueHandler(std::function<int()> handler)
{
_getValue = std::move(handler);
}
int32_t getValue() const
{
return _getValue != nullptr ? _getValue() : 0;
}
void setDisplayHandler(std::function<std::string(int value)> function)
{
displayFunction = std::move(function);
update();
}
virtual void update();
protected:
int vdefault = 0;
int vmin;
int vmax;
int step = 1;
int fastStep = 10;
int accelFactor = 4;
int currentValue;
std::string prefix;
std::string suffix;
std::string zeroText;
std::function<int()> _getValue;
std::function<void(int)> _setValue;
std::function<std::string(int)> displayFunction;
std::function<bool(int)> isValueAvailable;
void updateDisplay();
void updateDisplay();
void openEdit();
};
+1 -1
View File
@@ -36,7 +36,7 @@ static const lv_obj_class_t bar_class = {
.user_data = nullptr,
.event_cb = nullptr,
.width_def = LV_PCT(100),
.height_def = 32,
.height_def = EdgeTxStyles::UI_ELEMENT_HEIGHT,
.editable = LV_OBJ_CLASS_EDITABLE_INHERIT,
.group_def = LV_OBJ_CLASS_GROUP_DEF_INHERIT,
.instance_size = sizeof(lv_bar_t),
+17 -12
View File
@@ -45,7 +45,6 @@ StaticText::StaticText(Window* parent, const rect_t& rect, std::string txt,
LV_PART_MAIN);
lv_label_set_text(lvobj, text.c_str());
if (rect.h == 0) lv_obj_set_height(lvobj, LV_SIZE_CONTENT);
lv_obj_refresh_style(lvobj, LV_PART_ANY, LV_STYLE_PROP_ANY);
}
#if defined(DEBUG_WINDOWS)
@@ -246,22 +245,28 @@ void StaticImage::setZoom()
// Display image from file system with software scaling
// - uglier but much faster than LVGL scaling
StaticBitmap::StaticBitmap(Window* parent, const rect_t& rect,
const char* filename, LcdFlags bgColor) :
Window(parent, rect)
LcdFlags bgColor, const char* filename) :
Window(parent, rect), bgColor(bgColor)
{
setWindowFlag(NO_FOCUS);
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_CLICKABLE);
if (!filename) return;
setSource(filename);
}
img = BitmapBuffer::loadBitmap(filename, BMP_ARGB4444);
if (img) {
img->resizeToLVGL(width(), height(), bgColor);
canvas = lv_canvas_create(lvobj);
lv_obj_center(canvas);
lv_canvas_set_buffer(canvas, img->getData(), img->width(), img->height(),
LV_IMG_CF_TRUE_COLOR);
void StaticBitmap::setSource(const char *filename)
{
if (filename) {
if (img) delete img;
img = BitmapBuffer::loadBitmap(filename, BMP_ARGB4444);
if (img) {
img->resizeToLVGL(width(), height(), bgColor);
if (canvas) lv_obj_del(canvas);
canvas = lv_canvas_create(lvobj);
lv_obj_center(canvas);
lv_canvas_set_buffer(canvas, img->getData(), img->width(), img->height(),
LV_IMG_CF_TRUE_COLOR);
}
}
}
+3 -1
View File
@@ -162,16 +162,18 @@ class StaticBitmap : public Window
{
public:
StaticBitmap(Window *parent, const rect_t &rect,
const char *filename, LcdFlags bgColor);
LcdFlags bgColor, const char *filename = nullptr);
~StaticBitmap();
#if defined(DEBUG_WINDOWS)
std::string getName() const override { return "StaticBitmap"; }
#endif
void setSource(const char *filename);
bool hasImage() const;
protected:
LcdFlags bgColor;
lv_obj_t *canvas = nullptr;
BitmapBuffer *img = nullptr;
};
+140 -51
View File
@@ -27,80 +27,169 @@
#include "menu.h"
#endif
TextEdit::TextEdit(Window* parent, const rect_t& rect, char* value,
uint8_t length) :
FormField(rect, 0), value(value), length(length)
class TextArea : public FormField
{
lv_obj_enable_style_refresh(false);
public:
TextArea(Window* parent, const rect_t& rect, char* value, uint8_t length) :
FormField(parent, rect, 0, etx_textarea_create), value(value), length(length)
{
lv_textarea_set_max_length(lvobj, length);
lv_textarea_set_placeholder_text(lvobj, "---");
// Workaround for performance issues with lv_textarea - create on top layer
// not this window then reparent to this window after setup finished
this->parent = parent;
lvobj = lv_textarea_create(lv_layer_top());
if (rect.w == 0) setWidth(DEF_W);
update();
}
#if defined(DEBUG_WINDOWS)
std::string getName() const override { return "TextArea"; }
#endif
void update()
{
// value may not be null-terminated
std::string txt(value, length);
lv_textarea_set_text(lvobj, txt.c_str());
}
void onClicked() override {
setEditMode(true);
}
void openKeyboard() {
TextKeyboard::show(this);
}
void setCancelHandler(std::function<void(void)> handler)
{
cancelHandler = std::move(handler);
}
static LAYOUT_VAL(DEF_W, 100, 100)
protected:
char* value;
uint8_t length;
std::function<void(void)> cancelHandler = nullptr;
void trim()
{
for (int i = length - 1; i >= 0; i--) {
if (value[i] == ' ' || value[i] == '\0')
value[i] = '\0';
else
break;
}
}
void changeEnd(bool forceChanged = false) override
{
if (lvobj == nullptr) return;
bool changed = false;
auto text = lv_textarea_get_text(lvobj);
if (strncmp(value, text, length) != 0) {
changed = true;
}
if (changed || forceChanged) {
strncpy(value, text, length);
trim();
FormField::changeEnd();
} else if (cancelHandler) {
cancelHandler();
}
}
void onCancel() override
{
if (cancelHandler)
cancelHandler();
else
FormField::onCancel();
}
};
/*
The lv_textarea object is slow. To avoid too much overhead on views with multiple
edit fields, the text area is initially displayed as a button. When the button
is pressed, a text area object is created over the top of the button in order
to edit the value.
*/
TextEdit::TextEdit(Window* parent, const rect_t& rect, char* text,
uint8_t length,
std::function<void(void)> updateHandler) :
TextButton(parent, rect, "", [=]() {
openEdit();
return 0;
}),
updateHandler(updateHandler), text(text), length(length)
{
if (rect.w == 0) setWidth(TextArea::DEF_W);
// Do this first - before any styles are applied, otherwise it is very slow
update();
etx_textarea_style(lvobj);
lv_textarea_set_max_length(lvobj, length);
lv_textarea_set_placeholder_text(lvobj, "---");
lv_obj_set_parent(lvobj, parent->getLvObj());
setupLVGL();
if (rect.w == 0) setWidth(100);
lv_obj_enable_style_refresh(true);
lv_obj_refresh_style(lvobj, LV_PART_ANY, LV_STYLE_PROP_ANY);
lv_obj_align(label, LV_ALIGN_OUT_LEFT_MID, 0, PAD_TINY);
}
void TextEdit::update()
{
// value may not be null-terminated
std::string txt(value, length);
lv_textarea_set_text(lvobj, txt.c_str());
if (text[0]) {
std::string s(text, length);
setText(s);
} else {
setText("---");
}
}
void TextEdit::trim()
void TextEdit::openEdit()
{
for (int i = length - 1; i >= 0; i--) {
if (value[i] == ' ' || value[i] == '\0')
value[i] = '\0';
else
break;
if (edit == nullptr) {
edit = new TextArea(this,
{-(PAD_MEDIUM + 2), -(PAD_TINY + 2),
lv_obj_get_width(lvobj), lv_obj_get_height(lvobj)},
text, length);
edit->setChangeHandler([=]() {
std::string s(text, length);
setText(s);
if (updateHandler) updateHandler();
lv_group_focus_obj(lvobj);
edit->hide();
});
edit->setCancelHandler([=]() {
lv_group_focus_obj(lvobj);
edit->hide();
});
}
edit->show();
lv_group_focus_obj(edit->getLvObj());
edit->openKeyboard();
lv_obj_add_state(lvobj, LV_STATE_FOCUSED);
}
void TextEdit::changeEnd(bool forceChanged)
void TextEdit::preview(bool edited, char* text, uint8_t length)
{
if (lvobj == nullptr) return;
bool changed = false;
auto text = lv_textarea_get_text(lvobj);
if (strncmp(value, text, length) != 0) {
changed = true;
}
if (changed || forceChanged) {
strncpy(value, text, length);
trim();
FormField::changeEnd();
}
edit = new TextArea(this,
{-(PAD_MEDIUM + 2), -(PAD_TINY + 2), width(), height()},
text, length);
lv_group_focus_obj(edit->getLvObj());
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_CLICKABLE);
lv_obj_clear_flag(edit->getLvObj(), LV_OBJ_FLAG_CLICKABLE);
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_CLICK_FOCUSABLE);
lv_obj_clear_flag(edit->getLvObj(), LV_OBJ_FLAG_CLICK_FOCUSABLE);
lv_obj_add_state(edit->getLvObj(), LV_STATE_FOCUSED);
if (edited) lv_obj_add_state(edit->getLvObj(), LV_STATE_EDITED);
}
void TextEdit::onClicked() { TextKeyboard::show(this); }
ModelTextEdit::ModelTextEdit(Window* parent, const rect_t& rect, char* value,
uint8_t length) :
TextEdit(parent, rect, value, length)
TextEdit(parent, rect, value, length,
[]() { storageDirty(EE_MODEL); })
{
setChangeHandler([]() { storageDirty(EE_MODEL); });
}
RadioTextEdit::RadioTextEdit(Window* parent, const rect_t& rect, char* value,
uint8_t length) :
TextEdit(parent, rect, value, length)
TextEdit(parent, rect, value, length,
[]() { storageDirty(EE_GENERAL); })
{
setChangeHandler([]() { storageDirty(EE_GENERAL); });
}
+14 -13
View File
@@ -19,31 +19,32 @@
#pragma once
#include "form.h"
#include "button.h"
class TextEdit : public FormField
class TextArea;
class TextEdit : public TextButton
{
public:
TextEdit(Window* parent, const rect_t& rect, char* value, uint8_t length);
TextEdit(Window* parent, const rect_t& rect, char* text, uint8_t length,
std::function<void(void)> updateHandler = nullptr);
#if defined(DEBUG_WINDOWS)
std::string getName() const override { return "TextEdit"; }
std::string getName() const override { return "TextEdit \"" + text + "\""; }
#endif
uint8_t getMaxLength() const { return length; }
char* getData() const { return value; }
void preview(bool edited, char* text, uint8_t length);
void update();
protected:
static void event_cb(lv_event_t* e);
static LAYOUT_VAL(DEF_W, 100, 100)
char* value;
protected:
std::function<void(void)> updateHandler = nullptr;
TextArea* edit = nullptr;
char* text;
uint8_t length;
void trim();
void changeEnd(bool forceChanged = false) override;
void onClicked() override;
void openEdit();
};
class ModelTextEdit : public TextEdit
+2 -2
View File
@@ -55,8 +55,8 @@ static const lv_obj_class_t switch_class = {
.destructor_cb = nullptr,
.user_data = nullptr,
.event_cb = nullptr,
.width_def = 0,
.height_def = 32,
.width_def = ToggleSwitch::TOGGLE_W,
.height_def = EdgeTxStyles::UI_ELEMENT_HEIGHT,
.editable = LV_OBJ_CLASS_EDITABLE_INHERIT,
.group_def = LV_OBJ_CLASS_GROUP_DEF_INHERIT,
.instance_size = sizeof(lv_switch_t),
+3 -1
View File
@@ -47,7 +47,9 @@ class ToggleSwitch : public FormField
}
void update() const;
static LAYOUT_VAL(TOGGLE_W, 52, 52)
protected:
std::function<uint8_t()> _getValue;
std::function<void(uint8_t)> _setValue;
+93 -7
View File
@@ -20,6 +20,7 @@
#include "button.h"
#include "form.h"
#include "static.h"
#include "themes/etx_lv_theme.h"
std::list<Window *> Window::trash;
@@ -103,11 +104,6 @@ Window::Window(Window *parent, const rect_t &rect, LvglCreate objConstruct) :
if (objConstruct == nullptr) objConstruct = window_create;
lvobj = objConstruct(lv_parent);
Window::setupLVGL();
}
void Window::setupLVGL()
{
lv_obj_set_user_data(lvobj, this);
lv_obj_add_event_cb(lvobj, Window::window_event_cb, LV_EVENT_ALL, nullptr);
@@ -115,7 +111,6 @@ void Window::setupLVGL()
if (rect.w) lv_obj_set_width(lvobj, rect.w);
if (rect.h) lv_obj_set_height(lvobj, rect.h);
// lv_obj_set_scrollbar_mode(lvobj, LV_SCROLLBAR_MODE_OFF);
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_SCROLL_ELASTIC);
if (parent) {
@@ -382,7 +377,7 @@ void Window::enable(bool enabled)
void Window::addBackButton()
{
new ButtonBase(
this, {0, 0, MENU_HEADER_HEIGHT, MENU_HEADER_HEIGHT},
this, {0, 0, EdgeTxStyles::MENU_HEADER_HEIGHT, EdgeTxStyles::MENU_HEADER_HEIGHT},
[=]() -> uint8_t {
onCancel();
return 0;
@@ -439,3 +434,94 @@ NavWindow::NavWindow(Window *parent, const rect_t &rect,
{
setWindowFlag(OPAQUE);
}
SetupButtonGroup::SetupButtonGroup(Window* parent, const rect_t& rect, const char* title, int cols,
PaddingSize padding, PageDefs pages, coord_t btnHeight) :
Window(parent, rect)
{
padAll(padding);
coord_t buttonWidth = (width() - PAD_SMALL * (cols + 1) - PAD_TINY * 2) / cols;
int rows = (pages.size() + cols - 1) / cols;
int height = rows * btnHeight + (rows - 1) * PAD_MEDIUM + PAD_TINY * 2;
if (title) {
height += EdgeTxStyles::PAGE_LINE_HEIGHT + PAD_TINY;
}
setHeight(height);
if (title)
new Subtitle(this, title);
int n = 0;
int remaining = pages.size();
coord_t yo = title ? EdgeTxStyles::PAGE_LINE_HEIGHT + PAD_TINY : 0;
coord_t xw = buttonWidth + PAD_SMALL;
coord_t xo = (width() - (cols * xw - PAD_SMALL)) / 2;
coord_t x, y;
for (auto& entry : pages) {
if (remaining < cols && (n % cols == 0)) {
coord_t space = ((cols - remaining) * xw) / (remaining + 1);
xw += space;
xo += space;
}
x = xo + (n % cols) * xw;
y = yo + (n / cols) * (btnHeight + PAD_MEDIUM);
// TODO: sort out all caps title strings VS quick menu strings
std::string title(entry.title);
for (std::string::iterator it = title.begin(); it != title.end(); ++it) {
if (*it == '\n')
*it = ' ';
}
auto btn = new TextButton(this, rect_t{x, y, buttonWidth, btnHeight}, title, [&, entry]() {
entry.createPage();
return 0;
});
btn->setWrap();
if (entry.isActive) btn->setCheckHandler([=]() { btn->check(entry.isActive()); });
n += 1;
remaining -= 1;
}
}
SetupLine::SetupLine(Window* parent, coord_t y, coord_t col2, PaddingSize padding, const char* title,
std::function<void(Window*, coord_t, coord_t)> createEdit, coord_t lblYOffset) :
Window(parent, {0, y, LCD_W - padding * 2, 0})
{
padAll(PAD_ZERO);
coord_t titleY = PAD_MEDIUM + 1 + lblYOffset;
coord_t titleH = EdgeTxStyles::PAGE_LINE_HEIGHT;
coord_t h = EdgeTxStyles::UI_ELEMENT_HEIGHT + PAD_TINY * 2 + lblYOffset * 2;
if (createEdit) {
coord_t editY = PAD_TINY;
coord_t lblWidth = col2 - PAD_SMALL - PAD_TINY;
if (title) {
if (getTextWidth(title) >= lblWidth) {
h += PAD_MEDIUM;
titleY = 0;
titleH = EdgeTxStyles::UI_ELEMENT_HEIGHT + PAD_TINY + 1;
editY = PAD_SMALL + 1;
}
new StaticText(this, {PAD_TINY, titleY, lblWidth, titleH}, title);
}
setHeight(h);
createEdit(this, col2, editY);
} else {
setHeight(h);
new StaticText(this, {0, titleY, 0, titleH}, title, COLOR_THEME_PRIMARY1 | FONT(BOLD));
}
}
coord_t SetupLine::showLines(Window* parent, coord_t y, coord_t col2, PaddingSize padding, SetupLineDef* setupLines, int lineCount)
{
Window* w;
for (int i = 0; i < lineCount; i += 1) {
w = new SetupLine(parent, y, col2, padding, setupLines[i].title, setupLines[i].createEdit);
y += w->height() + padding;
}
return y;
}
+39 -14
View File
@@ -26,6 +26,7 @@
#include "bitmapbuffer.h"
#include "libopenui_defines.h"
#include "opentx_helpers.h"
#include "themes/etx_lv_theme.h"
typedef uint32_t WindowFlags;
@@ -33,14 +34,6 @@ typedef uint32_t WindowFlags;
#undef OPAQUE
#endif
enum PaddingSize {
PAD_ZERO = 0,
PAD_TINY = 2,
PAD_SMALL = 4,
PAD_MEDIUM = 6,
PAD_LARGE = 8
};
constexpr WindowFlags OPAQUE = 1u << 0u;
constexpr WindowFlags NO_FOCUS = 1u << 1u;
@@ -55,8 +48,6 @@ class Window
Window(const rect_t &rect);
Window(Window *parent, const rect_t &rect, LvglCreate objConstruct = nullptr);
virtual void setupLVGL();
virtual ~Window();
#if defined(DEBUG_WINDOWS)
@@ -91,11 +82,8 @@ class Window
void setRect(rect_t value)
{
rect = value;
lv_obj_enable_style_refresh(false);
lv_obj_set_pos(lvobj, rect.x, rect.y);
lv_obj_set_size(lvobj, rect.w, rect.h);
lv_obj_enable_style_refresh(true);
lv_obj_refresh_style(lvobj, LV_PART_ANY, LV_STYLE_PROP_ANY);
}
void setWidth(coord_t value)
@@ -181,7 +169,7 @@ class Window
virtual bool isBubblePopup() { return false; }
void setFlexLayout(lv_flex_flow_t flow = LV_FLEX_FLOW_COLUMN,
lv_coord_t padding = 2, coord_t width = LV_PCT(100),
lv_coord_t padding = PAD_TINY, coord_t width = LV_PCT(100),
coord_t height = LV_SIZE_CONTENT);
FormLine *newLine(FlexGridLayout &layout);
@@ -238,3 +226,40 @@ class NavWindow : public Window
virtual bool bubbleEvents() { return true; }
void onEvent(event_t event) override;
};
struct PageButtonDef {
const char* title;
std::function<void()> createPage;
std::function<bool()> isActive;
PageButtonDef(const char* title, std::function<void()> createPage, std::function<bool()> isActive = nullptr) :
title(title), createPage(std::move(createPage)), isActive(std::move(isActive))
{}
};
class SetupButtonGroup : public Window
{
public:
typedef std::list<PageButtonDef> PageDefs;
SetupButtonGroup(Window* parent, const rect_t& rect, const char* title, int cols,
PaddingSize padding, PageDefs pages, coord_t btnHeight = EdgeTxStyles::UI_ELEMENT_HEIGHT);
protected:
};
struct SetupLineDef {
const char* title;
std::function<void(Window*, coord_t, coord_t)> createEdit;
};
class SetupLine : public Window
{
public:
SetupLine(Window* parent, coord_t y, coord_t col2, PaddingSize padding, const char* title,
std::function<void(Window*, coord_t, coord_t)> createEdit, coord_t lblYOffset = 0);
static coord_t showLines(Window* parent, coord_t y, coord_t col2, PaddingSize padding, SetupLineDef* setupLines, int lineCount);
protected:
};
@@ -188,5 +188,9 @@ endforeach()
foreach(LVGL_FILE ${LVGL_SOURCES})
set(LVGL_SRC_FILES ${LVGL_SRC_FILES} ${LVGL_SRC_DIR}/${LVGL_FILE})
endforeach()
foreach(LVGL_FILE ${LVGL_SRC_FILES})
SET_SOURCE_FILES_PROPERTIES( ${LVGL_FILE} PROPERTIES COMPILE_FLAGS -O3 )
endforeach()
set(SRC ${SRC} ${LVGL_SRC_FILES})