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 5 commits into
base: main
Choose a base branch
from

Conversation

philmoz
Copy link
Collaborator

@philmoz philmoz commented Feb 19, 2025

Summary:

Details:
This PR allow the Lua API functions to access the widget or stand alone script that called the function. In addition this adds the telemetry queue per widget required for #5773.

The code now sends the path of the widget being loaded to the script 'create()' function (as the 3rd parameter).

The following changes have been made to the getSwitchIndex() and getSourceIndex() API functions:

  • Both functions check the name value against the default names for switches and sources as well as the user defined custom names (previously only custom names were checked if set by the user).
  • Both functions will always return the switch or source index, previously they would only return a value if the requested item was available, so could not be used on startup when the widgets are loaded.
  • The getSourceIndex() function will match names with or without the symbol string prefix. E.G. getSourceIndex(CHAR_SWITCH.."SF") and getSourceIndex("SF") will both work.

For the widget 'options' table, entries of type SWITCH and SOURCE, can set their default, min and max values from a string. This is a shortcut to using getSwitchIndex() or getSourceIndex() in the option table.
E.G. these two lines are equivalent:

  { "Switch", SWITCH, "SF"..CHAR_DOWN },
  { "Switch", SWITCH, getSwitchIndex("SF"..CHAR_DOWN) },

@philmoz philmoz added enhancement ✨ New feature or request color Related generally to color LCD radios lua-api Lua API related labels Feb 19, 2025
@philmoz philmoz added this to the 3.0 milestone Feb 19, 2025
@philmoz
Copy link
Collaborator Author

philmoz commented Feb 19, 2025

Added support for the default value of a SWITCH or SOURCE option to be a table of possible values.
The first available value is used. Completes the changes requested in #5917
E.G.:

      { "volt_sensor", SOURCE, {"cell","VFAS","RxBt","A1", "A2"} }

philmoz added 3 commits February 22, 2025 12:31
Send path name of widget folder to script 'create()' function.
Enhancements for widgets option default values, getSwitchIndex() and getSourceIndex() Lua function.
@philmoz philmoz force-pushed the philmoz/lua_widget_enhancments branch from 751a48a to e26392e Compare February 22, 2025 01:31
@wimalopaan
Copy link
Contributor

The arc graphical primitive uses functions or values for the startAngle and endAngle properties. Other graphical primitives like retangle or triangle use only values.
I started rewriting some old graphics intensitive widgets and it would be really cool if also rectangle, triangle, circle and line could use functions (or values) as well at least for their coordinates.

@philmoz
Copy link
Collaborator Author

philmoz commented Feb 22, 2025

The position of all objects can be set with the 'pos()' function.
The size of most objects can be set with the 'size()' function.
E.G:

        {type="rectangle", filled=true,
          color=getFillColor,
          size=(function() return fw, math.floor(wgt.vPercent / 100 * (fh)) end),
          pos=(function() return 0, fh - math.floor(wgt.vPercent / 100 * (fh)) end)},

@wimalopaan
Copy link
Contributor

wimalopaan commented Feb 22, 2025

The position of all objects can be set with the 'pos()' function.
The size of most objects can be set with the 'size()' function.

Perfect! Sorry, I missed that in the docu ....

Does pos() really move relative to the window or relative to the parent? What's the behaviour if both xand y are present together with pos()?

One problem with triangle remains: here size() and pos() are not sufficient, I would need also rotate(). But I think it would be much simpler to let the property pts be also a function.

@philmoz
Copy link
Collaborator Author

philmoz commented Feb 22, 2025

Does pos() really move relative to the window or relative to the parent? What's the behaviour if both xand y are present together with pos()?

Parent. I've updated the gitbook docs.

One problem with triangle remains: here size() and pos() are not sufficient, I would need also rotate(). But I think it would be much simpler to let the property pts be also a function.

Triangle is complicated as Lvgl does not have a native triangle object.
The code creates a square mask and draws the triangle into it.
The 'pos()' function can move it; but 'size()' is not implemented.
Rotation would be tricky (what point do you rotate around?).
Having a function for 'pts' could be possible; but it would need to be smart and only redraw the mask when one or more points changed.

@wimalopaan
Copy link
Contributor

Rotation would be tricky (what point do you rotate around?).

Yes. Most libs have to notion of an origin of the drawing canvas. And the rotation rotates around this origin. But I don't know if that's possible for lvgl.

Having a function for 'pts' could be possible; but it would need to be smart and only redraw the mask when one or more points changed.

Mmh, this should be mostly the same as using the set() function for the pts property. But maybe I'm wrong here ...

@philmoz
Copy link
Collaborator Author

philmoz commented Feb 22, 2025

Having a function for 'pts' could be possible; but it would need to be smart and only redraw the mask when one or more points changed.

Mmh, this should be mostly the same as using the set() function for the pts property. But maybe I'm wrong here ...

I am assuming you would only call 'set()' when something changes so it does not check.

@wimalopaan
Copy link
Contributor

Having a function for 'pts' could be possible; but it would need to be smart and only redraw the mask when one or more points changed.

Mmh, this should be mostly the same as using the set() function for the pts property. But maybe I'm wrong here ...

I am assuming you would only call 'set()' when something changes so it does not check.

Ok, then maybe saving the triangle-objects ref and using set() would be best?

@wimalopaan
Copy link
Contributor

Perfect!
Unfortunately it will take a week until I can do some real testing.

@wimalopaan
Copy link
Contributor

I noticed a new (!) problem with the lvgl UI controls. Actually I have no minimal verifying example, so I have to describe it in words:

  1. create a page with a slider and use a get function and put a print() debug message in it.
  2. overwrite the first page with another page that does not contain the slider created under 1)

Now see, that the get function of 1) is still called.

I don't think that this is intentional, because the slider of 1) should be deleted. I think this behaviour changed some time ago.

Unfortunately I have no small(!) example widget ... will need some time.

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.

2 participants