Merge pull request #330 from peppy/textbox-improvements

Textbox improvements
This commit is contained in:
Dean Herbert 2017-02-08 17:34:12 +09:00 committed by GitHub
commit fd8179b370
11 changed files with 142 additions and 80 deletions

@ -1 +1 @@
Subproject commit 93cd883930e362f7bb8c361ac7f36b5387d4fac3
Subproject commit 3811650c08bc47282a373d870e4d2203b38d275d

View File

@ -1,7 +1,11 @@
// 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.Sprites;
using osu.Framework.MathUtils;
using OpenTK;
using OpenTK.Graphics;
namespace osu.Game.Graphics.Sprites
{
@ -14,5 +18,26 @@ public OsuSpriteText()
Shadow = true;
TextSize = FONT_SIZE;
}
protected override Drawable CreateFallbackCharacterDrawable()
{
var tex = GetTextureForCharacter('?');
if (tex != null)
{
float adjust = (RNG.NextSingle() - 0.5f) * 2;
return new Sprite
{
Texture = tex,
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Scale = new Vector2(1 + adjust * 0.2f),
Rotation = adjust * 15,
Colour = Color4.White,
};
}
return base.CreateFallbackCharacterDrawable();
}
}
}

View File

@ -13,7 +13,7 @@
namespace osu.Game.Graphics.UserInterface
{
class Nub : Container, IStateful<CheckBoxState>
class Nub : CircularContainer, IStateful<CheckBoxState>
{
public const float COLLAPSED_SIZE = 20;
public const float EXPANDED_SIZE = 40;
@ -27,10 +27,6 @@ public Nub()
{
Size = new Vector2(COLLAPSED_SIZE, 12);
Masking = true;
CornerRadius = Height / 2;
Masking = true;
BorderColour = Color4.White;
BorderThickness = border_width;

View File

@ -0,0 +1,52 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Transformations;
using OpenTK;
using OpenTK.Graphics;
namespace osu.Game.Graphics.UserInterface
{
public class OsuPasswordTextBox : OsuTextBox
{
protected override Drawable GetDrawableCharacter(char c) => new PasswordMaskChar(CalculatedTextSize);
public class PasswordMaskChar : Container
{
private CircularContainer circle;
public PasswordMaskChar(float size)
{
Size = new Vector2(size / 2, size);
Children = new[]
{
circle = new CircularContainer
{
Anchor = Anchor.Centre,
Alpha = 0,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.8f, 0),
Children = new[]
{
new Box
{
Colour = Color4.White,
RelativeSizeAxes = Axes.Both,
}
},
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
circle.FadeIn(500, EasingTypes.OutQuint);
circle.ResizeTo(new Vector2(0.8f), 500, EasingTypes.OutQuint);
}
}
}
}

View File

@ -3,6 +3,8 @@
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input;
using osu.Game.Graphics.Sprites;
@ -17,10 +19,19 @@ public class OsuTextBox : TextBox
protected override Color4 BackgroundFocused => OsuColour.Gray(0.3f).Opacity(0.8f);
protected override Color4 BackgroundCommit => BorderColour;
protected override float LeftRightPadding => 10;
protected override SpriteText CreatePlaceholder() => new OsuSpriteText
{
Font = @"Exo2.0-MediumItalic",
Colour = new Color4(180, 180, 180, 255),
Margin = new MarginPadding { Left = 2 },
};
public OsuTextBox()
{
Height = 40;
TextContainer.Height = OsuSpriteText.FONT_SIZE / Height;
TextContainer.Height = 0.5f;
CornerRadius = 5;
}
@ -43,12 +54,7 @@ protected override void OnFocusLost(InputState state)
base.OnFocusLost(state);
}
}
public class OsuPasswordTextBox : OsuTextBox
{
protected virtual char MaskCharacter => '*';
protected override Drawable AddCharacterToFlow(char c) => base.AddCharacterToFlow(MaskCharacter);
protected override Drawable GetDrawableCharacter(char c) => new OsuSpriteText { Text = c.ToString(), TextSize = CalculatedTextSize };
}
}

View File

@ -14,7 +14,7 @@
namespace osu.Game.Overlays
{
class LoginOverlay : OverlayContainer
class LoginOverlay : FocusedOverlayContainer
{
private LoginOptions optionsSection;
@ -64,6 +64,8 @@ private void load(OsuColour colours)
protected override void PopIn()
{
base.PopIn();
optionsSection.Bounding = true;
FadeIn(transition_time, EasingTypes.OutQuint);
}

View File

@ -26,16 +26,16 @@ public Bindable<string> Bindable
}
}
}
protected override string InternalText
public OptionTextBox()
{
get { return base.InternalText; }
set
{
base.InternalText = value;
if (bindable != null)
bindable.Value = value;
}
OnChange += onChange;
}
private void onChange(TextBox sender, bool newText)
{
if (bindable != null)
bindable.Value = Text;
}
private void bindableValueChanged(object sender, EventArgs e)

