1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 14:53:01 +08:00

Tidy up OsuTabControl and FilterControl.

This commit is contained in:
Dean Herbert 2017-03-16 16:35:44 +09:00
parent 4bedd4d2d7
commit 334e389518
No known key found for this signature in database
GPG Key ID: 46D71BF4958ABB49
8 changed files with 122 additions and 89 deletions

View File

@ -26,7 +26,7 @@ namespace osu.Desktop.VisualTests.Tests
Add(new FillFlowContainer Add(new FillFlowContainer
{ {
Direction = FillDirection.Horizontal, Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Children = new Drawable[] Children = new Drawable[]
{ {
filter = new OsuTabControl<GroupMode> filter = new OsuTabControl<GroupMode>

View File

@ -15,7 +15,7 @@ namespace osu.Game.Graphics.UserInterface
protected override TabItem<T> CreateTabItem(T value) => new OsuTabItem<T> { Value = value }; protected override TabItem<T> CreateTabItem(T value) => new OsuTabItem<T> { Value = value };
public OsuTabControl(float offset = 0) : base(offset) public OsuTabControl()
{ {
if (!typeof(T).IsEnum) if (!typeof(T).IsEnum)
throw new InvalidOperationException("OsuTabControl only supports enums as the generic type argument"); throw new InvalidOperationException("OsuTabControl only supports enums as the generic type argument");
@ -45,5 +45,12 @@ namespace osu.Game.Graphics.UserInterface
item.AccentColour = value; item.AccentColour = value;
} }
} }
protected override void Update()
{
base.Update();
DropDown.Header.Height = DrawHeight;
}
} }
} }

View File

@ -1,29 +0,0 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.UserInterface.Tab;
namespace osu.Game.Graphics.UserInterface
{
public class OsuTabDropDownHeader : TabDropDownHeader
{
protected override string Label { get; set; }
public OsuTabDropDownHeader()
{
Foreground.Children = new Drawable[]
{
new TextAwesome
{
Icon = FontAwesome.fa_ellipsis_h,
TextSize = 14,
Margin = new MarginPadding{ Top = 6, Bottom = 4 },
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
}
};
}
}
}

View File

@ -6,18 +6,17 @@ using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Transforms; using osu.Framework.Graphics.Transforms;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Framework.Graphics.UserInterface.Tab; using osu.Framework.Graphics.UserInterface.Tab;
using osu.Framework.Input;
namespace osu.Game.Graphics.UserInterface namespace osu.Game.Graphics.UserInterface
{ {
public class OsuTabDropDownMenu<T> : TabDropDownMenu<T> public class OsuTabDropDownMenu<T> : TabDropDownMenu<T>
{ {
public override float HeaderWidth => 14;
public override float HeaderHeight => 24;
private Color4? accentColour; private Color4? accentColour;
public Color4 AccentColour public Color4 AccentColour
{ {
@ -25,7 +24,7 @@ namespace osu.Game.Graphics.UserInterface
set set
{ {
accentColour = value; accentColour = value;
Header.Colour = value; ((OsuTabDropDownHeader)Header).AccentColour = value;
foreach (var item in ItemList.OfType<OsuTabDropDownMenuItem<T>>()) foreach (var item in ItemList.OfType<OsuTabDropDownMenuItem<T>>())
item.AccentColour = value; item.AccentColour = value;
} }
@ -33,7 +32,7 @@ namespace osu.Game.Graphics.UserInterface
protected override DropDownHeader CreateHeader() => new OsuTabDropDownHeader protected override DropDownHeader CreateHeader() => new OsuTabDropDownHeader
{ {
Colour = AccentColour AccentColour = AccentColour
}; };
protected override DropDownMenuItem<T> CreateDropDownItem(string key, T value) => protected override DropDownMenuItem<T> CreateDropDownItem(string key, T value) =>
@ -69,5 +68,63 @@ namespace osu.Game.Graphics.UserInterface
if (accentColour == null) if (accentColour == null)
AccentColour = colours.Blue; AccentColour = colours.Blue;
} }
public class OsuTabDropDownHeader : DropDownHeader
{
protected override string Label { get; set; }
private Color4? accentColour;
public Color4 AccentColour
{
get { return accentColour.GetValueOrDefault(); }
set
{
accentColour = value;
BackgroundColourHover = value;
Foreground.Colour = value;
}
}
protected override bool OnHover(InputState state)
{
Foreground.Colour = BackgroundColour;
return base.OnHover(state);
}
protected override void OnHoverLost(InputState state)
{
Foreground.Colour = BackgroundColourHover;
base.OnHoverLost(state);
}
public OsuTabDropDownHeader()
{
RelativeSizeAxes = Axes.None;
AutoSizeAxes = Axes.X;
BackgroundColour = Color4.Black;
Background.Height = 0.5f;
Background.CornerRadius = 3;
Background.Masking = true;
Foreground.RelativeSizeAxes = Axes.None;
Foreground.AutoSizeAxes = Axes.X;
Foreground.RelativeSizeAxes = Axes.Y;
Foreground.Margin = new MarginPadding(5);
Foreground.Children = new Drawable[]
{
new TextAwesome
{
Icon = FontAwesome.fa_ellipsis_h,
TextSize = 14,
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
}
};
Padding = new MarginPadding { Left = 5, Right = 5 };
}
}
} }
} }

View File

