1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-17 16:52:57 +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,7 +145,15 @@ namespace osu.Game.Graphics.UserInterface
Origin = Anchor.CentreLeft; Origin = Anchor.CentreLeft;
AutoSizeAxes = Axes.Both; AutoSizeAxes = Axes.Both;
Spacing = new Vector2(10);
Direction = FillDirection.Horizontal;
Child = new Container
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
Margin = new MarginPadding { Horizontal = MARGIN_HORIZONTAL, Vertical = MARGIN_VERTICAL },
Children = new Drawable[] Children = new Drawable[]
{ {
NormalText = new OsuSpriteText NormalText = new OsuSpriteText
@ -154,7 +162,6 @@ namespace osu.Game.Graphics.UserInterface
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
Font = OsuFont.GetFont(size: text_size), Font = OsuFont.GetFont(size: text_size),
Margin = new MarginPadding { Horizontal = MARGIN_HORIZONTAL, Vertical = MARGIN_VERTICAL },
}, },
BoldText = new OsuSpriteText BoldText = new OsuSpriteText
{ {
@ -163,7 +170,7 @@ namespace osu.Game.Graphics.UserInterface
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold), Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold),
Margin = new MarginPadding { Horizontal = MARGIN_HORIZONTAL, Vertical = MARGIN_VERTICAL }, }
} }
}; };
} }

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);