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

Lua Labs • [GUI] dynamic widget definition

$
0
0
I'm building a preferences menu. Preferences can take multiple forms, such as the simple bool for which I am using a checkbox/button. I use a table to hold preferences, along with things like their default value, range, etc. These will be displayed in a tree_view, with the node type depending on new_prefs.type (e.g. bool == button).

Code:

        table.insert(new_prefs,{ id = "northfrost_animation", default = true , type = "bool", value = true,                description = _"Display animation for northfrost aura"})        table.insert(new_prefs,{ id = "ai_aggression", default = 1, menu = "ai", type = "float", value = 1, min=-10, max = 2, step = 0.1,                        description = _"aggression"})


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.

If I am correct, then my question is how do I create/define/whatever a widget in a tree_view "at runtime"?

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.

I hope this make some sort of sense. At least, what I'm trying to do.

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).


This was my original attempt:

Code:

       local prefs_tv = T.tree_view { id = "prefs_tv",                T.node { id = "bool_node",                        T.node_definition {                                T.row {                                        T.column {                                                grow_factor = 0,                                                horizontal_alignment = "left",                                                T.toggle_button { id = "prefs_tv_button",                                                        definition = "default"                                                }                                        },                                        T.column {                                                grow_factor = 0,                                                horizontal_alignment = "left",                                                T.label { id = "prefs_tv_label",                                                }                                        },                                         T.column { grow_factor = 1, T.spacer {} }                                }                        }                },                T.node { id = "float_node",                        T.node_definition {                                T.row {                                        -- probably need a spacer/blank image here                                        T.column {                                                grow_factor = 0,                                                horizontal_alignment = "left",                                                T.label { id = "prefs_tv_label",                                                }                                        },                                         T.column {                                                grow_factor = 0,                                                horizontal_alignment = "left",                                                T.slider { id = "prefs_tv_slider",                                                       definition = "default"                                                }                                        },                                        T.column { grow_factor = 1, T.spacer {} }                                }                        }                }        } ...                                elseif pref.type == "float" then                                local item = dialog.prefs_tv:add_item_of_type("float_node")                                item.prefs_tv_label.label = pref.description                                item.prefs_tv_slider.minimum_value = pref.min     -- Line 134                                --item.prefs_tv_slider.maximum_value = pref.max                                item.prefs_tv_slider.value = pref.value                                --item.prefs_tv_slider.step_size = pref.step                        end       prefs.lua:134: bad argument #2 to 'newindex' (invalid modifiable property of widget)         

Statistics: Posted by white_haired_uncle — Today, 1:58 am



Viewing all articles
Browse latest Browse all 1439

Trending Articles