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): allow all UI controls for widgets when full screen #5808

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

philmoz
Copy link
Collaborator

@philmoz philmoz commented Jan 20, 2025

Extends the Lua LVGL API to allow buttons, text and number edit, sliders etc to be used on widgets when the widget is in full screen mode.

Example widget script:

local opts = {
}

local wgt
local exitApp = false

local function create(zone, opts)
  wgt = { zone=zone, opts=opts }
  return wgt
end

local function update(wgt, opts)
  wgt.opts = opts
  exitApp = false

  if lvgl == nil then return end

  lvgl.clear()

  local lyt

  if (lvgl.isFullscreen()) then
    lyt = {
      {type="button", text="Close", x=100, y=100,
          press=(
              function()
                  lvgl.confirm({title="Exit", message="Really exit?",
                      confirm=(function() exitApp = true end)
                  })
              end)},
    }
  else
    lyt = {
      {type="label", text="Enter full screen for UI", x=100, y=100},
    }
  end

  lvgl.build(lyt)
end

local function background(wgt)
end

local function refresh(wgt, event, touchState)
  if (exitApp) then
    lcd.exitFullScreen()
  end

  if lvgl == nil then
    lcd.drawText(0, 0, "Lvgl support required", COLOR_THEME_WARNING)
  end
end

return { name="Lvgl App", options=opts, create=create, update=update, refresh=refresh, background=background, useLvgl=true }

@philmoz philmoz added enhancement ✨ New feature or request color Related generally to color LCD radios lua-api Lua API related labels Jan 20, 2025
@philmoz philmoz added this to the 2.11 milestone Jan 20, 2025
@philmoz philmoz changed the title feat(color): allow all UI for App Mode widgets when full screen. feat(color): allow all UI controls for widgets when full screen. Jan 20, 2025
@philmoz philmoz marked this pull request as draft January 20, 2025 23:26
@pfeerick pfeerick changed the title feat(color): allow all UI controls for widgets when full screen. feat(color): allow all UI controls for widgets when full screen Jan 21, 2025
@philmoz philmoz marked this pull request as ready for review January 21, 2025 02:26
@philmoz philmoz force-pushed the philmoz/lua-lvgl-app-mode branch 2 times, most recently from 731932e to 8f861ec Compare January 22, 2025 05:45
@philmoz philmoz marked this pull request as draft January 22, 2025 22:35
@philmoz philmoz force-pushed the philmoz/lua-lvgl-app-mode branch from 9ef3bee to aa5a078 Compare January 23, 2025 00:53
@wimalopaan
Copy link
Contributor

wimalopaan commented Jan 23, 2025

Many thanks for your great work!

Most stuff was already discussed on discord.

Just not to get lost I mention the following issues I actually see:

@philmoz
Copy link
Collaborator Author

philmoz commented Jan 23, 2025

Slider and toggle switch fixed.
You can use any number in place of the PAD_xx constants so not sure a PAD_XL is really needed.

A note on the lvgl.getContext() function.
For widgets it returns the same table that was created with the first 'create()' function call. This allows functions that get or set properties in UI elements to access the internal script data without having to pass the table to every function call.
For stand alone scripts it returns nil.
This was requested by @offer-shmuely.

@wimalopaan
Copy link
Contributor

Slider and toggle switch fixed.

Confirm with my test app. Thanks!!!

You can use any number in place of the PAD_xx constants so not sure a PAD_XL is really needed.

Ok, maybe need only a docu fix then.

A note on the lvgl.getContext() function. For widgets it returns the same table that was created with the first 'create()' function call. This allows functions that get or set properties in UI elements to access the internal script data without having to pass the table to every function call. For stand alone scripts it returns nil. This was requested by @offer-shmuely.

Cool, will also have a look at that.

@philmoz
Copy link
Collaborator Author

philmoz commented Jan 24, 2025

Added 'momentaryButton' control:

{type="momentaryButton", text="Title", press=(function() end), release=(function() end)}

Shows in checked state while pressed.
'press' function is only called when first pressed.
'release' function is called when touch / key press ends.

@philmoz philmoz marked this pull request as ready for review January 24, 2025 02:51
@wimalopaan
Copy link
Contributor

Added 'momentaryButton' control:

Wow! Absolute great work. Many thanks.

First tests are successful ;-)

@wimalopaan
Copy link
Contributor

wimalopaan commented Jan 24, 2025

Just an idea for a small improvement (in my eyes):

the UI classes button and momentaryButton share the same screen layout - they are visually indistinguishable. I would prefer to have different looks for them, to say: the momentaryButton should get another layout (maybe italic font or not a rounded rectangle).

That said, I would it find useful to override the default colors (from theme). The color property for e.g. button is ignored. Maybe there could be textColor, fgColor, bgColor that override the theme defaults.

@offer-shmuely
Copy link
Contributor

offer-shmuely commented Jan 24, 2025 via email

@philmoz
Copy link
Collaborator Author

philmoz commented Jan 24, 2025

Great addition For ease of documentation, it will be better as buttonMomentarySo it will be sorted alphabetically

@wimalopaan - the momentary button was your idea, do you have any preference for how it is named? Now would be the time to change it.

@philmoz
Copy link
Collaborator Author

philmoz commented Jan 24, 2025

the UI classes button and momentaryButton share the same screen layout - they are visually indistinguishable. I would prefer to have different looks for them, to say: the momentaryButton should get another layout (maybe italic font or not a rounded rectangle).

@JimB40 - do you have any thoughts on this?

@wimalopaan
Copy link
Contributor

Great addition For ease of documentation, it will be better as buttonMomentarySo it will be sorted alphabetically

@wimalopaan - the momentary button was your idea, do you have any preference for how it is named? Now would be the time to change it.

I would still vote for momentaryButton.

@philmoz philmoz force-pushed the philmoz/lua-lvgl-app-mode branch from 8c192f2 to 0de975f Compare January 25, 2025 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
color Related generally to color LCD radios enhancement ✨ New feature or request lua-api Lua API related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants