Skip to content

Commit

Permalink
Add tabbing support to setup metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
flustix committed Apr 14, 2024
1 parent 0e7dbd6 commit 46d611e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
18 changes: 17 additions & 1 deletion fluXis.Game/Screens/Edit/Tabs/Setup/Entries/SetupTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,27 @@
using fluXis.Game.Graphics.UserInterface.Color;
using fluXis.Game.Graphics.UserInterface.Text;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Events;

namespace fluXis.Game.Screens.Edit.Tabs.Setup.Entries;

public partial class SetupTextBox : SetupEntry
public partial class SetupTextBox : SetupEntry, ITabbableContainer
{
public bool CanBeTabbedTo => true;
public override bool AcceptsFocus => true;

protected override float ContentSpacing => -3;

public string Default { get; init; } = string.Empty;
public string Placeholder { get; init; } = string.Empty;
public Action<string> OnChange { get; init; } = _ => { };

public CompositeDrawable TabbableContentContainer
{
set => textBox.TabbableContentContainer = value;
}

private FluXisTextBox textBox;

public SetupTextBox(string title)
Expand All @@ -36,4 +46,10 @@ protected override Drawable CreateContent()
OnTextChanged = () => OnChange.Invoke(textBox.Text)
};
}

protected override void OnFocus(FocusEvent e)
{
// redirect focus to the textbox
GetContainingInputManager().ChangeFocus(textBox);
}
}
11 changes: 9 additions & 2 deletions fluXis.Game/Screens/Edit/Tabs/SetupTab.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Linq;
using fluXis.Game.Graphics.Containers;
using fluXis.Game.Graphics.Sprites;
using fluXis.Game.Graphics.UserInterface.Color;
using fluXis.Game.Screens.Edit.Tabs.Setup;
using fluXis.Game.Screens.Edit.Tabs.Setup.Entries;
using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
Expand All @@ -17,6 +19,8 @@ public partial class SetupTab : EditorTab
public override IconUsage Icon => FontAwesome6.Solid.ScrewdriverWrench;
public override string TabName => "Setup";

private SetupSection metadata;

[BackgroundDependencyLoader]
private void load(EditorMap map)
{
Expand Down Expand Up @@ -71,7 +75,7 @@ private void load(EditorMap map)
Spacing = new Vector2(30),
Children = new Drawable[]
{
new SetupSection("Metadata")
metadata = new SetupSection("Metadata")
{
Entries = new Drawable[]
{
Expand Down Expand Up @@ -110,7 +114,7 @@ private void load(EditorMap map)
Default = map.MapInfo.Metadata.Tags,
Placeholder = "No Tags",
OnChange = value => map.MapInfo.Metadata.Tags = map.RealmMap.Metadata.Tags = value
},
}
}
},
new SetupSection("Colors")
Expand Down Expand Up @@ -206,5 +210,8 @@ private void load(EditorMap map)
}
}
};

// tabbing support
metadata.OfType<SetupTextBox>().ForEach(textBox => textBox.TabbableContentContainer = metadata);
}
}

0 comments on commit 46d611e

Please sign in to comment.