Skip to content

Commit

Permalink
Change size button should inherit the ToolbarEditActionButton.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Aug 19, 2024
1 parent d8758eb commit 78282f9
Showing 1 changed file with 56 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Karaoke.Configuration;
using osu.Game.Rulesets.Karaoke.Utils;
using osuTK;
Expand All @@ -21,10 +20,7 @@ public partial class AdjustFontSizeButton : CompositeDrawable

public AdjustFontSizeButton()
{
IconButton previousSizeButton;
OsuSpriteText fontSizeSpriteText;
IconButton nextSizeButton;
float[] sizes = FontUtils.ComposerFontSize();

Height = SpecialActionToolbar.HEIGHT;
AutoSizeAxes = Axes.X;
Expand All @@ -36,18 +32,9 @@ public AdjustFontSizeButton()
Direction = FillDirection.Horizontal,
Children = new Drawable[]
{
previousSizeButton = new IconButton
new DecreasePreviewFontSizeActionButton
{
Size = new Vector2(SpecialActionToolbar.ICON_SIZE),
Icon = FontAwesome.Solid.Minus,
Action = () =>
{
float previousSize = sizes.GetPrevious(bindableFontSize.Value);
if (previousSize == default)
return;

bindableFontSize.Value = previousSize;
},
},
new Container
{
Expand All @@ -59,27 +46,16 @@ public AdjustFontSizeButton()
Origin = Anchor.Centre,
},
},
nextSizeButton = new IconButton
new IncreasePreviewFontSizeActionButton
{
Size = new Vector2(SpecialActionToolbar.ICON_SIZE),
Icon = FontAwesome.Solid.Plus,
Action = () =>
{
float nextSize = sizes.GetNext(bindableFontSize.Value);
if (nextSize == default)
return;

bindableFontSize.Value = nextSize;
},
},
},
};

bindableFontSize.BindValueChanged(e =>
{
fontSizeSpriteText.Text = FontUtils.GetText(e.NewValue);
previousSizeButton.Enabled.Value = sizes.GetPrevious(e.NewValue) != default;
nextSizeButton.Enabled.Value = sizes.GetNext(e.NewValue) != default;
});
}

Expand All @@ -88,4 +64,58 @@ private void load(KaraokeRulesetLyricEditorConfigManager lyricEditorConfigManage
{
lyricEditorConfigManager.BindWith(KaraokeRulesetLyricEditorSetting.FontSizeInComposer, bindableFontSize);
}

private partial class DecreasePreviewFontSizeActionButton : PreviewFontSizeActionButton
{
protected override KaraokeEditAction EditAction => KaraokeEditAction.DecreasePreviewFontSize;

protected override float GetTriggeredFontSize(float[] sizes, float currentFontSize) => sizes.GetPrevious(currentFontSize);

public DecreasePreviewFontSizeActionButton()
{
SetIcon(FontAwesome.Solid.Minus);
}
}

private partial class IncreasePreviewFontSizeActionButton : PreviewFontSizeActionButton
{
protected override KaraokeEditAction EditAction => KaraokeEditAction.IncreasePreviewFontSize;

protected override float GetTriggeredFontSize(float[] sizes, float currentFontSize) => sizes.GetNext(currentFontSize);

public IncreasePreviewFontSizeActionButton()
{
SetIcon(FontAwesome.Solid.Plus);
}
}

private abstract partial class PreviewFontSizeActionButton : ToolbarEditActionButton
{
private static readonly float[] sizes = FontUtils.ComposerFontSize();

private readonly Bindable<float> bindableFontSize = new();

protected PreviewFontSizeActionButton()
{
Action = () =>
{
float triggeredFontSize = GetTriggeredFontSize(sizes, bindableFontSize.Value);
bindableFontSize.Value = triggeredFontSize != default ? triggeredFontSize : bindableFontSize.Value;
};

bindableFontSize.BindValueChanged(e =>
{
float triggeredFontSize = GetTriggeredFontSize(sizes, e.NewValue);
SetState(triggeredFontSize != default);
});
}

protected abstract float GetTriggeredFontSize(float[] sizes, float currentFontSize);

[BackgroundDependencyLoader]
private void load(KaraokeRulesetLyricEditorConfigManager lyricEditorConfigManager)
{
lyricEditorConfigManager.BindWith(KaraokeRulesetLyricEditorSetting.FontSizeInComposer, bindableFontSize);
}
}
}

0 comments on commit 78282f9

Please sign in to comment.