Radiobutton discussion

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
guardog
Burner Inserter
Burner Inserter
Posts: 8
Joined: Tue Aug 02, 2022 7:49 pm
Contact:

Radiobutton discussion

Post 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.

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2530
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Documentation Improvement Requests

Post 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.)
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

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

Re: Documentation Improvement Requests

Post 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
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2530
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Documentation Improvement Requests

Post 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.)
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

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

Re: Documentation Improvement Requests

Post 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 1999 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.)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2530
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Documentation Improvement Requests

Post 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.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

curiosity
Filter Inserter
Filter Inserter
Posts: 322
Joined: Wed Sep 11, 2019 4:13 pm
Contact:

Re: Documentation Improvement Requests

Post 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.

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

Re: Documentation Improvement Requests

Post 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.)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2530
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Documentation Improvement Requests

Post 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.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

curiosity
Filter Inserter
Filter Inserter
Posts: 322
Joined: Wed Sep 11, 2019 4:13 pm
Contact:

Re: Documentation Improvement Requests

Post 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.

User avatar
Therenas
Factorio Staff
Factorio Staff
Posts: 232
Joined: Tue Dec 11, 2018 2:10 pm
Contact:

Re: Radiobutton discussion

Post 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.

Post Reply

Return to “Modding discussion”