View File

@ -19,7 +19,7 @@ public class LoginOptions : OptionsSubsection, IOnlineComponent
{
private bool bounding = true;
protected override string Header => "Sign In";
protected override string Header => "Account";
public override RectangleF BoundingBox => bounding ? base.BoundingBox : RectangleF.Empty;
@ -112,11 +112,13 @@ private void load(APIAccess api, OsuConfigManager config)
{
username = new OsuTextBox
{
PlaceholderText = "Username",
RelativeSizeAxes = Axes.X,
Text = api?.Username ?? string.Empty
},
password = new OsuPasswordTextBox
{
PlaceholderText = "Password",
RelativeSizeAxes = Axes.X
},
saveUsername = new OsuCheckbox

View File

@ -23,7 +23,7 @@
namespace osu.Game.Overlays
{
public class OptionsOverlay : OverlayContainer
public class OptionsOverlay : FocusedOverlayContainer
{
internal const float CONTENT_MARGINS = 10;
@ -159,26 +159,10 @@ protected override void Update()
}
}
protected override bool OnHover(InputState state) => true;
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => true;
protected override bool OnClick(InputState state) => true;
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
switch (args.Key)
{
case Key.Escape:
if (State == Visibility.Hidden) return false;
Hide();
return true;
}
return base.OnKeyDown(state, args);
}
protected override void PopIn()
{
base.PopIn();
scrollContainer.MoveToX(0, TRANSITION_LENGTH, EasingTypes.OutQuint);
sidebar.MoveToX(0, TRANSITION_LENGTH, EasingTypes.OutQuint);
FadeTo(1, TRANSITION_LENGTH / 2);

View File

@ -3,19 +3,20 @@
using System;
using System.Linq;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Input;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Screens.Select
{
public class SearchTextBox : TextBox
/// <summary>
/// A textbox which holds focus eagerly.
/// </summary>
public class SearchTextBox : OsuTextBox
{
protected override Color4 BackgroundUnfocused => new Color4(10, 10, 10, 255);
protected override Color4 BackgroundFocused => new Color4(10, 10, 10, 255);
@ -33,39 +34,13 @@ public bool HoldFocus
}
}
private SpriteText placeholder;
protected override string InternalText
{
get { return base.InternalText; }
set
{
base.InternalText = value;
if (placeholder != null)
{
if (string.IsNullOrEmpty(value))
placeholder.Text = "type to search";
else
placeholder.Text = string.Empty;
}
}
}
public override bool RequestingFocus => HoldFocus;
public SearchTextBox()
{
Height = 35;
TextContainer.Padding = new MarginPadding(5);
Add(new Drawable[]
{
placeholder = new SpriteText
{
Font = @"Exo2.0-MediumItalic",
Text = "type to search",
Colour = new Color4(180, 180, 180, 255),
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Margin = new MarginPadding { Left = 10 },
},
new TextAwesome
{
Icon = FontAwesome.fa_search,
@ -74,25 +49,44 @@ public SearchTextBox()
Margin = new MarginPadding { Right = 10 },
}
});
PlaceholderText = "type to search";
}
protected override void Update()
protected override bool OnFocus(InputState state)
{
if (HoldFocus) RequestFocus();
base.Update();
var result = base.OnFocus(state);
BorderThickness = 0;
return result;
}
protected override void OnFocusLost(InputState state)
{
if (state.Keyboard.Keys.Any(key => key == Key.Escape))
Exit?.Invoke();
{
if (Text.Length > 0)
Text = string.Empty;
else
Exit?.Invoke();
}
base.OnFocusLost(state);
}
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
if (args.Key == Key.Left || args.Key == Key.Right || args.Key == Key.Enter)
return false;
if (!state.Keyboard.ControlPressed && !state.Keyboard.ShiftPressed)
{
switch (args.Key)
{
case Key.Left:
case Key.Right:
case Key.Up:
case Key.Down:
case Key.Enter:
return false;
}
}
return base.OnKeyDown(state, args);
}
}

View File

@ -69,6 +69,7 @@
<Compile Include="Graphics\Sprites\OsuSpriteText.cs" />
<Compile Include="Graphics\UserInterface\BackButton.cs" />
<Compile Include="Graphics\UserInterface\Nub.cs" />
<Compile Include="Graphics\UserInterface\OsuPasswordTextBox.cs" />
<Compile Include="Graphics\UserInterface\OsuSliderBar.cs" />
<Compile Include="Graphics\UserInterface\OsuTextBox.cs" />
<Compile Include="Graphics\UserInterface\TwoLayerButton.cs" />