Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(color): enhancements for Lua widget scripts. #5926

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion radio/src/gui/colorlcd/libui/list_line_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void InputMixButtonBase::setSource(mixsrc_t idx)
else
lv_obj_clear_state(source, LV_STATE_USER_1);

lv_label_set_text(source, s);
lv_label_set_text(source, s);
}

void InputMixButtonBase::setOpts(const char* s)
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/colorlcd/mainview/layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class LayoutFactory

virtual const uint8_t* getBitmap() const = 0;

virtual const ZoneOption* getOptions() const = 0;
virtual const ZoneOption* getLayoutOptions() const = 0;

virtual WidgetsContainer* create(
Window* parent, LayoutPersistentData* persistentData) const = 0;
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/colorlcd/mainview/layout_factory_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class BaseLayoutFactory: public LayoutFactory

const uint8_t* getBitmap() const override { return bitmap; }

const ZoneOption * getOptions() const override
const ZoneOption * getLayoutOptions() const override
{
return options;
}
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/colorlcd/mainview/screen_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ void ScreenSetupPage::buildLayoutOptions()
if (!factory) return;

int index = 0;
for (auto* option = factory->getOptions(); option->name; option++, index++) {
for (auto* option = factory->getLayoutOptions(); option->name; option++, index++) {
auto layoutData = &g_model.screenData[customScreenIndex].layoutData;
ZoneOptionValue* value = &layoutData->options[index].value;

Expand Down
9 changes: 5 additions & 4 deletions radio/src/gui/colorlcd/mainview/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ void Widget::openMenu()
return;
}

if (getOptions() || fsAllowed) {
if (hasOptions() || fsAllowed) {
Menu* menu = new Menu();
menu->setTitle(getFactory()->getDisplayName());
if (fsAllowed) {
menu->addLine(STR_WIDGET_FULLSCREEN, [&]() { setFullscreen(true); });
}
if (getOptions() && getOptions()->name) {
if (hasOptions()) {
menu->addLine(STR_WIDGET_SETTINGS,
[=]() { new WidgetSettings(this); });
}
Expand Down Expand Up @@ -146,9 +146,9 @@ bool Widget::onLongPress()
return true;
}

const ZoneOption* Widget::getOptions() const
const ZoneOption* Widget::getOptionDefinitions() const
{
return getFactory()->getOptions();
return getFactory()->getDefaultOptions();
}

void Widget::enableFocus(bool enable)
Expand Down Expand Up @@ -253,6 +253,7 @@ void WidgetFactory::initPersistentData(Widget::PersistentData* persistentData,
{
if (setDefault) {
memset(persistentData, 0, sizeof(Widget::PersistentData));
parseOptionDefaults();
}
if (options) {
int i = 0;
Expand Down
6 changes: 4 additions & 2 deletions radio/src/gui/colorlcd/mainview/widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class Widget : public ButtonBase

const WidgetFactory* getFactory() const { return factory; }

const ZoneOption* getOptions() const;
const ZoneOption* getOptionDefinitions() const;
bool hasOptions() const { return getOptionDefinitions() && getOptionDefinitions()->name; }

virtual const char* getErrorMessage() const { return nullptr; }

Expand Down Expand Up @@ -117,7 +118,8 @@ class WidgetFactory

const char* getName() const { return name; }

const ZoneOption* getOptions() const { return options; }
const ZoneOption* getDefaultOptions() const { return options; }
virtual const void parseOptionDefaults() const {}

const char* getDisplayName() const
{
Expand Down
3 changes: 2 additions & 1 deletion radio/src/gui/colorlcd/mainview/widget_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ WidgetSettings::WidgetSettings(Widget* w) :
FlexGridLayout grid(line_col_dsc, line_row_dsc, PAD_TINY);

uint8_t optIdx = 0;
auto opt = widget->getOptions();
auto opt = widget->getOptionDefinitions();

while (opt && opt->name != nullptr) {
auto line = form->newLine(grid);

Expand Down
4 changes: 2 additions & 2 deletions radio/src/gui/colorlcd/mainview/widgets_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ SetupWidgetsPageSlot::SetupWidgetsPageSlot(Window* parent, const rect_t& rect,
menu->addLine(STR_SELECT_WIDGET,
[=]() { addNewWidget(container, slotIndex); });
auto widget = container->getWidget(slotIndex);
if (widget->getOptions() && widget->getOptions()->name)
if (widget->hasOptions())
menu->addLine(STR_WIDGET_SETTINGS,
[=]() { new WidgetSettings(widget); });
menu->addLine(STR_REMOVE_WIDGET,
Expand Down Expand Up @@ -103,7 +103,7 @@ void SetupWidgetsPageSlot::addNewWidget(WidgetsContainer* container,
menu->addLine(factory->getDisplayName(), [=]() {
container->createWidget(slotIndex, factory);
auto widget = container->getWidget(slotIndex);
if (widget->getOptions() && widget->getOptions()->name)
if (widget->hasOptions())
new WidgetSettings(widget);
});
if (cur && strcmp(cur, factory->getDisplayName()) == 0)
Expand Down
12 changes: 6 additions & 6 deletions radio/src/gui/colorlcd/standalone_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ StandaloneLuaWindow::StandaloneLuaWindow(bool useLvgl, int initFn, int runFn) :

etx_solid_bg(lvobj);

luaScriptManager = this;

if (useLvglLayout()) {
padAll(PAD_ZERO);
etx_scrollbar(lvobj);
Expand All @@ -146,8 +148,6 @@ StandaloneLuaWindow::StandaloneLuaWindow(bool useLvgl, int initFn, int runFn) :
lv_obj_set_style_text_align(lbl, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN);
lv_obj_set_style_pad_top(lbl, (LCD_H - EdgeTxStyles::PAGE_LINE_HEIGHT) / 2, LV_PART_MAIN);
lv_label_set_text(lbl, STR_LOADING);

luaLvglManager = this;
} else {
lcdBuffer = new BitmapBuffer(BMP_RGB565, LCD_W, LCD_H);

Expand Down Expand Up @@ -218,7 +218,7 @@ void StandaloneLuaWindow::deleteLater(bool detach, bool trash)
if (lcdBuffer) delete lcdBuffer;
lcdBuffer = nullptr;

luaLvglManager = nullptr;
luaScriptManager = nullptr;

Layer::pop(this);
Layer::back()->show();
Expand Down Expand Up @@ -320,13 +320,13 @@ void StandaloneLuaWindow::checkEvents()
luaLcdAllowed = false;
}

void StandaloneLuaWindow::onClicked() { Keyboard::hide(false); LuaEventHandler::onClicked(); }
void StandaloneLuaWindow::onClicked() { Keyboard::hide(false); LuaScriptManager::onClickedEvent(); }

void StandaloneLuaWindow::onCancel() { LuaEventHandler::onCancel(); }
void StandaloneLuaWindow::onCancel() { LuaScriptManager::onCancelEvent(); }

void StandaloneLuaWindow::onEvent(event_t evt)
{
LuaEventHandler::onLuaEvent(evt);
LuaScriptManager::onLuaEvent(evt);
}

void StandaloneLuaWindow::popupPaint(BitmapBuffer* dc, coord_t x, coord_t y, coord_t w, coord_t h,
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/colorlcd/standalone_lua.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

extern void luaExecStandalone(const char * filename);

class StandaloneLuaWindow : public Window, public LuaEventHandler, public LuaLvglManager
class StandaloneLuaWindow : public Window, public LuaScriptManager
{
static StandaloneLuaWindow* _instance;

Expand Down
5 changes: 2 additions & 3 deletions radio/src/lua/api_colorlcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#define BITMAP_METATABLE "BITMAP*"

BitmapBuffer* luaLcdBuffer = nullptr;
LuaWidget *runningFS = nullptr;

/*luadoc
@function lcd.refresh()
Expand Down Expand Up @@ -1386,8 +1385,8 @@ Exit full screen widget mode.
*/
static int luaLcdExitFullScreen(lua_State *L)
{
if (runningFS)
runningFS->closeFullscreen();
if (luaScriptManager)
luaScriptManager->exitFullscreen();
return 0;
}

Expand Down
Loading