1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 16:27:26 +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
{
Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both,
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
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 };
public OsuTabControl(float offset = 0) : base(offset)
public OsuTabControl()
{
if (!typeof(T).IsEnum)
throw new InvalidOperationException("OsuTabControl only supports enums as the generic type argument");
@ -45,5 +45,12 @@ namespace osu.Game.Graphics.UserInterface
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 osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Transforms;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Graphics.UserInterface.Tab;
using osu.Framework.Input;
namespace osu.Game.Graphics.UserInterface
{
public class OsuTabDropDownMenu<T> : TabDropDownMenu<T>
{
public override float HeaderWidth => 14;
public override float HeaderHeight => 24;
private Color4? accentColour;
public Color4 AccentColour
{
@ -25,7 +24,7 @@ namespace osu.Game.Graphics.UserInterface
set
{
accentColour = value;
Header.Colour = value;
((OsuTabDropDownHeader)Header).AccentColour = value;
foreach (var item in ItemList.OfType<OsuTabDropDownMenuItem<T>>())
item.AccentColour = value;
}
@ -33,7 +32,7 @@ namespace osu.Game.Graphics.UserInterface
protected override DropDownHeader CreateHeader() => new OsuTabDropDownHeader
{
Colour = AccentColour
AccentColour = AccentColour
};
protected override DropDownMenuItem<T> CreateDropDownItem(string key, T value) =>
@ -69,5 +68,63 @@ namespace osu.Game.Graphics.UserInterface
if (accentColour == null)
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()
{
AutoSizeAxes = Axes.Both;
AutoSizeAxes = Axes.X;
RelativeSizeAxes = Axes.Y;
Children = new Drawable[]
{
text = new OsuSpriteText
{
Margin = new MarginPadding(5),
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
TextSize = 14,
Font = @"Exo2.0-Bold", // Font should only turn bold when active?
},

View File

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

View File

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

View File

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