LuaGuiElement:focused [R/W] / on_gui_focused_state_changed event

Things that we aren't going to implement
User avatar
raiguard
Factorio Staff
Factorio Staff
Posts: 615
Joined: Wed Dec 13, 2017 8:29 pm
Contact:

LuaGuiElement:focused [R/W] / on_gui_focused_state_changed event

Post by raiguard »

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
2019-07-13 13_00_44-Factorio 0.17.56.png
2019-07-13 13_00_44-Factorio 0.17.56.png (45.58 KiB) Viewed 1756 times
Don't forget, you're here forever.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5304
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: LuaGuiElement:focused [R/W] / on_gui_focused_state_changed event

Post by Klonan »

You can implement it using the on_gui_text_changed event,
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
User avatar
raiguard
Factorio Staff
Factorio Staff
Posts: 615
Joined: Wed Dec 13, 2017 8:29 pm
Contact:

Re: LuaGuiElement:focused [R/W] / on_gui_focused_state_changed event

Post by raiguard »

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.
Attachments
sanity_checking.mp4
(27.16 KiB) Downloaded 78 times
Don't forget, you're here forever.
User avatar
Therenas
Factorio Staff
Factorio Staff
Posts: 261
Joined: Tue Dec 11, 2018 2:10 pm
Contact:

Re: LuaGuiElement:focused [R/W] / on_gui_focused_state_changed event

Post by Therenas »

+ 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.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14598
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: LuaGuiElement:focused [R/W] / on_gui_focused_state_changed event

Post by Rseding91 »

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.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5304
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: LuaGuiElement:focused [R/W] / on_gui_focused_state_changed event

Post by Klonan »

Rseding91 wrote: Sun Jul 14, 2019 1:56 pm 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.
Classic XY Problem
https://en.wikipedia.org/wiki/XY_problem
User avatar
raiguard
Factorio Staff
Factorio Staff
Posts: 615
Joined: Wed Dec 13, 2017 8:29 pm
Contact:

Re: LuaGuiElement:focused [R/W] / on_gui_focused_state_changed event

Post by raiguard »

Rseding91 wrote: Sun Jul 14, 2019 1:56 pm 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.
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.
Post Reply

Return to “Won't implement”