Files
space-station-14/Content.Client/Stylesheets/Sheetlets/SwitchButtonSheetlet.cs
Absotively 6ee812cfe5 SwitchButton (#39161)
* Initial toggle switch styling

* tweak toggle switch textures

* Simplify toggle SVG images a bit

* Better name for switch button

* Update CheckButtons that were already just regular buttons

* Match checkbox/text field outline colour instead of slider outline colour

* Use switch button for APC power

* Update switch button styling; add separate style for power buttons

* Use new switch button in midi channels menu

* Add spacer

* adjust switch button icon proportions, position

* Add disabled toggle switch styles, use improved pressed style setup, make APC breaker state visible to all

* Use Janet Blackquill's icon design; remove StyleClassPowerSwitchButton. Co-authored-by: Janet Blackquill <uhhadd@gmail.com>

* Style switch children directly instead of with propagated styles

* Add attributions file

* Turns out source is a required field

* Move SwitchButton out of engine

* Move styles to sheetlet

* Make workaround for child controls not updating work in content

* Icon layers

* Set up ISwitchButtonConfig

* Fix disabled switch label font color

* Don't redefine base pseudostyles

* Use pseudoclass helpers for better readability

* Use margin instead of padding element

* Remove unused using statements

* Remove extra image file

* Update attributions for changed files
2026-01-22 17:31:56 +00:00

126 lines
5.6 KiB
C#

using Content.Client.Stylesheets.SheetletConfigs;
using Content.Client.Stylesheets.Stylesheets;
using Content.Client.UserInterface.Controls;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using static Content.Client.Stylesheets.StylesheetHelpers;
namespace Content.Client.Stylesheets.Sheetlets;
[CommonSheetlet]
public sealed class SwitchButtonSheetlet<T> : Sheetlet<T> where T : PalettedStylesheet, ISwitchButtonConfig
{
public override StyleRule[] GetRules(T sheet, object config)
{
ISwitchButtonConfig switchButtonCfg = sheet;
var trackFillTex = sheet.GetTextureOr(switchButtonCfg.SwitchButtonTrackFillPath, NanotrasenStylesheet.TextureRoot);
var trackOutlineTex = sheet.GetTextureOr(switchButtonCfg.SwitchButtonTrackOutlinePath, NanotrasenStylesheet.TextureRoot);
var thumbFillTex = sheet.GetTextureOr(switchButtonCfg.SwitchButtonThumbFillPath, NanotrasenStylesheet.TextureRoot);
var thumbOutlineTex = sheet.GetTextureOr(switchButtonCfg.SwitchButtonThumbOutlinePath, NanotrasenStylesheet.TextureRoot);
var symbolOffTex = sheet.GetTextureOr(switchButtonCfg.SwitchButtonSymbolOffPath, NanotrasenStylesheet.TextureRoot);
var symbolOnTex = sheet.GetTextureOr(switchButtonCfg.SwitchButtonSymbolOnPath, NanotrasenStylesheet.TextureRoot);
return
[
// SwitchButton
E<SwitchButton>().Prop(SwitchButton.StylePropertySeparation, 10),
E<SwitchButton>()
.ParentOf(E<TextureRect>().Class(SwitchButton.StyleClassTrackFill))
.Prop(TextureRect.StylePropertyTexture, trackFillTex)
.Modulate(sheet.SecondaryPalette.BackgroundDark),
E<SwitchButton>()
.ParentOf(E<TextureRect>().Class(SwitchButton.StyleClassTrackOutline))
.Prop(TextureRect.StylePropertyTexture, trackOutlineTex)
.Modulate(sheet.SecondaryPalette.Text),
E<SwitchButton>()
.ParentOf(E<TextureRect>().Class(SwitchButton.StyleClassThumbFill))
.Prop(TextureRect.StylePropertyTexture, thumbFillTex)
.Modulate(sheet.PrimaryPalette.Element)
.HorizontalAlignment(Control.HAlignment.Left),
E<SwitchButton>()
.ParentOf(E<TextureRect>().Class(SwitchButton.StyleClassThumbOutline))
.Prop(TextureRect.StylePropertyTexture, thumbOutlineTex)
.Modulate(sheet.PrimaryPalette.Text)
.HorizontalAlignment(Control.HAlignment.Left),
E<SwitchButton>()
.ParentOf(E<TextureRect>().Class(SwitchButton.StyleClassSymbol))
.Prop(TextureRect.StylePropertyTexture, symbolOffTex)
.Modulate(sheet.SecondaryPalette.Text),
// Pressed styles
E<SwitchButton>()
.PseudoPressed()
.ParentOf(E<TextureRect>().Class(SwitchButton.StyleClassTrackFill))
.Modulate(sheet.PositivePalette.Text),
E<SwitchButton>()
.PseudoPressed()
.ParentOf(E<TextureRect>().Class(SwitchButton.StyleClassSymbol))
.Prop(TextureRect.StylePropertyTexture, symbolOnTex)
.Modulate(Color.White), // Same color as text, not yet in any of the palettes
E<SwitchButton>()
.PseudoPressed()
.ParentOf(E<TextureRect>().Class(SwitchButton.StyleClassThumbFill))
.HorizontalAlignment(Control.HAlignment.Right),
E<SwitchButton>()
.PseudoPressed()
.ParentOf(E<TextureRect>().Class(SwitchButton.StyleClassThumbOutline))
.HorizontalAlignment(Control.HAlignment.Right),
// Disabled styles
E<SwitchButton>()
.PseudoDisabled()
.ParentOf(E<TextureRect>().Class(SwitchButton.StyleClassTrackFill))
.Modulate(sheet.SecondaryPalette.DisabledElement),
E<SwitchButton>()
.PseudoDisabled()
.ParentOf(E<TextureRect>().Class(SwitchButton.StyleClassTrackOutline))
.Modulate(sheet.SecondaryPalette.DisabledElement),
E<SwitchButton>()
.PseudoDisabled()
.ParentOf(E<TextureRect>().Class(SwitchButton.StyleClassThumbFill))
.Modulate(sheet.PrimaryPalette.DisabledElement),
E<SwitchButton>()
.PseudoDisabled()
.ParentOf(E<TextureRect>().Class(SwitchButton.StyleClassThumbOutline))
.Modulate(sheet.PrimaryPalette.TextDark),
E<SwitchButton>()
.PseudoDisabled()
.ParentOf(E<TextureRect>().Class(SwitchButton.StyleClassSymbol))
.Modulate(sheet.SecondaryPalette.TextDark),
E<SwitchButton>()
.PseudoDisabled()
.ParentOf(E<Label>())
.Modulate(sheet.PrimaryPalette.TextDark),
// Both pressed & disabled styles
// Note that some of the pressed-only and disabled-only styles do not conflict
// and will also be used
E<SwitchButton>()
.PseudoPressed()
.PseudoDisabled()
.ParentOf(E<TextureRect>().Class(SwitchButton.StyleClassTrackFill))
.Modulate(sheet.PositivePalette.DisabledElement),
E<SwitchButton>()
.PseudoPressed()
.PseudoDisabled()
.ParentOf(E<TextureRect>().Class(SwitchButton.StyleClassSymbol))
.Modulate(sheet.PositivePalette.Text),
];
}
}