Skip to content

Commit

Permalink
Improve visuals of BasicSliderBar focus
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Oct 21, 2024
1 parent df5fffc commit cc00127
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public TestSceneSliderBar()
Size = new Vector2(200, 50),
BackgroundColour = Color4.White,
SelectionColour = Color4.Pink,
FocusColour = Color4.Purple,
FocusColour = Color4.OrangeRed,
KeyboardStep = 1,
Current = sliderBarValue
},
Expand All @@ -73,7 +73,7 @@ public TestSceneSliderBar()
RangePadding = 20,
BackgroundColour = Color4.White,
SelectionColour = Color4.Pink,
FocusColour = Color4.Purple,
FocusColour = Color4.OrangeRed,
KeyboardStep = 1,
Current = sliderBarValue
},
Expand All @@ -87,7 +87,7 @@ public TestSceneSliderBar()
Size = new Vector2(200, 10),
BackgroundColour = Color4.White,
SelectionColour = Color4.Pink,
FocusColour = Color4.Purple,
FocusColour = Color4.OrangeRed,
KeyboardStep = 1,
Current = sliderBarValue
},
Expand All @@ -100,7 +100,7 @@ public TestSceneSliderBar()
Size = new Vector2(200, 10),
BackgroundColour = Color4.White,
SelectionColour = Color4.Pink,
FocusColour = Color4.Purple,
FocusColour = Color4.OrangeRed,
KeyboardStep = 1,
Current = sliderBarValue
},
Expand Down
37 changes: 20 additions & 17 deletions osu.Framework/Graphics/UserInterface/BasicSliderBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,10 @@ public Color4 BackgroundColour
set => Box.Colour = value;
}

private Color4 selectionColour = FrameworkColour.Yellow;

public Color4 SelectionColour
{
get => selectionColour;
set
{
selectionColour = value;
updateColour();
}
get => SelectionBox.Colour;
set => SelectionBox.Colour = value;
}

private Color4 focusColour = FrameworkColour.YellowGreen;
Expand All @@ -38,7 +32,7 @@ public Color4 FocusColour
set
{
focusColour = value;
updateColour();
updateFocus();
}
}

Expand All @@ -56,30 +50,39 @@ public BasicSliderBar()
},
SelectionBox = new Box
{
Colour = FrameworkColour.Yellow,
RelativeSizeAxes = Axes.Both,
}
};

updateColour();
}

private void updateColour()
{
SelectionBox.Colour = HasFocus ? FocusColour : SelectionColour;
Masking = true;
}

protected override void OnFocus(FocusEvent e)
{
updateColour();
updateFocus();
base.OnFocus(e);
}

protected override void OnFocusLost(FocusLostEvent e)
{
updateColour();
updateFocus();
base.OnFocusLost(e);
}

private void updateFocus()
{
if (HasFocus)
{
BorderThickness = 3;
BorderColour = FocusColour;
}
else
{
BorderThickness = 0;
}
}

protected override void UpdateValue(float value)
{
SelectionBox.ScaleTo(new Vector2(value, 1), 300, Easing.OutQuint);
Expand Down

0 comments on commit cc00127

Please sign in to comment.