@ -81,12 +81,16 @@ namespace osu.Game.Graphics.UserInterface
public OsuTabItem() public OsuTabItem()
{ {
AutoSizeAxes = Axes.Both; AutoSizeAxes = Axes.X;
RelativeSizeAxes = Axes.Y;
Children = new Drawable[] Children = new Drawable[]
{ {
text = new OsuSpriteText text = new OsuSpriteText
{ {
Margin = new MarginPadding(5), Margin = new MarginPadding(5),
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
TextSize = 14, TextSize = 14,
Font = @"Exo2.0-Bold", // Font should only turn bold when active? Font = @"Exo2.0-Bold", // Font should only turn bold when active?
}, },

View File

@ -27,6 +27,8 @@ namespace osu.Game.Screens.Select
private OsuTabControl<SortMode> sortTabs; private OsuTabControl<SortMode> sortTabs;
TabControl<GroupMode> groupTabs;
private SortMode sort = SortMode.Title; private SortMode sort = SortMode.Title;
public SortMode Sort public SortMode Sort
{ {
@ -55,34 +57,30 @@ namespace osu.Game.Screens.Select
} }
} }
private OsuSpriteText spriteText;
public Action Exit; public Action Exit;
private SearchTextBox searchTextBox; private SearchTextBox searchTextBox;
public FilterControl(float height) public override bool Contains(Vector2 screenSpacePos) => base.Contains(screenSpacePos) || groupTabs.Contains(screenSpacePos) || sortTabs.Contains(screenSpacePos);
{
TabControl<GroupMode> groupTabs;
public FilterControl()
{
Children = new Drawable[] Children = new Drawable[]
{ {
new Box new Box
{ {
Colour = Color4.Black, Colour = Color4.Black,
Alpha = 0.8f, Alpha = 0.8f,
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.Both,
Height = height
}, },
new FillFlowContainer new Container
{ {
Padding = new MarginPadding(20), Padding = new MarginPadding(20),
AutoSizeAxes = Axes.Y, BypassContainsCheck = true,
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.Y,
Width = 500,
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
Origin = Anchor.TopRight, Origin = Anchor.TopRight,
Width = 0.4f, // TODO: InnerWidth property or something
Direction = FillDirection.Vertical,
Children = new Drawable[] Children = new Drawable[]
{ {
searchTextBox = new SearchTextBox searchTextBox = new SearchTextBox
@ -95,53 +93,50 @@ namespace osu.Game.Screens.Select
}, },
Exit = () => Exit?.Invoke(), Exit = () => Exit?.Invoke(),
}, },
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
{
new Box new Box
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Height = 1, Height = 1,
Y = 24,
Colour = OsuColour.Gray(80), Colour = OsuColour.Gray(80),
Origin = Anchor.TopLeft, Origin = Anchor.BottomLeft,
Anchor = Anchor.TopLeft, Anchor = Anchor.BottomLeft,
Position = new Vector2(0, 23)
}, },
groupTabs = new OsuTabControl<GroupMode> new FillFlowContainer
{ {
Width = 230, Anchor = Anchor.BottomRight,
AutoSort = true Origin = Anchor.BottomRight,
}, Direction = FillDirection.Horizontal,
new Container RelativeSizeAxes = Axes.X,
{ AutoSizeAxes = Axes.Y,
AutoSizeAxes = Axes.Both, BypassContainsCheck = true,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Children = new Drawable[] Children = new Drawable[]
{ {
spriteText = new OsuSpriteText groupTabs = new OsuTabControl<GroupMode>
{ {
Font = @"Exo2.0-Bold", RelativeSizeAxes = Axes.X,
Text = "Sort results by", Width = 0.5f,
TextSize = 14, AutoSort = true
Margin = new MarginPadding
{
Top = 5,
Bottom = 5
}, },
}, //spriteText = new OsuSpriteText
sortTabs = new OsuTabControl<SortMode>(87) //{
// Font = @"Exo2.0-Bold",
// Text = "Sort results by",
// TextSize = 14,
// Margin = new MarginPadding
// {
// Top = 5,
// Bottom = 5
// },
//},
sortTabs = new OsuTabControl<SortMode>()
{ {
Width = 191, RelativeSizeAxes = Axes.X,
Width = 0.5f,
AutoSort = true, AutoSort = true,
} }
} }
} },
}
}
} }
} }
}; };
@ -166,7 +161,7 @@ namespace osu.Game.Screens.Select
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
sortTabs.AccentColour = spriteText.Colour = colours.GreenLight; sortTabs.AccentColour = colours.GreenLight;
} }
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => true; protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => true;

View File

@ -94,10 +94,10 @@ namespace osu.Game.Screens.Select
Anchor = Anchor.CentreRight, Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight, Origin = Anchor.CentreRight,
}); });
Add(FilterControl = new FilterControl(filter_height) Add(FilterControl = new FilterControl
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, Height = filter_height,
FilterChanged = () => filterChanged(), FilterChanged = () => filterChanged(),
Exit = Exit, Exit = Exit,
}); });

View File

@ -350,7 +350,6 @@
<Compile Include="Screens\Select\Options\BeatmapOptionsButton.cs" /> <Compile Include="Screens\Select\Options\BeatmapOptionsButton.cs" />
<Compile Include="Screens\Select\Options\BeatmapOptionsOverlay.cs" /> <Compile Include="Screens\Select\Options\BeatmapOptionsOverlay.cs" />
<Compile Include="Graphics\UserInterface\OsuTabControl.cs" /> <Compile Include="Graphics\UserInterface\OsuTabControl.cs" />
<Compile Include="Graphics\UserInterface\OsuTabDropDownHeader.cs" />
<Compile Include="Graphics\UserInterface\OsuTabDropDownMenu.cs" /> <Compile Include="Graphics\UserInterface\OsuTabDropDownMenu.cs" />
<Compile Include="Graphics\UserInterface\OsuTabDropDownMenuItem.cs" /> <Compile Include="Graphics\UserInterface\OsuTabDropDownMenuItem.cs" />
<Compile Include="Graphics\UserInterface\OsuTabItem.cs" /> <Compile Include="Graphics\UserInterface\OsuTabItem.cs" />