Page 1 of 1

Radiobutton discussion

Posted: Mon Nov 28, 2022 1:57 am
by guardog
https://lua-api.factorio.com/latest/LuaGuiElement.html

Just being nitpicky with the description of "radiobutton" type.

Functionally I think it is a little bit different from checkbox - when you click a selected checkbox it will deselect, but if you click a selected radio button it stays selected.

Re: Documentation Improvement Requests

Posted: Wed Nov 30, 2022 3:31 pm
by FuryoftheStars
guardog wrote:
Mon Nov 28, 2022 1:57 am
https://lua-api.factorio.com/latest/LuaGuiElement.html

Just being nitpicky with the description of "radiobutton" type.

Functionally I think it is a little bit different from checkbox - when you click a selected checkbox it will deselect, but if you click a selected radio button it stays selected.
Additionally, their uses are also different. In a group of checkboxes, you can select multiple. In a group of radiobuttons, selecting one deselects the rest.
(At least, this is how they're supposed to work. I don't know if Factorio has anything implemented for that automatically or not.)

Re: Documentation Improvement Requests

Posted: Fri Dec 02, 2022 2:01 pm
by Pi-C
FuryoftheStars wrote:
Wed Nov 30, 2022 3:31 pm
Additionally, their uses are also different. In a group of checkboxes, you can select multiple. In a group of radiobuttons, selecting one deselects the rest.
(At least, this is how they're supposed to work. I don't know if Factorio has anything implemented for that automatically or not.)
I believe you have to take care of toggling radiobuttons in your GUIs yourself. See here:
"radiobutton": A clickable element that is functionally identical to a checkbox, but has a circular appearance. Relevant event: on_gui_checked_state_changed

Re: Documentation Improvement Requests

Posted: Fri Dec 02, 2022 2:54 pm
by FuryoftheStars
Pi-C wrote:
Fri Dec 02, 2022 2:01 pm
FuryoftheStars wrote:
Wed Nov 30, 2022 3:31 pm
Additionally, their uses are also different. In a group of checkboxes, you can select multiple. In a group of radiobuttons, selecting one deselects the rest.
(At least, this is how they're supposed to work. I don't know if Factorio has anything implemented for that automatically or not.)
I believe you have to take care of toggling radiobuttons in your GUIs yourself. See here:
"radiobutton": A clickable element that is functionally identical to a checkbox, but has a circular appearance. Relevant event: on_gui_checked_state_changed
Yes, I had already read that, but every place where I've used radios have something implemented in the backend so any radios placed in the same container are automatically linked and thus change each other's states.

I suppose you could take the way it's written in the Factorio documentation to mean they don't have that, but I suppose (for clarity sake) I'd suggest making a mention in there one way or the other if the modder needs to handle it themselves. (I think this is what I was (poorly) trying to say before.)

Re: Documentation Improvement Requests

Posted: Fri Dec 02, 2022 4:47 pm
by Pi-C
FuryoftheStars wrote:
Fri Dec 02, 2022 2:54 pm
Pi-C wrote:
Fri Dec 02, 2022 2:01 pm
"radiobutton": A clickable element that is functionally identical to a checkbox, but has a circular appearance. Relevant event: on_gui_checked_state_changed
Yes, I had already read that, but every place where I've used radios have something implemented in the backend so any radios placed in the same container are automatically linked and thus change each other's states.
Consider this screenshot from a mod I'm working on:
checkboxes.png
checkboxes.png (25.85 KiB) Viewed 2134 times
Each player can "own" only one vehicle at a time, but may have "locked" several vehicles simultaneously. The checkboxes are all contained in the same table. Which ones should be linked? All checkboxes in the same table, all checkboxes in the same row, or all checkboxes in the same column? The game doesn't know how you want your interface to work, so it seems reasonable that you have to implement some logic for toggling the boxes yourself.

(By the way: I could have used radio buttons for "Toggle ownership" to make it more obvious that only one of them can be active at any given time. However, with radio buttons, one would always be on -- but in this case it is intended that all buttons could be off.)

Re: Documentation Improvement Requests

Posted: Fri Dec 02, 2022 5:45 pm
by FuryoftheStars
Pi-C wrote:
Fri Dec 02, 2022 4:47 pm
FuryoftheStars wrote:
Fri Dec 02, 2022 2:54 pm
Pi-C wrote:
Fri Dec 02, 2022 2:01 pm
"radiobutton": A clickable element that is functionally identical to a checkbox, but has a circular appearance. Relevant event: on_gui_checked_state_changed
Yes, I had already read that, but every place where I've used radios have something implemented in the backend so any radios placed in the same container are automatically linked and thus change each other's states.
Consider this screenshot from a mod I'm working on:
checkboxes.png
Each player can "own" only one vehicle at a time, but may have "locked" several vehicles simultaneously. The checkboxes are all contained in the same table. Which ones should be linked? All checkboxes in the same table, all checkboxes in the same row, or all checkboxes in the same column? The game doesn't know how you want your interface to work, so it seems reasonable that you have to implement some logic for toggling the boxes yourself.

