Replies: 1 comment
-
If you are having many small scale tree-structured widgets, another approach is to define theirs types inline using the union syntax. --- root
---@class BackgroundUI: Widget
---@field clientVersion WidgetPanel|{ label: WidgetLabel }
---@field title Widget
---@type BackgroundUI
local background
local a = background.clientVersion -- WidgetPanel|{ label: WidgetLabel }
local b = background.clientVersion.| -- trigger suggestion here => `label`
If widgets can be created dynamically in your program, then I think there is no way to annotate them. I think annotations are used for describing the classes themselves, but not the result of a dynamically created structure. Just use ---@class Element
---@field id? string
---@field children Element[]
---@class HTMLElement: Element
---@field title? string
---@class HTMLImageElement: Element
---@field src? string |
Beta Was this translation helpful? Give feedback.
-
Hello!
I'm creating definition files for a widgets in a custom program i use.
Widgets are classes that has multiple methods available - in Lua it's type is userdata.
Widgets however can also have any number of fields with any type (like tables), therefore they can have a field that is also of widget type - like child & parent.
Widgets in general create a tree-like structure (like in html ie.)
An example would be:
I'm thinking about the best way to define such structure... The only way i've came up with is defining class with one level at a time, which feels terrible... and with rich structure would be unreadable:
Hopefully i've explained it well enough... Do you guys have any tips on how to make it, simply better?
Thanks for any advice!
Beta Was this translation helpful? Give feedback.
All reactions