Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds
SwitchButton
, a switch button control. This is intended mainly for power buttons in things like the APC UI and gas manipulation device UIs.space-wizards/space-station-14#39161 adds styles for this control to space-station-14 and changes the APC UI to use it.
Description and technical details
I've added some screenshots that show how the control's layout works. These use the styles from space-wizards/space-station-14#39161. That PR will not actually implement all of the UI changes shown in these screenshots. It only changes the APC menu. I plan to change the gas pump status button in a later PR, and I currently do not plan to actually change the intercom menu at all, but it makes a useful layout example.
The control has three visible components. From left to right, they are:
Clicking any of these toggles the button state.
The control has localizable default state labels of "Off" and "On"; I think having state labels improves usability in most of the cases where this control would be used. Microsoft uses default "Off" and "On" labels and encourages developers to use them; it seems likely they'd provide different guidance if these default labels caused many localization issues.
The default state labels can be overwritten by setting
OffStateText
andOnStateText
.The state label portion of the switch reserves overlapping space for both labels, so the button's size and layout don't change when the button is clicked.
If there is a main label, and the button is expanded horizontally, the excess space is put at the end of the main label. This means that if multiple switch buttons with the same labels and width are stacked, for instance in a vertical

BoxContainer
, they will all line up nicely.If the main label is empty, the icon and state label are aligned left.

It is my understanding that RobustToolbox doesn't support right-to-left text; if I am wrong about that then
SwitchButton
will need some additional work to handle rtl layouts.CheckButton
The
CheckButton
class appears to have originally been intended to be this type of control. It inherits fromButton
and I do not believe it has ever had any actual differences fromButton
.It is currently used in three places, all of which are have layouts based around it being regular button. As such, removing it or turning it into the actual switch button implementation would cause problems for old game versions.
I have added
[Obsolete]
toCheckButton
. In space-wizards/space-station-14#39161, all uses ofCheckButton
are replaced withButton
.