(By the way: I could have used radio buttons for "Toggle ownership" to make it more obvious that only one of them can be active at any given time. However, with radio buttons, one would always be on -- but in this case it is intended that all buttons could be off.)
I haven't done UIs in Factorio, so I don't know what they have for containers, but what I'm used to is being able to put in smaller containers within the main one for exactly that purpose. And if you have something more complex, then (again, what I'm used to) you have the ability to set a property that disables the automatic linking on a per radiobutton basis. Checkboxes are never done automatically in what I've used.

Re: Documentation Improvement Requests

Posted: Mon Dec 05, 2022 1:29 am
by curiosity
FuryoftheStars wrote:
Fri Dec 02, 2022 2:54 pm
Yes, I had already read that, but every place where I've used radios have something implemented in the backend so any radios placed in the same container are automatically linked and thus change each other's states.
I have only seen an automatic implementation like that once in all the frameworks I have encountered (ironically, it was the very first one, which gave me unreasonable expectations for the rest).

But yes, for the sake of clarity it's worth mentioning that there's no automagic behavior to radiobuttons.

Re: Documentation Improvement Requests

Posted: Mon Dec 05, 2022 9:37 am
by Pi-C
FuryoftheStars wrote:
Fri Dec 02, 2022 5:45 pm
I haven't done UIs in Factorio, so I don't know what they have for containers, but what I'm used to is being able to put in smaller containers within the main one for exactly that purpose.
GUIs in Factorio have different types of containers, which may be nested. There are frames, flows, and scroll-panes. All of these have a "direction" property which determines whether the elements put into the container will be arranged horizontally or vertically. Additionally, there are tables that require a "column_count" property on creation. All elements added to a table will be arranged horizontally until there are more than column_count elements in a row; as soon as there are more elements than column_count, the row will be wrapped, and the element will be added as first column of the next row. Thus, there is no way to link all radio buttons in a row or all radio buttons in a column because you don't define rows and columns, but just add some elements. (If you want to add more columns to your table, but forget to change column_count, you may end up with shifted columns, e.g. a label above a checkbox above a textfield instead of 3 labels in column 1, 3 checkboxes in column 2, and 3 textfields in column 3.)

Re: Documentation Improvement Requests

Posted: Mon Dec 05, 2022 2:12 pm
by FuryoftheStars
Pi-C wrote:
Mon Dec 05, 2022 9:37 am
FuryoftheStars wrote:
Fri Dec 02, 2022 5:45 pm
I haven't done UIs in Factorio, so I don't know what they have for containers, but what I'm used to is being able to put in smaller containers within the main one for exactly that purpose.
GUIs in Factorio have different types of containers, which may be nested. There are frames, flows, and scroll-panes. All of these have a "direction" property which determines whether the elements put into the container will be arranged horizontally or vertically. Additionally, there are tables that require a "column_count" property on creation. All elements added to a table will be arranged horizontally until there are more than column_count elements in a row; as soon as there are more elements than column_count, the row will be wrapped, and the element will be added as first column of the next row. Thus, there is no way to link all radio buttons in a row or all radio buttons in a column because you don't define rows and columns, but just add some elements. (If you want to add more columns to your table, but forget to change column_count, you may end up with shifted columns, e.g. a label above a checkbox above a textfield instead of 3 labels in column 1, 3 checkboxes in column 2, and 3 textfields in column 3.)
Ok... but this doesn't change that I think it'd still be good to note that they're not automatically linked.

Re: Documentation Improvement Requests

Posted: Mon Dec 26, 2022 5:23 am
by curiosity
guardog wrote:
Mon Nov 28, 2022 1:57 am
https://lua-api.factorio.com/latest/LuaGuiElement.html

Just being nitpicky with the description of "radiobutton" type.

Functionally I think it is a little bit different from checkbox - when you click a selected checkbox it will deselect, but if you click a selected radio button it stays selected.
This is very important to note. The distinctive property of radiobuttons is not their "circular appearance" (which is just a customizable graphic), but their behavior when clicked while in the "on" state.

Re: Radiobutton discussion

Posted: Wed Mar 22, 2023 4:34 pm
by Therenas
(Split from documentation improvement requests thread)

-> I noted for 1.1.79 that radiobuttons both don't unselect when clicked and are not linked in any way. Thanks to all.