Skip to content

Commit

Permalink
Improve UI a bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
Equbuxu committed Dec 12, 2021
1 parent ca4e25c commit f577f8f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
25 changes: 20 additions & 5 deletions PixiEditor/Helpers/Behaviours/TextBoxFocusBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interactivity;
using PixiEditor.Models.Controllers.Shortcuts;

namespace PixiEditor.Helpers.Behaviours
{
Expand All @@ -12,11 +11,19 @@ internal class TextBoxFocusBehavior : Behavior<TextBox>
// Using a DependencyProperty as the backing store for FillSize. This enables animation, styling, binding, etc...
public static readonly DependencyProperty FillSizeProperty =
DependencyProperty.Register(
"FillSize",
nameof(FillSize),
typeof(bool),
typeof(TextBoxFocusBehavior),
new PropertyMetadata(false));

// Using a DependencyProperty as the backing store for FillSize. This enables animation, styling, binding, etc...
public static readonly DependencyProperty SelectOnFocusProperty =
DependencyProperty.Register(
nameof(SelectOnFocus),
typeof(bool),
typeof(TextBoxFocusBehavior),
new PropertyMetadata(true));

private string oldText; // Value of textbox before editing
private bool valueConverted; // This bool is used to avoid double convertion if enter is hitted

Expand All @@ -26,6 +33,12 @@ public bool FillSize
set => SetValue(FillSizeProperty, value);
}

public bool SelectOnFocus
{
get => (bool)GetValue(SelectOnFocusProperty);
set => SetValue(SelectOnFocusProperty, value);
}

protected override void OnAttached()
{
base.OnAttached();
Expand Down Expand Up @@ -74,7 +87,8 @@ private void RemoveFocus()
object sender,
KeyboardFocusChangedEventArgs e)
{
AssociatedObject.SelectAll();
if (SelectOnFocus)
AssociatedObject.SelectAll();
if (FillSize)
{
valueConverted = false;
Expand All @@ -86,7 +100,8 @@ private void RemoveFocus()
object sender,
MouseEventArgs e)
{
AssociatedObject.SelectAll();
if (SelectOnFocus)
AssociatedObject.SelectAll();
}

private void AssociatedObjectPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
Expand Down Expand Up @@ -127,4 +142,4 @@ private void ConvertValue()
valueConverted = true;
}
}
}
}
8 changes: 4 additions & 4 deletions PixiEditor/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<cmd:EventToCommand Command="{Binding CloseWindowCommand}" PassEventArgsToCommand="True" />
</i:EventTrigger>
</i:Interaction.Triggers>
<Grid Name="mainGrid" Margin="5" Focusable="True">
<Grid Name="mainGrid" Margin="5" Focusable="True" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="45" />
<ColumnDefinition Width="1*" />
Expand Down Expand Up @@ -256,10 +256,10 @@
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
<Grid Grid.Column="1" Grid.Row="2" Background="#303030">
<Grid Grid.Column="1" Grid.Row="2" Background="#303030" >
<Grid AllowDrop="True" Drop="MainWindow_Drop">
<DockingManager ActiveContent="{Binding BitmapManager.ActiveDocument, Mode=TwoWay, Converter={StaticResource DockingManagerActiveContentConverter}}"
DocumentsSource="{Binding BitmapManager.Documents}">
<DockingManager ActiveContent="{Binding BitmapManager.ActiveDocument, Mode=Default, Converter={StaticResource DockingManagerActiveContentConverter}}"
DocumentsSource="{Binding BitmapManager.Documents}" >
<DockingManager.Theme>
<avalonDockTheme:PixiEditorDockTheme />
</DockingManager.Theme>
Expand Down
2 changes: 1 addition & 1 deletion PixiEditor/Views/UserControls/SizeInput.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
d:Text="22">
<i:Interaction.Behaviors>
<behaviors:GlobalShortcutFocusBehavior/>
<behaviors:TextBoxFocusBehavior FillSize="True" />
<behaviors:TextBoxFocusBehavior FillSize="True" SelectOnFocus="{Binding SelectOnFocus, ElementName=uc}" />
</i:Interaction.Behaviors>
</TextBox>
<Grid Grid.Column="1" Background="{Binding BorderBrush, ElementName=border}"
Expand Down
9 changes: 9 additions & 0 deletions PixiEditor/Views/UserControls/SizeInput.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public SizeInput AspectRatioControl
public static readonly DependencyProperty MaxSizeProperty =
DependencyProperty.Register(nameof(MaxSize), typeof(int), typeof(SizeInput), new PropertyMetadata(int.MaxValue));

public static readonly DependencyProperty SelectOnFocusProperty =
DependencyProperty.Register(nameof(SelectOnFocus), typeof(bool), typeof(SizeInput), new PropertyMetadata(true));

private int loadedAspectRatioSize = -1;

private int loadedSize = -1;
Expand All @@ -49,6 +52,12 @@ public SizeInput()
InitializeComponent();
}

public bool SelectOnFocus
{
get => (bool)GetValue(SelectOnFocusProperty);
set => SetValue(SelectOnFocusProperty, value);
}

public int Size
{
get => (int)GetValue(SizeProperty);
Expand Down
4 changes: 2 additions & 2 deletions PixiEditor/Views/UserControls/SizePicker.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
AspectRatioValue="{Binding Path=ChosenHeight, ElementName=uc}"
AspectRatioControl="{Binding ElementName=HeightPicker}"
HorizontalAlignment="Left" Margin="10,0,0,0"
FontSize="16" MaxSize="9999"
FontSize="16" MaxSize="9999" SelectOnFocus="False"
Size="{Binding Path=ChosenWidth, ElementName=uc, Mode=TwoWay}" />
</DockPanel>
<DockPanel Margin="5,10,0,0" HorizontalAlignment="Center" VerticalAlignment="Center">
Expand All @@ -26,7 +26,7 @@
AspectRatioValue="{Binding Path=ChosenWidth, ElementName=uc}"
AspectRatioControl="{Binding ElementName=WidthPicker}"
HorizontalAlignment="Left" Width="150" Height="30"
FontSize="16" MaxSize="9999"
FontSize="16" MaxSize="9999" SelectOnFocus="False"
Size="{Binding ChosenHeight, ElementName=uc, Mode=TwoWay}" />
</DockPanel>
<CheckBox Name="aspectRatio" Content="Preserve aspect ratio" Foreground="White" HorizontalAlignment="Left"
Expand Down

0 comments on commit f577f8f

Please sign in to comment.