Skip to content

Commit 033a73e

Browse files
committed
Update switch button visuals
1 parent 95cf050 commit 033a73e

File tree

2 files changed

+26
-33
lines changed

2 files changed

+26
-33
lines changed

osu.Game/Graphics/UserInterfaceV2/FormCheckBox.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private void load(AudioManager audio)
8888
Anchor = Anchor.BottomLeft,
8989
Origin = Anchor.BottomLeft,
9090
},
91-
new FormSwitchButton
91+
new SwitchButton
9292
{
9393
Anchor = Anchor.CentreRight,
9494
Origin = Anchor.CentreRight,
@@ -173,12 +173,5 @@ private void updateState()
173173
public void SetDefault() => Current.SetDefault();
174174

175175
public bool IsDisabled => Current.Disabled;
176-
177-
private partial class FormSwitchButton : SwitchButton
178-
{
179-
// it doesn't make sense for this to show hover state or respond to input.
180-
// FormCheckBox already handles all of that.
181-
public override bool PropagatePositionalInputSubTree => false;
182-
}
183176
}
184177
}

osu.Game/Graphics/UserInterfaceV2/SwitchButton.cs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public partial class SwitchButton : Checkbox
2323
private const float padding = 1.25f;
2424

2525
private readonly Box fill;
26-
private readonly Container switchContainer;
27-
private readonly Drawable switchCircle;
28-
private readonly CircularContainer circularContainer;
26+
private readonly Container nubContainer;
27+
private readonly Drawable nub;
28+
private readonly CircularContainer content;
2929

3030
[Resolved]
3131
private OverlayColourProvider colourProvider { get; set; } = null!;
@@ -37,7 +37,7 @@ public SwitchButton()
3737
{
3838
Size = new Vector2(45, 20);
3939

40-
InternalChild = circularContainer = new CircularContainer
40+
InternalChild = content = new CircularContainer
4141
{
4242
RelativeSizeAxes = Axes.Both,
4343
BorderColour = Color4.White,
@@ -55,15 +55,14 @@ public SwitchButton()
5555
{
5656
RelativeSizeAxes = Axes.Both,
5757
Padding = new MarginPadding(border_thickness + padding),
58-
Child = switchContainer = new Container
58+
Child = nubContainer = new Container
5959
{
6060
RelativeSizeAxes = Axes.Both,
61-
Child = switchCircle = new CircularContainer
61+
Child = nub = new Circle
6262
{
6363
RelativeSizeAxes = Axes.Both,
6464
FillMode = FillMode.Fit,
6565
Masking = true,
66-
Child = new Box { RelativeSizeAxes = Axes.Both }
6766
}
6867
}
6968
}
@@ -90,7 +89,7 @@ protected override void LoadComplete()
9089

9190
private void updateState()
9291
{
93-
switchCircle.MoveToX(Current.Value ? switchContainer.DrawWidth - switchCircle.DrawWidth : 0, 200, Easing.OutQuint);
92+
nub.MoveToX(Current.Value ? nubContainer.DrawWidth - nub.DrawWidth : 0, 200, Easing.OutQuint);
9493
fill.FadeTo(Current.Value ? 1 : 0, 250, Easing.OutQuint);
9594

9695
updateColours();
@@ -120,32 +119,33 @@ protected override void OnUserChange(bool value)
120119

121120
private void updateColours()
122121
{
123-
ColourInfo targetSwitchColour;
124-
ColourInfo targetBorderColour;
122+
ColourInfo borderColour;
123+
ColourInfo switchColour;
125124

126125
if (Current.Disabled)
127126
{
128-
if (Current.Value)
129-
targetBorderColour = colourProvider.Dark1.Opacity(0.5f);
130-
else
131-
targetBorderColour = colourProvider.Background2.Opacity(0.5f);
132-
133-
targetSwitchColour = colourProvider.Dark1.Opacity(0.5f);
134-
fill.Colour = colourProvider.Background5;
127+
borderColour = colourProvider.Dark2;
128+
switchColour = colourProvider.Dark1;
129+
fill.Colour = colourProvider.Dark5;
135130
}
136131
else
137132
{
138-
if (Current.Value)
139-
targetBorderColour = IsHovered ? colourProvider.Highlight1.Lighten(0.3f) : colourProvider.Highlight1;
140-
else
141-
targetBorderColour = IsHovered ? colourProvider.Background1 : colourProvider.Background2;
133+
bool hover = IsHovered && !Current.Disabled;
134+
135+
borderColour = hover ? colourProvider.Highlight1.Opacity(0.5f) : colourProvider.Highlight1.Opacity(0.3f);
136+
switchColour = hover ? colourProvider.Highlight1 : colourProvider.Light4;
137+
138+
if (!Current.Value)
139+
{
140+
borderColour = borderColour.MultiplyAlpha(0.8f);
141+
switchColour = switchColour.MultiplyAlpha(0.8f);
142+
}
142143

143-
targetSwitchColour = colourProvider.Highlight1;
144-
fill.Colour = colourProvider.Background4;
144+
fill.Colour = colourProvider.Background6;
145145
}
146146

147-
switchContainer.FadeColour(targetSwitchColour, 250, Easing.OutQuint);
148-
circularContainer.TransformTo(nameof(BorderColour), targetBorderColour, 250, Easing.OutQuint);
147+
nubContainer.FadeColour(switchColour, 250, Easing.OutQuint);
148+
content.TransformTo(nameof(BorderColour), borderColour, 250, Easing.OutQuint);
149149
}
150150
}
151151
}

0 commit comments

Comments
 (0)