1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-17 14:33:21 +08:00

Refactor DrawableOsuMenuItem to remove a hack

This commit is contained in:
Bartłomiej Dach 2024-07-18 09:46:06 +02:00
parent ef1add3ebb
commit 3531f646f2
No known key found for this signature in database
2 changed files with 25 additions and 26 deletions

View File

@ -124,7 +124,7 @@ namespace osu.Game.Graphics.UserInterface
protected sealed override Drawable CreateContent() => text = CreateTextContainer(); protected sealed override Drawable CreateContent() => text = CreateTextContainer();
protected virtual TextContainer CreateTextContainer() => new TextContainer(); protected virtual TextContainer CreateTextContainer() => new TextContainer();
protected partial class TextContainer : Container, IHasText protected partial class TextContainer : FillFlowContainer, IHasText
{ {
public LocalisableString Text public LocalisableString Text
{ {
@ -145,25 +145,32 @@ namespace osu.Game.Graphics.UserInterface
Origin = Anchor.CentreLeft; Origin = Anchor.CentreLeft;
AutoSizeAxes = Axes.Both; AutoSizeAxes = Axes.Both;
Spacing = new Vector2(10);
Direction = FillDirection.Horizontal;
Children = new Drawable[] Child = new Container
{ {
NormalText = new OsuSpriteText Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
Margin = new MarginPadding { Horizontal = MARGIN_HORIZONTAL, Vertical = MARGIN_VERTICAL },
Children = new Drawable[]
{ {
AlwaysPresent = true, // ensures that the menu item does not change width when switching between normal and bold text. NormalText = new OsuSpriteText
Anchor = Anchor.CentreLeft, {
Origin = Anchor.CentreLeft, AlwaysPresent = true, // ensures that the menu item does not change width when switching between normal and bold text.
Font = OsuFont.GetFont(size: text_size), Anchor = Anchor.CentreLeft,
Margin = new MarginPadding { Horizontal = MARGIN_HORIZONTAL, Vertical = MARGIN_VERTICAL }, Origin = Anchor.CentreLeft,
}, Font = OsuFont.GetFont(size: text_size),
BoldText = new OsuSpriteText },
{ BoldText = new OsuSpriteText
AlwaysPresent = true, // ensures that the menu item does not change width when switching between normal and bold text. {
Alpha = 0, AlwaysPresent = true, // ensures that the menu item does not change width when switching between normal and bold text.
Anchor = Anchor.CentreLeft, Alpha = 0,
Origin = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold), Origin = Anchor.CentreLeft,
Margin = new MarginPadding { Horizontal = MARGIN_HORIZONTAL, Vertical = MARGIN_VERTICAL }, Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold),
}
} }
}; };
} }

View File

@ -51,7 +51,7 @@ namespace osu.Game.Graphics.UserInterface
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
Size = new Vector2(10), Size = new Vector2(10),
Margin = new MarginPadding { Horizontal = MARGIN_HORIZONTAL }, Margin = new MarginPadding { Left = -MARGIN_HORIZONTAL, Right = MARGIN_HORIZONTAL },
AlwaysPresent = true, AlwaysPresent = true,
}); });
} }
@ -62,14 +62,6 @@ namespace osu.Game.Graphics.UserInterface
state.BindValueChanged(updateState, true); state.BindValueChanged(updateState, true);
} }
protected override void Update()
{
base.Update();
// Todo: This is bad. This can maybe be done better with a refactor of DrawableOsuMenuItem.
stateIcon.X = BoldText.DrawWidth + 10;
}
private void updateState(ValueChangedEvent<object> state) private void updateState(ValueChangedEvent<object> state)
{ {
var icon = menuItem.GetIconForState(state.NewValue); var icon = menuItem.GetIconForState(state.NewValue);