Readded Carriage - Moved Focus on enter/escape to Add Button - altered some background and foreground colors
This commit is contained in:
+27
-7
@@ -15,7 +15,8 @@
|
|||||||
ExtendClientAreaToDecorationsHint="True"
|
ExtendClientAreaToDecorationsHint="True"
|
||||||
CanResize="False"
|
CanResize="False"
|
||||||
Topmost="True"
|
Topmost="True"
|
||||||
Title="SimpleNote">
|
Title="SimpleNote"
|
||||||
|
>
|
||||||
<Window.Styles>
|
<Window.Styles>
|
||||||
<Style Selector="TextBox">
|
<Style Selector="TextBox">
|
||||||
<Style Selector="^:focus">
|
<Style Selector="^:focus">
|
||||||
@@ -32,7 +33,7 @@
|
|||||||
</Style>
|
</Style>
|
||||||
</Style>
|
</Style>
|
||||||
</Window.Styles>
|
</Window.Styles>
|
||||||
<!--<Border CornerRadius="15" BorderBrush="White" BorderThickness="2" Background="#000000aa">-->
|
<!-- <Border CornerRadius="7.5" BorderBrush="rgba(128, 128, 128, 0.6)" BorderThickness="2" Background="rgba(128, 128, 128, 0.3)"> -->
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<ExperimentalAcrylicBorder IsHitTestVisible="False">
|
<ExperimentalAcrylicBorder IsHitTestVisible="False">
|
||||||
<ExperimentalAcrylicBorder.Material>
|
<ExperimentalAcrylicBorder.Material>
|
||||||
@@ -44,7 +45,13 @@
|
|||||||
</ExperimentalAcrylicBorder.Material>
|
</ExperimentalAcrylicBorder.Material>
|
||||||
</ExperimentalAcrylicBorder>
|
</ExperimentalAcrylicBorder>
|
||||||
<TextBox x:Name="FocusBox" IsVisible="False"/>
|
<TextBox x:Name="FocusBox" IsVisible="False"/>
|
||||||
<Button Margin="5,0" Command="{Binding AddButtonPressedCommand}" FontSize="{Binding FontSize}" Width="40" HorizontalContentAlignment="Center">
|
<Button x:Name="AddButton" Margin="3,0"
|
||||||
|
Command="{Binding AddButtonPressedCommand}"
|
||||||
|
FontSize="{Binding FontSize}"
|
||||||
|
Width="40" HorizontalContentAlignment="Center"
|
||||||
|
Background="rgba(64, 64, 64, 0.6)"
|
||||||
|
Foreground="White"
|
||||||
|
>
|
||||||
+
|
+
|
||||||
</Button>
|
</Button>
|
||||||
<ItemsControl ItemsSource="{Binding Notes}">
|
<ItemsControl ItemsSource="{Binding Notes}">
|
||||||
@@ -55,10 +62,15 @@
|
|||||||
</ItemsControl.ItemsPanel>
|
</ItemsControl.ItemsPanel>
|
||||||
<ItemsControl.ItemTemplate>
|
<ItemsControl.ItemTemplate>
|
||||||
<DataTemplate x:DataType="vm:Note">
|
<DataTemplate x:DataType="vm:Note">
|
||||||
<Border CornerRadius="7.5" Margin="5,5,0,5" BorderBrush="Gray" BorderThickness="2" Background="Transparent">
|
<Border CornerRadius="7.5"
|
||||||
|
Margin="5,5,0,5"
|
||||||
|
BorderBrush="rgba(0, 0, 0, 0.15)"
|
||||||
|
BorderThickness="2"
|
||||||
|
Background="rgba(64, 64, 64, 0.3)"
|
||||||
|
>
|
||||||
<StackPanel Margin="5" Background="Transparent" Orientation="Horizontal">
|
<StackPanel Margin="5" Background="Transparent" Orientation="Horizontal">
|
||||||
<TextBox Height="20"
|
<TextBox Height="20"
|
||||||
CaretBrush="Transparent"
|
CaretBrush="White"
|
||||||
BorderThickness="0"
|
BorderThickness="0"
|
||||||
Width="{Binding Width}"
|
Width="{Binding Width}"
|
||||||
TextChanged="TextBox_OnTextChanged"
|
TextChanged="TextBox_OnTextChanged"
|
||||||
@@ -78,7 +90,15 @@
|
|||||||
KeyDown="InputElement_OnKeyDown"
|
KeyDown="InputElement_OnKeyDown"
|
||||||
>
|
>
|
||||||
</TextBox>
|
</TextBox>
|
||||||
<Button Command="{Binding RemoveButtonClicked}" FontSize="{Binding FontSize}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Width="25" Padding="1,-3,0,0" Margin="5,0,0,0">
|
<Button Command="{Binding RemoveButtonClicked}"
|
||||||
|
FontSize="{Binding FontSize}"
|
||||||
|
HorizontalContentAlignment="Center"
|
||||||
|
VerticalContentAlignment="Center"
|
||||||
|
Width="25"
|
||||||
|
Padding="1,-3,0,0"
|
||||||
|
Margin="5,0,0,0"
|
||||||
|
Background="rgba(64, 64, 64, 0.3)"
|
||||||
|
Foreground="White">
|
||||||
x
|
x
|
||||||
</Button>
|
</Button>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
@@ -87,5 +107,5 @@
|
|||||||
</ItemsControl.ItemTemplate>
|
</ItemsControl.ItemTemplate>
|
||||||
</ItemsControl>
|
</ItemsControl>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<!--</Border>-->
|
<!-- </Border> -->
|
||||||
</Window>
|
</Window>
|
||||||
|
|||||||
+16
-33
@@ -1,11 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Linq;
|
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using System.Reactive.Linq;
|
|
||||||
using Avalonia.Input;
|
using Avalonia.Input;
|
||||||
using Avalonia.Interactivity;
|
|
||||||
using Avalonia.Media;
|
using Avalonia.Media;
|
||||||
using Avalonia.Platform;
|
using Avalonia.Platform;
|
||||||
|
|
||||||
@@ -13,8 +9,8 @@ namespace SimpleNote;
|
|||||||
|
|
||||||
public partial class MainWindow : Window
|
public partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
private ViewModel viewModel;
|
private ViewModel _viewModel;
|
||||||
private PixelRect? screen;
|
private PixelRect? _screen;
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
if (Screens.Primary == null)
|
if (Screens.Primary == null)
|
||||||
@@ -25,24 +21,24 @@ public partial class MainWindow : Window
|
|||||||
if (Screens.All[i].Bounds.Width > max.Bounds.Width) max = Screens.All[i];
|
if (Screens.All[i].Bounds.Width > max.Bounds.Width) max = Screens.All[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
screen = max.WorkingArea;
|
_screen = max.WorkingArea;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
screen = Screens.Primary?.WorkingArea;
|
_screen = Screens.Primary?.WorkingArea;
|
||||||
|
|
||||||
if (screen == null)
|
if (_screen == null)
|
||||||
{
|
{
|
||||||
Console.WriteLine("No screen available.");
|
Console.WriteLine("No screen available.");
|
||||||
Environment.Exit(1);
|
Environment.Exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Position = new PixelPoint(screen.Value.Width / 2 - 25, 10);
|
this.Position = new PixelPoint(_screen.Value.Width / 2 - 25, 10);
|
||||||
this.Width = 50;
|
this.Width = 50;
|
||||||
// this.MaxWidth = screen.Value.Width - 100;
|
// this.MaxWidth = screen.Value.Width - 100;
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
viewModel = new ViewModel();
|
_viewModel = new ViewModel();
|
||||||
DataContext = viewModel;
|
DataContext = _viewModel;
|
||||||
|
|
||||||
this.GetObservable(Window.WidthProperty)
|
this.GetObservable(Window.WidthProperty)
|
||||||
.Subscribe(width =>
|
.Subscribe(width =>
|
||||||
@@ -52,22 +48,9 @@ public partial class MainWindow : Window
|
|||||||
vm.WindowWidth = (double)width;
|
vm.WindowWidth = (double)width;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
AddButton.Focus();
|
||||||
public void init_TextField(string text)
|
|
||||||
{
|
|
||||||
var textBlock = new TextBlock
|
|
||||||
{
|
|
||||||
Text = text,
|
|
||||||
FontSize = viewModel.FontSize,
|
|
||||||
FontFamily = new FontFamily(FontFamily.DefaultFontFamilyName)
|
|
||||||
};
|
|
||||||
textBlock.Measure(Size.Infinity);
|
|
||||||
viewModel.WindowWidth = textBlock.DesiredSize.Width + 50;
|
|
||||||
Note.Text = text;
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
public static double TextWidth(string text)
|
public static double TextWidth(string text)
|
||||||
{
|
{
|
||||||
@@ -78,29 +61,29 @@ public partial class MainWindow : Window
|
|||||||
FontFamily = new FontFamily(FontFamily.DefaultFontFamilyName)
|
FontFamily = new FontFamily(FontFamily.DefaultFontFamilyName)
|
||||||
};
|
};
|
||||||
textBlock.Measure(Size.Infinity);
|
textBlock.Measure(Size.Infinity);
|
||||||
return textBlock.DesiredSize.Width + 30 < 60 ? 60 : textBlock.DesiredSize.Width + 30;
|
return textBlock.DesiredSize.Width + 30 < 60 ? 60 : (textBlock.DesiredSize.Width + 30) * 1.05;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void TextBox_OnTextChanged(object? sender, TextChangedEventArgs e)
|
private void TextBox_OnTextChanged(object? sender, TextChangedEventArgs e)
|
||||||
{
|
{
|
||||||
if (sender == null) return;
|
if (sender == null) return;
|
||||||
((TextBox)sender).Width = TextWidth(((TextBox)sender).Text);
|
((TextBox)sender).Width = TextWidth(((TextBox)sender).Text ?? "");
|
||||||
double width = 55;
|
double width = 55;
|
||||||
foreach (var note in viewModel.Notes)
|
foreach (var note in _viewModel.Notes)
|
||||||
{
|
{
|
||||||
width += note.Width + 49;
|
width += note.Width + 49;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (width == 55) width -= 5;
|
if ((int)width == 55) width -= 5;
|
||||||
|
|
||||||
this.Width = width;
|
this.Width = width;
|
||||||
if(!System.OperatingSystem.IsLinux()) // Screenpositionhandling on Hyprland/Wayland/X11 is different
|
if(!System.OperatingSystem.IsLinux()) // Screenpositionhandling on Hyprland/Wayland/X11 is different
|
||||||
this.Position = new PixelPoint((int)((screen.Value.Width - width) / 2), 10);
|
this.Position = new PixelPoint((int)((_screen.Value.Width - width) / 2), 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InputElement_OnKeyDown(object? sender, KeyEventArgs e)
|
private void InputElement_OnKeyDown(object? sender, KeyEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Key == Key.Enter)
|
if (e.Key == Key.Enter || e.Key == Key.Escape)
|
||||||
this.Focus();
|
AddButton.Focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -2,6 +2,7 @@ using System;
|
|||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
using Avalonia.Controls;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
@@ -13,6 +14,7 @@ public class ViewModel : ObservableObject
|
|||||||
private double _windowWidth = 200;
|
private double _windowWidth = 200;
|
||||||
public static double _fontSize = 20;
|
public static double _fontSize = 20;
|
||||||
private double _noteWidth;
|
private double _noteWidth;
|
||||||
|
public object? LastFocusedNote;
|
||||||
|
|
||||||
public ObservableCollection<Note> Notes { get; set; } = new ObservableCollection<Note>();
|
public ObservableCollection<Note> Notes { get; set; } = new ObservableCollection<Note>();
|
||||||
public ICommand AddButtonPressedCommand { get; }
|
public ICommand AddButtonPressedCommand { get; }
|
||||||
@@ -42,7 +44,6 @@ public class ViewModel : ObservableObject
|
|||||||
|
|
||||||
private void AddButtonPressedCommandEvent(object? sender)
|
private void AddButtonPressedCommandEvent(object? sender)
|
||||||
{
|
{
|
||||||
// TODO: generate new Note
|
|
||||||
AddNote();
|
AddNote();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user