feat(color): enhancements and fixes to the LVGL Lua API's (#6351)
This commit is contained in:
@@ -228,7 +228,7 @@ void Choice::openMenu()
|
||||
{
|
||||
setEditMode(true); // this needs to be done first before menu is created.
|
||||
|
||||
auto menu = new Menu();
|
||||
auto menu = new Menu(false, popupWidth);
|
||||
if (menuTitle) menu->setTitle(menuTitle);
|
||||
|
||||
fillMenu(menu);
|
||||
|
||||
@@ -54,10 +54,13 @@ class ChoiceBase : public FormField
|
||||
|
||||
const char* getTitle() const { return menuTitle; }
|
||||
|
||||
void setPopupWidth(coord_t w) { popupWidth = w; }
|
||||
|
||||
static LAYOUT_VAL_SCALED(ICON_W, 18)
|
||||
|
||||
protected:
|
||||
lv_obj_t *label;
|
||||
coord_t popupWidth = 0;
|
||||
int vmin = 0;
|
||||
int vmax = 0;
|
||||
const char *menuTitle = nullptr;
|
||||
|
||||
@@ -305,13 +305,15 @@ static lv_obj_t* menu_content_create(lv_obj_t* parent)
|
||||
class MenuWindowContent : public Window
|
||||
{
|
||||
public:
|
||||
explicit MenuWindowContent(Menu* parent) :
|
||||
explicit MenuWindowContent(Menu* parent, coord_t popupWidth) :
|
||||
Window(parent, rect_t{}, menu_content_create)
|
||||
{
|
||||
setWindowFlag(OPAQUE);
|
||||
|
||||
coord_t w = (popupWidth > MENUS_WIDTH) ? popupWidth : MENUS_WIDTH;
|
||||
|
||||
lv_obj_center(lvobj);
|
||||
setFlexLayout(LV_FLEX_FLOW_COLUMN, PAD_ZERO, MENUS_WIDTH, LV_SIZE_CONTENT);
|
||||
setFlexLayout(LV_FLEX_FLOW_COLUMN, PAD_ZERO, w, LV_SIZE_CONTENT);
|
||||
|
||||
header = new StaticText(this, {0, 0, LV_PCT(100), 0}, "",
|
||||
COLOR_THEME_PRIMARY2_INDEX);
|
||||
@@ -319,7 +321,7 @@ class MenuWindowContent : public Window
|
||||
header->padAll(PAD_SMALL);
|
||||
header->hide();
|
||||
|
||||
body = new MenuBody(this, rect_t{0, 0, MENUS_WIDTH, LV_SIZE_CONTENT});
|
||||
body = new MenuBody(this, rect_t{0, 0, w, LV_SIZE_CONTENT});
|
||||
lv_obj_set_style_max_height(body->getLvObj(), LCD_H * 0.8, LV_PART_MAIN);
|
||||
}
|
||||
|
||||
@@ -357,10 +359,10 @@ class MenuWindowContent : public Window
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
Menu::Menu(bool multiple) :
|
||||
Menu::Menu(bool multiple, coord_t popupWidth) :
|
||||
ModalWindow(true),
|
||||
multiple(multiple),
|
||||
content(new MenuWindowContent(this))
|
||||
content(new MenuWindowContent(this, popupWidth))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class Menu : public ModalWindow
|
||||
friend class MenuBody;
|
||||
|
||||
public:
|
||||
explicit Menu(bool multiple = false);
|
||||
explicit Menu(bool multiple = false, coord_t popupWidth = 0);
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() const override { return "Menu"; }
|
||||
|
||||
@@ -59,15 +59,20 @@ void Window::eventHandler(lv_event_t *e)
|
||||
|
||||
switch (code) {
|
||||
case LV_EVENT_SCROLL: {
|
||||
lv_coord_t scroll_x = lv_obj_get_scroll_x(target);
|
||||
lv_coord_t scroll_y = lv_obj_get_scroll_y(target);
|
||||
if (scrollHandler) scrollHandler(scroll_x, scroll_y);
|
||||
|
||||
// exclude pointer based scrolling (only focus scrolling)
|
||||
if (!lv_obj_is_scrolling(target)) {
|
||||
if (!lv_obj_is_scrolling(target) && !noForcedScroll) {
|
||||
lv_point_t *p = (lv_point_t *)lv_event_get_param(e);
|
||||
lv_coord_t scroll_bottom = lv_obj_get_scroll_bottom(target);
|
||||
|
||||
lv_coord_t scroll_y = lv_obj_get_scroll_y(target);
|
||||
TRACE("SCROLL[x=%d;y=%d;top=%d;bottom=%d]", p->x, p->y, scroll_y,
|
||||
scroll_bottom);
|
||||
|
||||
// Force scroll to top or bottom when near either edge.
|
||||
// Only applies when using rotary encoder or keys.
|
||||
if (scroll_y <= 45 && p->y > 0) {
|
||||
lv_obj_scroll_by(target, 0, scroll_y, LV_ANIM_OFF);
|
||||
} else if (scroll_bottom <= 16 && p->y < 0) {
|
||||
|
||||
@@ -75,6 +75,9 @@ class Window
|
||||
typedef std::function<void(bool)> FocusHandler;
|
||||
void setFocusHandler(FocusHandler h) { focusHandler = std::move(h); }
|
||||
|
||||
typedef std::function<void(coord_t, coord_t)> ScrollHandler;
|
||||
void setScrollHandler(ScrollHandler h) { scrollHandler = std::move(h); }
|
||||
|
||||
virtual void clear();
|
||||
virtual void deleteLater(bool detach = true, bool trash = true);
|
||||
|
||||
@@ -182,6 +185,8 @@ class Window
|
||||
virtual void enable(bool enabled = true);
|
||||
void disable() { enable(false); }
|
||||
|
||||
void disableForcedScroll() { noForcedScroll = true; }
|
||||
|
||||
protected:
|
||||
static std::list<Window *> trash;
|
||||
|
||||
@@ -194,12 +199,14 @@ class Window
|
||||
|
||||
WindowFlags windowFlags = 0;
|
||||
LcdFlags textFlags = 0;
|
||||
bool noForcedScroll = false;
|
||||
|
||||
bool _deleted = false;
|
||||
static bool _longPressed;
|
||||
|
||||
std::function<void()> closeHandler;
|
||||
std::function<void(bool)> focusHandler;
|
||||
CloseHandler closeHandler;
|
||||
FocusHandler focusHandler;
|
||||
std::function<void(coord_t, coord_t)> scrollHandler;
|
||||
|
||||
void deleteChildren();
|
||||
|
||||
|
||||
@@ -143,9 +143,9 @@ class WidgetFactory
|
||||
Widget::PersistentData* persistentData);
|
||||
|
||||
protected:
|
||||
const char* name;
|
||||
const char* displayName;
|
||||
const ZoneOption* options;
|
||||
const char* name = nullptr;
|
||||
const char* displayName = nullptr;
|
||||
const ZoneOption* options = nullptr;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
|
||||
Reference in New Issue
Block a user