1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-24 10:47:24 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/ShearedSearchTextBox.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

152 lines
6.0 KiB
C#
Raw Normal View History

2022-04-21 04:59:36 +08:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.Sprites;
using osu.Game.Overlays;
2022-04-22 23:01:56 +08:00
using osu.Game.Overlays.Mods;
2022-04-21 04:59:36 +08:00
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Graphics.UserInterface
{
public class ShearedSearchTextBox : CompositeDrawable, IHasCurrentValue<string>
{
private const float icon_container_width = 50;
2022-04-22 23:01:56 +08:00
private const float corner_radius = 7;
2022-04-21 04:59:36 +08:00
private const float height = 42;
2022-04-22 23:01:56 +08:00
private readonly Vector2 shear = new Vector2(ShearedOverlayContainer.SHEAR, 0);
private readonly Box background;
private readonly Box searchBoxBackground;
private readonly SearchTextBox textBox;
2022-04-21 04:59:36 +08:00
public Bindable<string> Current
{
get => textBox.Current;
set => textBox.Current = value;
2022-04-21 04:59:36 +08:00
}
public bool HoldFocus
{
get => textBox.HoldFocus;
set => textBox.HoldFocus = value;
}
public void TakeFocus() => textBox.TakeFocus();
public void KillFocus() => textBox.KillFocus();
public ShearedSearchTextBox()
2022-04-21 04:59:36 +08:00
{
Height = height;
Shear = shear;
Masking = true;
CornerRadius = corner_radius;
InternalChild = new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
background = new Box
2022-04-21 04:59:36 +08:00
{
RelativeSizeAxes = Axes.Both
},
new GridContainer
{
RelativeSizeAxes = Axes.Both,
Content = new[]
{
new Drawable[]
{
new Container
{
Name = @"Search box container",
RelativeSizeAxes = Axes.Both,
CornerRadius = corner_radius,
Masking = true,
Children = new Drawable[]
{
searchBoxBackground = new Box
2022-04-21 04:59:36 +08:00
{
RelativeSizeAxes = Axes.Both
},
textBox = new InnerSearchTextBox
2022-04-21 04:59:36 +08:00
{
Shear = -shear,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
RelativeSizeAxes = Axes.X,
Padding = new MarginPadding
{
2022-04-22 23:01:56 +08:00
Horizontal = corner_radius + shear.X
2022-04-21 04:59:36 +08:00
}
}
}
},
new Container
{
Name = @"Icon container",
RelativeSizeAxes = Axes.Y,
Width = icon_container_width,
Origin = Anchor.CentreRight,
Anchor = Anchor.CentreRight,
Children = new Drawable[]
{
new SpriteIcon
{
Icon = FontAwesome.Solid.Search,
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Size = new Vector2(16),
Shear = -shear
}
}
}
}
},
ColumnDimensions = new[] { new Dimension(), new Dimension(GridSizeMode.AutoSize) }
}
}
};
}
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
background.Colour = colourProvider.Background3;
searchBoxBackground.Colour = colourProvider.Background4;
}
public override bool HandleNonPositionalInput => textBox.HandleNonPositionalInput;
2022-04-21 04:59:36 +08:00
2022-05-03 12:24:48 +08:00
private class InnerSearchTextBox : SearchTextBox
2022-04-21 04:59:36 +08:00
{
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
BackgroundFocused = colourProvider.Background4;
BackgroundUnfocused = colourProvider.Background4;
Placeholder.Colour = Color4.White;
PlaceholderText = @"Search";
}
protected override SpriteText CreatePlaceholder() => new OsuSpriteText
{
Font = OsuFont.GetFont(size: 20, weight: FontWeight.SemiBold)
};
protected override Drawable GetDrawableCharacter(char c) => new FallingDownContainer
{
AutoSizeAxes = Axes.Both,
Child = new OsuSpriteText { Text = c.ToString(), Font = OsuFont.GetFont(size: 20, weight: FontWeight.SemiBold) },
};
}
}
}