feat(color): allow all UI controls for widgets when full screen (#5808)
This commit is contained in:
@@ -54,10 +54,6 @@ class SourceChoiceMenuToolbar : public MenuToolbar
|
||||
[=](int16_t index) {
|
||||
if (index >= MIXSRC_FIRST_POT && index <= MIXSRC_LAST_POT)
|
||||
return false;
|
||||
#if MAX_AXIS > 0
|
||||
if (index >= MIXSRC_FIRST_AXIS && index <= MIXSRC_LAST_AXIS)
|
||||
return false;
|
||||
#endif
|
||||
return index >= MIXSRC_FIRST_STICK && index <= lastSource;
|
||||
},
|
||||
STR_MENU_STICKS);
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#include "static.h"
|
||||
#include "etx_lv_theme.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static void button_constructor(const lv_obj_class_t* class_p, lv_obj_t* obj)
|
||||
{
|
||||
etx_btn_style(obj, LV_PART_MAIN);
|
||||
@@ -51,6 +53,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) :
|
||||
@@ -97,6 +101,8 @@ void ButtonBase::checkEvents()
|
||||
if (checkHandler) checkHandler();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
TextButton::TextButton(Window* parent, const rect_t& rect, std::string text,
|
||||
std::function<uint8_t(void)> pressHandler) :
|
||||
ButtonBase(parent, rect, pressHandler, button_create),
|
||||
@@ -107,6 +113,8 @@ TextButton::TextButton(Window* parent, const rect_t& rect, std::string text,
|
||||
lv_obj_center(label);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IconButton::IconButton(Window* parent, EdgeTxIcon icon, coord_t x, coord_t y,
|
||||
std::function<uint8_t(void)> pressHandler) :
|
||||
ButtonBase(parent, {x, y, EdgeTxStyles::UI_ELEMENT_HEIGHT, EdgeTxStyles::UI_ELEMENT_HEIGHT}, pressHandler, button_create)
|
||||
@@ -117,3 +125,33 @@ IconButton::IconButton(Window* parent, EdgeTxIcon icon, coord_t x, coord_t y,
|
||||
}
|
||||
|
||||
void IconButton::setIcon(EdgeTxIcon icon) { iconImage->setIcon(icon); }
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
MomentaryButton::MomentaryButton(Window* parent, const rect_t& rect, std::string text,
|
||||
std::function<void(void)> pressHandler,
|
||||
std::function<void(void)> releaseHandler) :
|
||||
FormField(parent, rect, button_create),
|
||||
pressHandler(std::move(pressHandler)),
|
||||
releaseHandler(std::move(releaseHandler)),
|
||||
text(std::move(text))
|
||||
{
|
||||
label = lv_label_create(lvobj);
|
||||
lv_label_set_text(label, this->text.c_str());
|
||||
lv_obj_center(label);
|
||||
}
|
||||
|
||||
void MomentaryButton::onPressed()
|
||||
{
|
||||
if (pressHandler)
|
||||
pressHandler();
|
||||
lv_obj_add_state(lvobj, LV_STATE_CHECKED);
|
||||
lv_obj_clear_state(lvobj, LV_STATE_PRESSED);
|
||||
}
|
||||
|
||||
void MomentaryButton::onReleased()
|
||||
{
|
||||
if (releaseHandler)
|
||||
releaseHandler();
|
||||
lv_obj_clear_state(lvobj, LV_STATE_CHECKED);
|
||||
}
|
||||
|
||||
@@ -94,6 +94,11 @@ class TextButton : public ButtonBase
|
||||
}
|
||||
}
|
||||
|
||||
void setFont(FontIndex font)
|
||||
{
|
||||
etx_font(label, font);
|
||||
}
|
||||
|
||||
void setWrap()
|
||||
{
|
||||
lv_obj_set_width(label, lv_pct(100));
|
||||
@@ -102,9 +107,8 @@ class TextButton : public ButtonBase
|
||||
}
|
||||
|
||||
protected:
|
||||
lv_obj_t* label = nullptr;
|
||||
|
||||
std::string text;
|
||||
lv_obj_t* label = nullptr;
|
||||
};
|
||||
|
||||
class IconButton : public ButtonBase
|
||||
@@ -118,3 +122,40 @@ class IconButton : public ButtonBase
|
||||
protected:
|
||||
StaticIcon* iconImage = nullptr;
|
||||
};
|
||||
|
||||
// Button class that is in checked state while pressed and
|
||||
// returns to normal state when released.
|
||||
// Used by Lua scripts.
|
||||
class MomentaryButton : public FormField
|
||||
{
|
||||
public:
|
||||
MomentaryButton(Window* parent, const rect_t& rect, std::string text,
|
||||
std::function<void(void)> pressHandler = nullptr,
|
||||
std::function<void(void)> releaseHandler = nullptr);
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() const override { return "MomentaryButton"; }
|
||||
#endif
|
||||
|
||||
void onPressed() override;
|
||||
void onReleased() override;
|
||||
|
||||
void setText(std::string value)
|
||||
{
|
||||
if (value != text) {
|
||||
text = std::move(value);
|
||||
lv_label_set_text(label, text.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void setFont(FontIndex font)
|
||||
{
|
||||
etx_font(label, font);
|
||||
}
|
||||
|
||||
protected:
|
||||
std::function<void(void)> pressHandler;
|
||||
std::function<void(void)> releaseHandler;
|
||||
std::string text;
|
||||
lv_obj_t* label = nullptr;
|
||||
};
|
||||
|
||||
@@ -21,11 +21,94 @@
|
||||
#include "form.h"
|
||||
#include "etx_lv_theme.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void SliderBase::slider_changed_cb(lv_event_t* e)
|
||||
{
|
||||
if (lv_event_get_code(e) == LV_EVENT_VALUE_CHANGED) {
|
||||
SliderBase* sl = (SliderBase*)lv_event_get_user_data(e);
|
||||
if (sl != nullptr) {
|
||||
lv_obj_t* target = lv_event_get_target(e);
|
||||
sl->setValue(lv_slider_get_value(target));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SliderBase::SliderBase(Window* parent, coord_t width, coord_t height, int32_t vmin, int32_t vmax,
|
||||
std::function<int()> getValue,
|
||||
std::function<void(int)> setValue) :
|
||||
Window(parent, {0, 0, width, height}, window_create),
|
||||
vmin(vmin),
|
||||
vmax(vmax),
|
||||
_getValue(std::move(getValue)),
|
||||
_setValue(std::move(setValue))
|
||||
{
|
||||
}
|
||||
|
||||
void SliderBase::update()
|
||||
{
|
||||
if (_getValue != nullptr) {
|
||||
// Fix for lv_slider_set_value not working when using the rotary encoder to
|
||||
// update value
|
||||
auto bar = (lv_bar_t*)slider;
|
||||
bar->cur_value_anim.anim_state = -1;
|
||||
bar->cur_value_anim.anim_end = _getValue();
|
||||
|
||||
lv_slider_set_value(slider, _getValue(), LV_ANIM_OFF);
|
||||
}
|
||||
}
|
||||
|
||||
void SliderBase::deleteLater(bool detach, bool trash)
|
||||
{
|
||||
if (!deleted()) {
|
||||
if (tickPts) delete tickPts;
|
||||
Window::deleteLater(detach, trash);
|
||||
}
|
||||
}
|
||||
|
||||
void SliderBase::setValue(int value)
|
||||
{
|
||||
if (_setValue != nullptr)
|
||||
_setValue(limit(vmin, value, vmax));
|
||||
}
|
||||
|
||||
void SliderBase::checkEvents()
|
||||
{
|
||||
Window::checkEvents();
|
||||
if (_getValue != nullptr) {
|
||||
int v = _getValue();
|
||||
if (v != lv_slider_get_value(slider))
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void SliderBase::enable(bool enabled)
|
||||
{
|
||||
if (!_deleted && slider) {
|
||||
if (lv_obj_has_state(slider, LV_STATE_DISABLED) == enabled) {
|
||||
if (enabled)
|
||||
lv_obj_clear_state(slider, LV_STATE_DISABLED);
|
||||
else
|
||||
lv_obj_add_state(slider, LV_STATE_DISABLED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SliderBase::setColor(LcdFlags color)
|
||||
{
|
||||
etx_bg_color_from_flags(slider, color, LV_PART_KNOB);
|
||||
if (tickPts)
|
||||
for (int i = 0; i < (vmax - vmin - 1); i += 1)
|
||||
etx_bg_color_from_flags(tickPts[i], color);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Slider
|
||||
const lv_style_const_prop_t slider_knob_props[] = {
|
||||
LV_STYLE_CONST_PAD_TOP(9), LV_STYLE_CONST_PAD_BOTTOM(9),
|
||||
LV_STYLE_CONST_PAD_LEFT(4), LV_STYLE_CONST_PAD_RIGHT(4),
|
||||
LV_STYLE_CONST_RADIUS(4), LV_STYLE_CONST_BORDER_WIDTH(2),
|
||||
LV_STYLE_CONST_PAD_TOP(PAD_LARGE + 1), LV_STYLE_CONST_PAD_BOTTOM(PAD_LARGE + 1),
|
||||
LV_STYLE_CONST_PAD_LEFT(PAD_SMALL), LV_STYLE_CONST_PAD_RIGHT(PAD_SMALL),
|
||||
LV_STYLE_CONST_RADIUS(PAD_SMALL), LV_STYLE_CONST_BORDER_WIDTH(PAD_TINY),
|
||||
LV_STYLE_PROP_INV,
|
||||
};
|
||||
LV_STYLE_CONST_MULTI_INIT(slider_knob, slider_knob_props);
|
||||
@@ -43,11 +126,15 @@ static void slider_constructor(const lv_obj_class_t* class_p, lv_obj_t* obj)
|
||||
etx_bg_color(obj, COLOR_THEME_EDIT_INDEX,
|
||||
LV_PART_INDICATOR | LV_STATE_FOCUSED | LV_STATE_EDITED);
|
||||
|
||||
etx_obj_add_style(obj, styles->bg_opacity_cover, LV_PART_KNOB);
|
||||
etx_solid_bg(obj, COLOR_THEME_PRIMARY2_INDEX, LV_PART_KNOB);
|
||||
etx_obj_add_style(obj, slider_knob, LV_PART_KNOB);
|
||||
etx_obj_add_style(obj, styles->border_color[COLOR_THEME_SECONDARY1_INDEX], LV_PART_MAIN);
|
||||
etx_obj_add_style(obj, styles->border_color[COLOR_THEME_FOCUS_INDEX],
|
||||
LV_PART_KNOB | LV_STATE_FOCUSED);
|
||||
|
||||
etx_obj_add_style(obj, styles->disabled, LV_PART_MAIN | LV_STATE_DISABLED);
|
||||
etx_obj_add_style(obj, styles->disabled, LV_PART_KNOB | LV_STATE_DISABLED);
|
||||
etx_obj_add_style(obj, styles->disabled, LV_PART_INDICATOR | LV_STATE_DISABLED);
|
||||
}
|
||||
|
||||
static const lv_obj_class_t slider_class = {
|
||||
@@ -57,7 +144,7 @@ static const lv_obj_class_t slider_class = {
|
||||
.user_data = nullptr,
|
||||
.event_cb = nullptr,
|
||||
.width_def = 0,
|
||||
.height_def = 8,
|
||||
.height_def = PAD_LARGE,
|
||||
.editable = LV_OBJ_CLASS_EDITABLE_INHERIT,
|
||||
.group_def = LV_OBJ_CLASS_GROUP_DEF_INHERIT,
|
||||
.instance_size = sizeof(lv_slider_t),
|
||||
@@ -68,34 +155,19 @@ static lv_obj_t* slider_create(lv_obj_t* parent)
|
||||
return etx_create(&slider_class, parent);
|
||||
}
|
||||
|
||||
void Slider::slider_changed_cb(lv_event_t* e)
|
||||
{
|
||||
if (lv_event_get_code(e) == LV_EVENT_VALUE_CHANGED) {
|
||||
Slider* sl = (Slider*)lv_event_get_user_data(e);
|
||||
if (sl != nullptr) {
|
||||
lv_obj_t* target = lv_event_get_target(e);
|
||||
sl->setValue(lv_slider_get_value(target));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Slider::Slider(Window* parent, coord_t width, int32_t vmin, int32_t vmax,
|
||||
std::function<int()> getValue,
|
||||
std::function<void(int)> setValue) :
|
||||
Window(parent, {0, 0, width, 32}, window_create),
|
||||
vmin(vmin),
|
||||
vmax(vmax),
|
||||
_getValue(std::move(getValue)),
|
||||
_setValue(std::move(setValue))
|
||||
SliderBase(parent, width, EdgeTxStyles::UI_ELEMENT_HEIGHT, vmin, vmax, getValue, setValue)
|
||||
{
|
||||
padTop(9);
|
||||
padLeft(8);
|
||||
padRight(8);
|
||||
padTop(PAD_LARGE + 1);
|
||||
padLeft(PAD_LARGE);
|
||||
padRight(PAD_LARGE);
|
||||
|
||||
slider = (new FormField(this, rect_t{}, slider_create))->getLvObj();
|
||||
lv_obj_set_width(slider, lv_pct(100));
|
||||
|
||||
lv_obj_add_event_cb(slider, Slider::slider_changed_cb, LV_EVENT_VALUE_CHANGED, this);
|
||||
lv_obj_add_event_cb(slider, SliderBase::slider_changed_cb, LV_EVENT_VALUE_CHANGED, this);
|
||||
lv_slider_set_range(slider, vmin, vmax);
|
||||
|
||||
lv_obj_add_event_cb(lvobj, Slider::on_draw, LV_EVENT_DRAW_MAIN_BEGIN,
|
||||
@@ -106,7 +178,7 @@ Slider::Slider(Window* parent, coord_t width, int32_t vmin, int32_t vmax,
|
||||
tickPts = new lv_obj_t*[range - 1];
|
||||
for (int n = 1; n < range; n += 1) {
|
||||
lv_obj_t* p = lv_obj_create(lvobj);
|
||||
lv_obj_set_size(p, 2, 6);
|
||||
lv_obj_set_size(p, PAD_TINY, PAD_MEDIUM);
|
||||
etx_solid_bg(p, COLOR_THEME_PRIMARY2_INDEX);
|
||||
tickPts[n - 1] = p;
|
||||
}
|
||||
@@ -126,7 +198,7 @@ void Slider::delayedInit()
|
||||
if (!loaded) {
|
||||
loaded = true;
|
||||
|
||||
coord_t w = lv_obj_get_width(lvobj) - 16;
|
||||
coord_t w = lv_obj_get_width(lvobj) - PAD_LARGE * 2;
|
||||
coord_t x = -1;
|
||||
int range = vmax - vmin;
|
||||
if (range < 10) {
|
||||
@@ -137,23 +209,109 @@ void Slider::delayedInit()
|
||||
}
|
||||
}
|
||||
|
||||
void Slider::update()
|
||||
{
|
||||
if (_getValue != nullptr) {
|
||||
// Fix for lv_slider_set_value not working when using the rotary encoder to
|
||||
// update value
|
||||
auto bar = (lv_bar_t*)slider;
|
||||
bar->cur_value_anim.anim_state = -1;
|
||||
bar->cur_value_anim.anim_end = _getValue();
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
lv_slider_set_value(slider, _getValue(), LV_ANIM_OFF);
|
||||
}
|
||||
// Vertical Slider
|
||||
const lv_style_const_prop_t vslider_knob_props[] = {
|
||||
LV_STYLE_CONST_PAD_TOP(PAD_SMALL), LV_STYLE_CONST_PAD_BOTTOM(PAD_SMALL),
|
||||
LV_STYLE_CONST_PAD_LEFT(PAD_LARGE + 1), LV_STYLE_CONST_PAD_RIGHT(PAD_LARGE + 1),
|
||||
LV_STYLE_CONST_RADIUS(PAD_SMALL), LV_STYLE_CONST_BORDER_WIDTH(PAD_TINY),
|
||||
LV_STYLE_PROP_INV,
|
||||
};
|
||||
LV_STYLE_CONST_MULTI_INIT(vslider_knob, vslider_knob_props);
|
||||
|
||||
static void vslider_constructor(const lv_obj_class_t* class_p, lv_obj_t* obj)
|
||||
{
|
||||
etx_solid_bg(obj, COLOR_THEME_SECONDARY1_INDEX);
|
||||
etx_obj_add_style(obj, styles->rounded, LV_PART_MAIN);
|
||||
etx_bg_color(obj, COLOR_THEME_FOCUS_INDEX, LV_PART_MAIN | LV_STATE_FOCUSED);
|
||||
etx_bg_color(obj, COLOR_THEME_EDIT_INDEX,
|
||||
LV_PART_MAIN | LV_STATE_FOCUSED | LV_STATE_EDITED);
|
||||
|
||||
etx_bg_color(obj, COLOR_THEME_FOCUS_INDEX,
|
||||
LV_PART_INDICATOR | LV_STATE_FOCUSED);
|
||||
etx_bg_color(obj, COLOR_THEME_EDIT_INDEX,
|
||||
LV_PART_INDICATOR | LV_STATE_FOCUSED | LV_STATE_EDITED);
|
||||
|
||||
etx_obj_add_style(obj, styles->bg_opacity_cover, LV_PART_KNOB);
|
||||
etx_obj_add_style(obj, vslider_knob, LV_PART_KNOB);
|
||||
etx_obj_add_style(obj, styles->border_color[COLOR_THEME_SECONDARY1_INDEX], LV_PART_MAIN);
|
||||
etx_obj_add_style(obj, styles->border_color[COLOR_THEME_FOCUS_INDEX],
|
||||
LV_PART_KNOB | LV_STATE_FOCUSED);
|
||||
|
||||
etx_obj_add_style(obj, styles->disabled, LV_PART_MAIN | LV_STATE_DISABLED);
|
||||
etx_obj_add_style(obj, styles->disabled, LV_PART_KNOB | LV_STATE_DISABLED);
|
||||
etx_obj_add_style(obj, styles->disabled, LV_PART_INDICATOR | LV_STATE_DISABLED);
|
||||
}
|
||||
|
||||
void Slider::deleteLater(bool detach, bool trash)
|
||||
static const lv_obj_class_t vslider_class = {
|
||||
.base_class = &lv_slider_class,
|
||||
.constructor_cb = vslider_constructor,
|
||||
.destructor_cb = nullptr,
|
||||
.user_data = nullptr,
|
||||
.event_cb = nullptr,
|
||||
.width_def = PAD_LARGE,
|
||||
.height_def = 0,
|
||||
.editable = LV_OBJ_CLASS_EDITABLE_INHERIT,
|
||||
.group_def = LV_OBJ_CLASS_GROUP_DEF_INHERIT,
|
||||
.instance_size = sizeof(lv_slider_t),
|
||||
};
|
||||
|
||||
static lv_obj_t* vslider_create(lv_obj_t* parent)
|
||||
{
|
||||
if (!deleted()) {
|
||||
if (tickPts) delete tickPts;
|
||||
Window::deleteLater(detach, trash);
|
||||
return etx_create(&vslider_class, parent);
|
||||
}
|
||||
|
||||
VerticalSlider::VerticalSlider(Window* parent, coord_t height, int32_t vmin, int32_t vmax,
|
||||
std::function<int()> getValue,
|
||||
std::function<void(int)> setValue) :
|
||||
SliderBase(parent, EdgeTxStyles::UI_ELEMENT_HEIGHT, height, vmin,vmax, getValue, setValue)
|
||||
{
|
||||
padLeft(PAD_LARGE + 1);
|
||||
padTop(PAD_LARGE);
|
||||
padBottom(PAD_LARGE);
|
||||
|
||||
slider = (new FormField(this, rect_t{}, vslider_create))->getLvObj();
|
||||
lv_obj_set_height(slider, lv_pct(100));
|
||||
|
||||
lv_obj_add_event_cb(slider, SliderBase::slider_changed_cb, LV_EVENT_VALUE_CHANGED, this);
|
||||
lv_slider_set_range(slider, vmin, vmax);
|
||||
|
||||
lv_obj_add_event_cb(lvobj, VerticalSlider::on_draw, LV_EVENT_DRAW_MAIN_BEGIN,
|
||||
nullptr);
|
||||
|
||||
int range = vmax - vmin;
|
||||
if (range < 10) {
|
||||
tickPts = new lv_obj_t*[range - 1];
|
||||
for (int n = 1; n < range; n += 1) {
|
||||
lv_obj_t* p = lv_obj_create(lvobj);
|
||||
lv_obj_set_size(p, PAD_MEDIUM, PAD_TINY);
|
||||
etx_solid_bg(p, COLOR_THEME_PRIMARY2_INDEX);
|
||||
tickPts[n - 1] = p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void VerticalSlider::on_draw(lv_event_t* e)
|
||||
{
|
||||
auto dlg = (VerticalSlider*)lv_obj_get_user_data(lv_event_get_target(e));
|
||||
if (dlg) dlg->delayedInit();
|
||||
}
|
||||
|
||||
void VerticalSlider::delayedInit()
|
||||
{
|
||||
if (!loaded) {
|
||||
loaded = true;
|
||||
|
||||
coord_t h = lv_obj_get_height(lvobj) - PAD_LARGE * 2;
|
||||
coord_t y = -1;
|
||||
int range = vmax - vmin;
|
||||
if (range < 10) {
|
||||
for (int n = 1; n < range; n += 1) {
|
||||
lv_obj_set_pos(tickPts[n - 1], 1, y + (h * n) / range);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,23 +20,19 @@
|
||||
|
||||
#include "window.h"
|
||||
|
||||
class Slider : public Window
|
||||
class SliderBase : public Window
|
||||
{
|
||||
public:
|
||||
Slider(Window* parent, coord_t width, int32_t vmin, int32_t vmax,
|
||||
SliderBase(Window* parent, coord_t width, coord_t height, int32_t vmin, int32_t vmax,
|
||||
std::function<int()> getValue, std::function<void(int)> setValue);
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() const override { return "Slider"; }
|
||||
#endif
|
||||
|
||||
void setValue(int value)
|
||||
{
|
||||
if (_setValue != nullptr) _setValue(limit(vmin, value, vmax));
|
||||
}
|
||||
void setValue(int value);
|
||||
void setColor(LcdFlags color);
|
||||
|
||||
void update();
|
||||
|
||||
void enable(bool enabled = true) override;
|
||||
|
||||
protected:
|
||||
int vmin;
|
||||
int vmax;
|
||||
@@ -47,9 +43,38 @@ class Slider : public Window
|
||||
std::function<int()> _getValue;
|
||||
std::function<void(int)> _setValue;
|
||||
|
||||
void deleteLater(bool detach, bool trash) override;
|
||||
void checkEvents() override;
|
||||
|
||||
static void slider_changed_cb(lv_event_t* e);
|
||||
};
|
||||
|
||||
class Slider : public SliderBase
|
||||
{
|
||||
public:
|
||||
Slider(Window* parent, coord_t width, int32_t vmin, int32_t vmax,
|
||||
std::function<int()> getValue, std::function<void(int)> setValue);
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() const override { return "Slider"; }
|
||||
#endif
|
||||
|
||||
protected:
|
||||
static void on_draw(lv_event_t* e);
|
||||
void delayedInit();
|
||||
};
|
||||
|
||||
class VerticalSlider : public SliderBase
|
||||
{
|
||||
public:
|
||||
VerticalSlider(Window* parent, coord_t height, int32_t vmin, int32_t vmax,
|
||||
std::function<int()> getValue, std::function<void(int)> setValue);
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() const override { return "VerticalSlider"; }
|
||||
#endif
|
||||
|
||||
protected:
|
||||
static void on_draw(lv_event_t* e);
|
||||
void delayedInit();
|
||||
|
||||
void deleteLater(bool detach, bool trash) override;
|
||||
};
|
||||
|
||||
@@ -100,3 +100,14 @@ void ToggleSwitch::onClicked()
|
||||
{
|
||||
// prevent FormField::onClicked()
|
||||
}
|
||||
|
||||
void ToggleSwitch::checkEvents()
|
||||
{
|
||||
Window::checkEvents();
|
||||
if (_getValue != nullptr) {
|
||||
bool v = _getValue() != 0;
|
||||
bool s = (lv_obj_get_state(lvobj) & LV_STATE_CHECKED) == LV_STATE_CHECKED;
|
||||
if (v != s)
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,5 +54,7 @@ class ToggleSwitch : public FormField
|
||||
std::function<uint8_t()> _getValue;
|
||||
std::function<void(uint8_t)> _setValue;
|
||||
|
||||
void checkEvents() override;
|
||||
|
||||
static void toggleswitch_event_handler(lv_event_t* e);
|
||||
};
|
||||
|
||||
@@ -96,6 +96,12 @@ void Window::eventHandler(lv_event_t *e)
|
||||
TRACE("LONG PRESS[%p]", this);
|
||||
_longPressed = onLongPress();
|
||||
break;
|
||||
case LV_EVENT_PRESSED:
|
||||
onPressed();
|
||||
break;
|
||||
case LV_EVENT_RELEASED:
|
||||
onReleased();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -146,6 +146,8 @@ class Window
|
||||
virtual void onClicked();
|
||||
virtual void onCancel();
|
||||
virtual bool onLongPress();
|
||||
virtual void onPressed() {}
|
||||
virtual void onReleased() {}
|
||||
|
||||
void invalidate();
|
||||
|
||||
@@ -177,7 +179,7 @@ class Window
|
||||
|
||||
virtual void show(bool visible = true);
|
||||
void hide() { show(false); }
|
||||
void enable(bool enabled = true);
|
||||
virtual void enable(bool enabled = true);
|
||||
void disable() { enable(false); }
|
||||
|
||||
protected:
|
||||
|
||||
@@ -361,6 +361,7 @@ bool ViewMain::onLongPress()
|
||||
if (isAppMode()) {
|
||||
int view = getCurrentMainView();
|
||||
customScreens[view]->getWidget(0)->setFullscreen(true);
|
||||
killEvents(KEY_ENTER);
|
||||
} else {
|
||||
enableWidgetSelect(true);
|
||||
}
|
||||
|
||||
@@ -120,9 +120,8 @@ void Widget::setFullscreen(bool enable)
|
||||
|
||||
bringToTop();
|
||||
|
||||
if (!lv_obj_get_group(lvobj)) {
|
||||
if (!lv_obj_get_group(lvobj))
|
||||
lv_group_add_obj(lv_group_get_default(), lvobj);
|
||||
}
|
||||
|
||||
// disable scroll chaining (sliding main view)
|
||||
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_SCROLL_CHAIN_HOR);
|
||||
@@ -130,7 +129,8 @@ void Widget::setFullscreen(bool enable)
|
||||
}
|
||||
|
||||
// set group in editing mode (keys LEFT / RIGHT)
|
||||
lv_group_set_editing(lv_group_get_default(), enable);
|
||||
if (enableFullScreenRE())
|
||||
lv_group_set_editing(lv_group_get_default(), enable);
|
||||
|
||||
onFullscreen(enable);
|
||||
|
||||
|
||||
@@ -67,6 +67,10 @@ class Widget : public ButtonBase
|
||||
// Set/unset fullscreen mode
|
||||
void setFullscreen(bool enable);
|
||||
void closeFullscreen() { closeFS = true; }
|
||||
bool isFullscreen() const { return fullscreen; }
|
||||
|
||||
// Should rotary encoder events be enabled when full screen
|
||||
virtual bool enableFullScreenRE() const { return true; }
|
||||
|
||||
// Called when the widget options have changed
|
||||
virtual void update();
|
||||
|
||||
@@ -237,6 +237,8 @@ void StandaloneLuaWindow::deleteLater(bool detach, bool trash)
|
||||
|
||||
luaState = prevLuaState;
|
||||
|
||||
luaEmptyEventBuffer();
|
||||
|
||||
Window::deleteLater(detach, trash);
|
||||
}
|
||||
|
||||
@@ -324,7 +326,7 @@ void StandaloneLuaWindow::onCancel() { LuaEventHandler::onCancel(); }
|
||||
|
||||
void StandaloneLuaWindow::onEvent(event_t evt)
|
||||
{
|
||||
LuaEventHandler::onEvent(evt);
|
||||
LuaEventHandler::onLuaEvent(evt);
|
||||
}
|
||||
|
||||
void StandaloneLuaWindow::popupPaint(BitmapBuffer* dc, coord_t x, coord_t y, coord_t w, coord_t h,
|
||||
|
||||
@@ -53,13 +53,13 @@ public:
|
||||
void clear() override;
|
||||
bool useLvglLayout() const override { return useLvgl; }
|
||||
bool isAppMode() const override { return false; }
|
||||
bool isWidget() override { return false; }
|
||||
bool isFullscreen() override { return true; }
|
||||
|
||||
void luaShowError() override;
|
||||
|
||||
void showError(bool firstCall, const char* title, const char* msg);
|
||||
|
||||
bool isWidget() override { return false; }
|
||||
|
||||
static LAYOUT_VAL(POPUP_HEADER_HEIGHT, 30, 30);
|
||||
static LAYOUT_VAL(POPUP_X, 50, 40);
|
||||
static LAYOUT_VAL(POPUP_Y, 70, 110);
|
||||
|
||||
+101
-23
@@ -253,29 +253,6 @@ static bool isSourceTelemCompAvailable(int source) {
|
||||
return isTelemetryFieldComparisonAvailable(qr.quot);
|
||||
}
|
||||
|
||||
enum SrcTypes {
|
||||
SRC_INPUT = 1 << 0,
|
||||
SRC_LUA = 1 << 1,
|
||||
SRC_STICK = 1 << 2,
|
||||
SRC_POT = 1 << 3,
|
||||
SRC_TILT = 1 << 4,
|
||||
SRC_SPACEMOUSE = 1 << 5,
|
||||
SRC_MINMAX = 1 << 6,
|
||||
SRC_HELI = 1 << 7,
|
||||
SRC_TRIM = 1 << 8,
|
||||
SRC_SWITCH = 1 << 9,
|
||||
SRC_FUNC_SWITCH = 1 << 10,
|
||||
SRC_LOGICAL_SWITCH = 1 << 11,
|
||||
SRC_TRAINER = 1 << 12,
|
||||
SRC_CHANNEL = 1 << 13,
|
||||
SRC_CHANNEL_ALL = 1 << 14,
|
||||
SRC_GVAR = 1 << 15,
|
||||
SRC_TX = 1 << 16,
|
||||
SRC_TIMER = 1 << 17,
|
||||
SRC_TELEM = 1 << 18,
|
||||
SRC_TELEM_COMP = 1 << 19,
|
||||
};
|
||||
|
||||
struct sourceAvailableCheck {
|
||||
uint16_t first;
|
||||
uint16_t last;
|
||||
@@ -310,6 +287,7 @@ static struct sourceAvailableCheck sourceChecks[] = {
|
||||
{ MIXSRC_FIRST_TIMER, MIXSRC_LAST_TIMER, SRC_TIMER, isSourceTimerAvailable },
|
||||
{ MIXSRC_FIRST_TELEM, MIXSRC_LAST_TELEM, SRC_TELEM, isSourceTelemAvailable },
|
||||
{ MIXSRC_FIRST_TELEM, MIXSRC_LAST_TELEM, SRC_TELEM_COMP, isSourceTelemCompAvailable },
|
||||
{ MIXSRC_NONE, MIXSRC_NONE, SRC_NONE, sourceIsAvailable },
|
||||
};
|
||||
|
||||
bool checkSourceAvailable(int source, uint32_t sourceTypes)
|
||||
@@ -451,6 +429,106 @@ bool isSwitchAvailable(int swtch, SwitchContext context)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool switchIsAvailable(int swtch, bool invert)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool isSwitchSwitchAvailable(int swtch, bool invert) {
|
||||
// Check normal switch
|
||||
if (swtch < MAX_SWITCHES * 3) {
|
||||
div_t swinfo = switchInfo(swtch);
|
||||
if (swinfo.quot >= switchGetMaxSwitches() + switchGetMaxFctSwitches()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!SWITCH_EXISTS(swinfo.quot)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IS_CONFIG_3POS(swinfo.quot)) {
|
||||
if (swinfo.rem == 1) {
|
||||
// mid position not available for 2POS switches
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Multipos switch
|
||||
int index = (swtch - SWSRC_FIRST_MULTIPOS_SWITCH) / XPOTS_MULTIPOS_COUNT;
|
||||
return (index < adcGetMaxInputs(ADC_INPUT_FLEX)) ? IS_POT_MULTIPOS(index) : false;
|
||||
}
|
||||
|
||||
static bool isSwitchTrimAvailable(int swtch, bool invert) {
|
||||
int index = swtch / 2;
|
||||
return index < keysGetMaxTrims();
|
||||
}
|
||||
|
||||
static bool isSwitchLSAvailable(int swtch, bool invert) {
|
||||
return isLogicalSwitchAvailable(swtch);
|
||||
}
|
||||
|
||||
static bool isSwitchFMAvailable(int swtch, bool invert) {
|
||||
if (swtch == 0)
|
||||
return true;
|
||||
FlightModeData * fm = flightModeAddress(swtch);
|
||||
return (fm->swtch != SWSRC_NONE);
|
||||
}
|
||||
|
||||
static bool isSwitchTelemAvailable(int swtch, bool invert) {
|
||||
return isTelemetryFieldAvailable(swtch);
|
||||
}
|
||||
|
||||
static bool isSwitchOtherAvailable(int swtch, bool invert) {
|
||||
swtch += SWSRC_ON;
|
||||
if (invert && (swtch == SWSRC_ON || swtch == SWSRC_ONE))
|
||||
return false;
|
||||
if (swtch == SWSRC_ON || swtch == SWSRC_ONE || swtch == SWSRC_TELEMETRY_STREAMING ||
|
||||
swtch == SWSRC_RADIO_ACTIVITY || swtch == SWSRC_TRAINER_CONNECTED)
|
||||
return true;
|
||||
#if defined(DEBUG_LATENCY)
|
||||
if (swtch == SWSRC_LATENCY_TOGGLE)
|
||||
return true;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
struct switchAvailableCheck {
|
||||
uint16_t first;
|
||||
uint16_t last;
|
||||
SwitchTypes type;
|
||||
bool (*check)(int, bool);
|
||||
};
|
||||
|
||||
static struct switchAvailableCheck switchChecks[] = {
|
||||
{ SWSRC_FIRST_SWITCH, SWSRC_LAST_MULTIPOS_SWITCH, SW_SWITCH, isSwitchSwitchAvailable },
|
||||
{ SWSRC_FIRST_TRIM, SWSRC_LAST_TRIM, SW_TRIM, isSwitchTrimAvailable },
|
||||
{ SWSRC_FIRST_LOGICAL_SWITCH, SWSRC_LAST_LOGICAL_SWITCH, SW_LOGICAL_SWITCH, isSwitchLSAvailable },
|
||||
{ SWSRC_FIRST_FLIGHT_MODE, SWSRC_LAST_FLIGHT_MODE, SW_FLIGHT_MODE, isSwitchFMAvailable },
|
||||
{ SWSRC_FIRST_SENSOR, SWSRC_LAST_SENSOR, SW_TELEM, isSwitchTelemAvailable },
|
||||
{ SWSRC_ON, SWSRC_COUNT - 1, SW_OTHER, isSwitchOtherAvailable },
|
||||
{ SWSRC_NONE, SWSRC_NONE, SW_NONE, switchIsAvailable },
|
||||
};
|
||||
|
||||
bool checkSwitchAvailable(int swtch, uint32_t swtchTypes)
|
||||
{
|
||||
bool invert = false;
|
||||
if (swtch < 0) {
|
||||
swtch = -swtch;
|
||||
invert = true;
|
||||
}
|
||||
|
||||
for (size_t i = 0 ; i < DIM(switchChecks); i += 1) {
|
||||
if (switchChecks[i].type & swtchTypes && swtch >= switchChecks[i].first && swtch <= switchChecks[i].last) {
|
||||
return switchChecks[i].check(swtch - switchChecks[i].first, invert);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isSerialModeAvailable(uint8_t port_nr, int mode)
|
||||
{
|
||||
#if defined(USB_SERIAL)
|
||||
|
||||
@@ -57,6 +57,8 @@ enum SwitchContext
|
||||
|
||||
int getFirstAvailable(int min, int max, IsValueAvailable isValueAvailable);
|
||||
|
||||
bool checkSourceAvailable(int source, uint32_t sourceTypes);
|
||||
bool checkSwitchAvailable(int swtch, uint32_t swtchTypes);
|
||||
bool isInputAvailable(int input);
|
||||
bool isSourceAvailableInInputs(int source);
|
||||
bool isThrottleSourceAvailable(int source);
|
||||
|
||||
Reference in New Issue
Block a user