Quantcast
Channel: The Battle for Wesnoth Forums
Viewing all articles
Browse latest Browse all 1439

Lua Labs • Re: [GUI] dynamic widget definition

$
0
0
Now for the float, I'd like to use a slider, and that slider's minimum and maximum values and step size aren't known when I create the node definition, and it appears they cannot be modified on the fly. My guess is that they are fixed, and I have to define them when I define(/instantiate/initialize/?) the widget.
Looks like it's just missing from the documentation – you can assign min_value and max_value to change a slider's bounds. Unfortunately, it looks like step size is missing not only from the documentation but from the implementation itself – it's not that it's immutable, but we forgot to add a way to change it from Lua.
My first thought was gui.add_widget_definition(), then something using add_item_of_type, but these ideas aren't really going anywhere for me. If you're wondering what in the world made me think those might be the answer, they're the only things I know that create stuff dynamically.
Widget definition works for purely cosmetic changes or for auxiliary behaviour changes. By "auxiliary" I mean aside from the primary purpose of the widget, so for example if you wanted your slider to have a button attached that when clicked sets the slider to the default value (and you needed enough slides like that that it'd be a pain to manually add a button beside each one), that could (I think) be done with a custom definition.

Add item of type doesn't dynamically generate entirely new content, as it must use a template defined in the WML to generate the element from (that's the "type" of the item you're adding). So it would work if you can break the sliders down into a small number categories, for example "slider with a step size of 1", and "slider with a step size of 5", and "slider with a step size of 10" – each of those would be defined as a different type in the WML. But if each slider needs its own unique step size, then I don't think this approach will help you.
I could just use a text_box of course, but I've built myself a puzzle I don't know how to solve with the slider idea (and it just seems like a nice way of constraining input to a "valid" range).
If you do like the idea of a text box, you could try out the new [spinner] widget. It's not documented yet, but it's basically a text box for numeric input. Though it doesn't currently support any kind of limited range (that's probably worth a feature request). And, glancing at the code, it seems it (unfortunately) probably doesn't even support read/write of value… I hope I'm wrong but I guess it's useless in Lua if I'm right.

Statistics: Posted by Celtic_Minstrel — Today, 2:14 am



Viewing all articles
Browse latest Browse all 1439

Trending Articles