mirror of
https://github.com/ppy/osu.git
synced 2024-12-17 12:22:55 +08:00
Refactor DrawableOsuMenuItem
to remove a hack
This commit is contained in:
parent
ef1add3ebb
commit
3531f646f2
@ -124,7 +124,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
protected sealed override Drawable CreateContent() => text = CreateTextContainer();
|
||||
protected virtual TextContainer CreateTextContainer() => new TextContainer();
|
||||
|
||||
protected partial class TextContainer : Container, IHasText
|
||||
protected partial class TextContainer : FillFlowContainer, IHasText
|
||||
{
|
||||
public LocalisableString Text
|
||||
{
|
||||
@ -145,25 +145,32 @@ namespace osu.Game.Graphics.UserInterface
|
||||
Origin = Anchor.CentreLeft;
|
||||
|
||||
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.
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
Font = OsuFont.GetFont(size: text_size),
|
||||
Margin = new MarginPadding { Horizontal = MARGIN_HORIZONTAL, Vertical = MARGIN_VERTICAL },
|
||||
},
|
||||
BoldText = new OsuSpriteText
|
||||
{
|
||||
AlwaysPresent = true, // ensures that the menu item does not change width when switching between normal and bold text.
|
||||
Alpha = 0,
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold),
|
||||
Margin = new MarginPadding { Horizontal = MARGIN_HORIZONTAL, Vertical = MARGIN_VERTICAL },
|
||||
NormalText = new OsuSpriteText
|
||||
{
|
||||
AlwaysPresent = true, // ensures that the menu item does not change width when switching between normal and bold text.
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
Font = OsuFont.GetFont(size: text_size),
|
||||
},
|
||||
BoldText = new OsuSpriteText
|
||||
{
|
||||
AlwaysPresent = true, // ensures that the menu item does not change width when switching between normal and bold text.
|
||||
Alpha = 0,
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold),
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
Size = new Vector2(10),
|
||||
Margin = new MarginPadding { Horizontal = MARGIN_HORIZONTAL },
|
||||
Margin = new MarginPadding { Left = -MARGIN_HORIZONTAL, Right = MARGIN_HORIZONTAL },
|
||||
AlwaysPresent = true,
|
||||
});
|
||||
}
|
||||
@ -62,14 +62,6 @@ namespace osu.Game.Graphics.UserInterface
|
||||
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)
|
||||
{
|
||||
var icon = menuItem.GetIconForState(state.NewValue);
|
||||
|
Loading…
Reference in New Issue
Block a user