Browse Source

prototype

pull/4487/head
Jumar Macato 6 years ago
parent
commit
32a34117e7
No known key found for this signature in database GPG Key ID: B19884DAC3A5BF3F
  1. 20
      samples/ControlCatalog/Pages/TextBoxPage.xaml
  2. 28
      src/Avalonia.Controls/TextBox.cs

20
samples/ControlCatalog/Pages/TextBoxPage.xaml

@ -4,21 +4,26 @@
<StackPanel.Styles>
<Style Selector="TextBox.InnerRight">
<Setter Property="Text" Value="Inner Right Content"/>
<Setter Property="InnerRightContent">
<Template>
<Button Content="Clear" />
<Button Content="Clear" Command="{Binding $parent[TextBox].Clear}" />
</Template>
</Setter>
</Style>
<Style Selector="TextBox.InnerLeft">
<Setter Property="Text" Value="Inner Left Content"/>
<Setter Property="InnerLeftContent">
<Template>
<Button Content="Clear" />
</Template>
</Setter>
</Style>
</Style>
<Style Selector="TextBox.Password">
<Setter Property="InnerRightContent">
<Template>
<ToggleButton Content="ToggleButton" IsChecked="{Binding $parent[TextBox].ShowPassword, Mode=OneWay}"/>
</Template>
</Setter>
</Style>
</StackPanel.Styles>
<TextBlock Classes="h1">TextBox</TextBlock>
@ -31,7 +36,8 @@
<TextBox Width="200" Watermark="Watermark" />
<TextBox Width="200" Watermark="Floating Watermark" UseFloatingWatermark="True" Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit."/>
<TextBox Width="200" Watermark="Password Box" UseFloatingWatermark="True" PasswordChar="*" Text="Password" />
<TextBox Width="200" Classes="Password" Watermark="Password Box" UseFloatingWatermark="True" PasswordChar="*" Text="Password" />
<TextBox Width="200" Text="Left aligned text" TextAlignment="Left" />
<TextBox Width="200" Text="Center aligned text" TextAlignment="Center" />
<TextBox Width="200" Text="Right aligned text" TextAlignment="Right" />
@ -42,8 +48,8 @@
<StackPanel Orientation="Vertical" Spacing="8">
<TextBox AcceptsReturn="True" TextWrapping="Wrap" Width="200" Height="125" Text="Multiline TextBox with TextWrapping.&#xD;&#xD;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est." />
<TextBox AcceptsReturn="True" Width="200" Height="125" Text="Multiline TextBox with no TextWrapping.&#xD;&#xD;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est." />
<TextBox Classes="InnerLeft" Width="200" FontWeight="Normal" FontStyle="Normal" FontFamily="avares://ControlCatalog/Assets/Fonts#Source Sans Pro"/>
<TextBox Classes="InnerRight" Width="200" FontWeight="Normal" FontStyle="Normal" FontFamily="avares://ControlCatalog/Assets/Fonts#Source Sans Pro"/>
<TextBox Classes="InnerLeft" Text="Inner Left Content" Width="200" FontWeight="Normal" FontStyle="Normal" FontFamily="avares://ControlCatalog/Assets/Fonts#Source Sans Pro"/>
<TextBox Classes="InnerRight" Text="Inner Right Content" Width="200" FontWeight="Normal" FontStyle="Normal" FontFamily="avares://ControlCatalog/Assets/Fonts#Source Sans Pro"/>
</StackPanel>
<StackPanel Orientation="Vertical" Spacing="8">
<TextBlock Classes="h2">resm fonts</TextBlock>

28
src/Avalonia.Controls/TextBox.cs

@ -101,6 +101,9 @@ namespace Avalonia.Controls
public static readonly StyledProperty<object> InnerRightContentProperty =
AvaloniaProperty.Register<TextBox, object>(nameof(InnerRightContent));
public static readonly StyledProperty<bool> ShowPasswordProperty =
AvaloniaProperty.Register<TextBox, bool>(nameof(ShowPassword));
struct UndoRedoState : IEquatable<UndoRedoState>
{
public string Text { get; }
@ -129,6 +132,10 @@ namespace Avalonia.Controls
static TextBox()
{
FocusableProperty.OverrideDefaultValue(typeof(TextBox), true);
ShowPasswordProperty.Changed.Subscribe((x)=>
{
});
}
public TextBox()
@ -291,7 +298,7 @@ namespace Avalonia.Controls
else
{
HandleTextInput(value);
}
}
_undoRedoHelper.Snapshot();
}
}
@ -344,6 +351,16 @@ namespace Avalonia.Controls
set { SetValue(InnerRightContentProperty, value); }
}
public bool ShowPassword
{
get { return GetValue(ShowPasswordProperty); }
set
{
SetValue(ShowPasswordProperty, value);
}
}
public TextWrapping TextWrapping
{
get { return GetValue(TextWrappingProperty); }
@ -774,7 +791,7 @@ namespace Avalonia.Controls
// if it did not, we change the selection to where the user clicked
var firstSelection = Math.Min(SelectionStart, SelectionEnd);
var lastSelection = Math.Max(SelectionStart, SelectionEnd);
var didClickInSelection = SelectionStart != SelectionEnd &&
var didClickInSelection = SelectionStart != SelectionEnd &&
caretIndex >= firstSelection && caretIndex <= lastSelection;
if (!didClickInSelection)
{
@ -821,6 +838,11 @@ namespace Avalonia.Controls
}
}
public void Clear()
{
Text = string.Empty;
}
private int DeleteCharacter(int index)
{
var start = index + 1;
@ -1086,7 +1108,7 @@ namespace Avalonia.Controls
SelectionEnd = CaretIndex;
}
private bool IsPasswordBox => PasswordChar != default(char);
private bool IsPasswordBox => ShowPassword && PasswordChar != default(char);
UndoRedoState UndoRedoHelper<UndoRedoState>.IUndoRedoHost.UndoRedoState
{

Loading…
Cancel
Save