GUI and textfield focus

Place to get help with not working mods / modding interface.
Post Reply
Pi-C
Smart Inserter
Smart Inserter
Posts: 1651
Joined: Sun Oct 14, 2018 8:13 am
Contact:

GUI and textfield focus

Post by Pi-C »

I've made a GUI containing a table with textfields. In response to on_gui_click and on_gui_text_changed, I change the textfield's style to highlighting mode, and when on_gui_confirmed fires, I reset the style again. This works great, but …

If the player is typing into one textfield and presses <TAB>, the focus is moved away from the current textfield to the next one available. I don't mind that the first textfield still is highlighted -- that's as expected because I want to warn the player that there still are unconfirmed changes. But I'd really like to change the style of the newly selected textfield as soon as it gets the focus.

In the following screenshot, the textfield for the Spidertron has been highlighted because it was active but the changes have not yet been confirmed. The textfield of the Heavy Truck still has the normal style you get when focusing a textfield with the tabulator key:
Spidertron: changes
Spidertron: changes
gui_textfields.png (31.21 KiB) Viewed 1047 times



In the light of threads like 92021, I suppose that will not be possible to detect when a textfield gets the focus. Or is there some secret way I could get it to work? :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
yaim904
Long Handed Inserter
Long Handed Inserter
Posts: 86
Joined: Wed Nov 17, 2021 11:26 pm
Contact:

Re: GUI and textfield focus

Post by yaim904 »

Hello,

I hope you are well,

There is no event related to the focus, and making them by means of flag variables (variables that indicate that everything is going well) can become tedious, but I think it is one of the options you have.

The other option that I envision is that you validate everything in the confirmation event, but I know the problems that this causes, so you must choose which wrong to accept.
Solo entiendo español, pero si tu también lo entiendes, escríbeme
:D
Everything i write in English is translated by google.
:D

Pi-C
Smart Inserter
Smart Inserter
Posts: 1651
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: GUI and textfield focus

Post by Pi-C »

yaim904 wrote:
Tue Jul 26, 2022 1:36 pm
Hello,

I hope you are well,
Hi, hope you are well, too! :-)

There is no event related to the focus, and making them by means of flag variables (variables that indicate that everything is going well) can become tedious, but I think it is one of the options you have.

The other option that I envision is that you validate everything in the confirmation event, but I know the problems that this causes, so you must choose which wrong to accept.
Thanks for the suggestions! However, I've found another way in the meantime: I listen to on_gui_text_changed changed now, so I can verify the text as soon as a character has been entered. When the text in the textfield matches an existing name, I set its style to "invalid_value_textfield". Also, when the cursor has just moved into that textfield (i.e. if the textfield still has the default style), I set the style to "highlighted_value_textfield". Finally, in on_gui_confirmed, I reset the style to the default again.

It is a compromise because the style won't be changed automatically -- the player must type something first. But it's less hassle than keeping track of what element has the focus and I think it will be sufficient.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
yaim904
Long Handed Inserter
Long Handed Inserter
Posts: 86
Joined: Wed Nov 17, 2021 11:26 pm
Contact:

Re: GUI and textfield focus

Post by yaim904 »

Pi-C wrote:
Tue Jul 26, 2022 2:06 pm
Thanks for the suggestions! However, I've found another way in the meantime: I listen to on_gui_text_changed changed now, so I can verify the text as soon as a character has been entered. When the text in the textfield matches an existing name, I set its style to "invalid_value_textfield". Also, when the cursor has just moved into that textfield (i.e. if the textfield still has the default style), I set the style to "highlighted_value_textfield". Finally, in on_gui_confirmed, I reset the style to the default again.
I like it is logical, maybe I implement it in my mod.
Solo entiendo español, pero si tu también lo entiendes, escríbeme
:D
Everything i write in English is translated by google.
:D

Post Reply

Return to “Modding help”