What?
The ability to specify a valid range of numerical values that may be entered into a textfield.
Whaat?
Mod settings can specify that a text field can only contain i.e. an integer beween 1 and 100, or a decimal between 0.1 and 0.5, and the text field will refuse any other input and show a helpful tooltip about the allowed value ranges. I'd like that ability for modded GUIs too. The LuaGuiElement could supply information about validity via LuaGuiElement.is_value_in_range [R] or similar.
LuaGuiElement 'textfield' with value range
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: LuaGuiElement 'textfield' with value range
FYI: you can already do this all script side. Watch for the text changed event and set the style of the text field if it's invalid + set the tooltip. It's exactly what the game does now for the mod setting text fields.
If you want to get ahold of me I'm almost always on Discord.
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: LuaGuiElement 'textfield' with value range
I know. But it would be a lot easier, especially for inexperienced modders, if there was a built-in way to do this. And as you already do it for mod-settings i was hoping it would be simple enough to expose the function to the API.Rseding91 wrote:FYI: you can already do this all script side. Watch for the text changed event and set the style of the text field if it's invalid + set the tooltip. It's exactly what the game does now for the mod setting text fields.
Re: LuaGuiElement 'textfield' with value range
As with most things modding: it's not that simple.eradicator wrote:I know. But it would be a lot easier, especially for inexperienced modders, if there was a built-in way to do this. And as you already do it for mod-settings i was hoping it would be simple enough to expose the function to the API.Rseding91 wrote:FYI: you can already do this all script side. Watch for the text changed event and set the style of the text field if it's invalid + set the tooltip. It's exactly what the game does now for the mod setting text fields.
It's not a simple function/property on the text box. The way it works in mod settings is the min/max is stored on the mod setting prototype which always exists in memory for the lifetime of the game and then the wrapper widget that shows the specific text-field mod setting listens to the text-changed event on the text widget and if it parses to a value below or above the prototype value then it changes the style and sets the tooltip.
That means in order to support it for custom-text-box the custom-text-box would have to store the min/max at all times in memory, save them to disk, listen to the change event and set the tooltip accordingly.
If you want to get ahold of me I'm almost always on Discord.
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: LuaGuiElement 'textfield' with value range
Are you implying that it would need to store/parse this for all text boxes regardless of if they use the feature? ... that would indeed be a no-go *sigh*.Rseding91 wrote:That means in order to support it for custom-text-box the custom-text-box would have to store the min/max at all times in memory, save them to disk, listen to the change event and set the tooltip accordingly.
If i have to implement that on the lua side i'd do it like this:
Code: Select all
local A = GUI.add{type='textbox'}
global.watchlist[A] = {start = range_start, end = range_end, is_in_range = false}
add_range_tooltip(A)
script.on_event(on_gui_text_changed,function(event)
if watchlist[event.element] then
if is_in_range(event.element) then
event.element.style = default_style
watchlist[event.element].is_in_range = true
else
event.element.style = out_of_range_style
watchlist[event.element].is_in_range = false
end
end)
Any further thoughts? (Or implementation tips.)
Re: LuaGuiElement 'textfield' with value range
Yes.eradicator wrote:Are you implying that it would need to store/parse this for all text boxes regardless of if they use the feature? ...
If you want to get ahold of me I'm almost always on Discord.