Hello. I am attempting to create an interface with a slider and number field, similar to many vanilla settings GUIs. In order to emulate exactly how input sanitation works in vanilla, I need to be able to tell when the user "defocuses" the textbox.
There is currently no way to read the focused state of a GUI element, so I would like to request that that capability be added. And in order to avoid the necessity of having an on_tick() event to keep track of the focused state, some sort of on_gui_focused_state_changed event would be nice.
Thanks in advance!
- raiguard
LuaGuiElement:focused [R/W] / on_gui_focused_state_changed event
LuaGuiElement:focused [R/W] / on_gui_focused_state_changed event
Don't forget, you're here forever.
Re: LuaGuiElement:focused [R/W] / on_gui_focused_state_changed event
You can implement it using the on_gui_text_changed event,
I have done the same in a mod of my own:
I have done the same in a mod of my own:
- Attachments
-
- 2019-07-13_22-01-23.mp4
- (350.81 KiB) Downloaded 67 times
Re: LuaGuiElement:focused [R/W] / on_gui_focused_state_changed event
Sorry, that's not what I meant. I have already done that as well. What I need this capability for is to emulate vanilla's sanity checking:
Vanilla doesn't actually edit the user's input while they're typing, but will correct it when they defocus the textfield. This is the behavior I am trying to emulate, which is impossible without what I requested.
The best that is possible now is to sanitize as the user types, but that can be very annoying since it won't let you completely replace the number very easily.
As an aside, it would be nice if pressing enter would defocus the textfield, like what happens with vanilla textfields.
Vanilla doesn't actually edit the user's input while they're typing, but will correct it when they defocus the textfield. This is the behavior I am trying to emulate, which is impossible without what I requested.
The best that is possible now is to sanitize as the user types, but that can be very annoying since it won't let you completely replace the number very easily.
As an aside, it would be nice if pressing enter would defocus the textfield, like what happens with vanilla textfields.
- Attachments
-
- sanity_checking.mp4
- (27.16 KiB) Downloaded 78 times
Don't forget, you're here forever.
Re: LuaGuiElement:focused [R/W] / on_gui_focused_state_changed event
+ 1 to this (and the unfocus on enter)
You can kind of catch the unfocus by listening to on_gui_click, and checking if the clicked element is not the one that should be reset, and run your code from there. It it not really reliable though, because not everything that defocuses fires on_gui_clicked.
You can kind of catch the unfocus by listening to on_gui_click, and checking if the clicked element is not the one that should be reset, and run your code from there. It it not really reliable though, because not everything that defocuses fires on_gui_clicked.
Re: LuaGuiElement:focused [R/W] / on_gui_focused_state_changed event
You're asking for the wrong thing. You should have just asked for support to do exactly what the base game is doing in that text field.
If you want to get ahold of me I'm almost always on Discord.
Re: LuaGuiElement:focused [R/W] / on_gui_focused_state_changed event
Well I was trying to generalize it. I figured that something more general that could have lots of usecases would be more likely to make it in, than something very specific.
Don't forget, you're here forever.