diff --git a/MainWindow.axaml b/MainWindow.axaml
index ae83ea8..eeebd46 100644
--- a/MainWindow.axaml
+++ b/MainWindow.axaml
@@ -15,7 +15,8 @@
ExtendClientAreaToDecorationsHint="True"
CanResize="False"
Topmost="True"
- Title="SimpleNote">
+ Title="SimpleNote"
+ >
-
+
@@ -44,7 +45,13 @@
-
-
+
diff --git a/MainWindow.axaml.cs b/MainWindow.axaml.cs
index b5e7021..a6ccc2a 100644
--- a/MainWindow.axaml.cs
+++ b/MainWindow.axaml.cs
@@ -1,11 +1,7 @@
using System;
-using System.ComponentModel;
-using System.Linq;
using Avalonia;
using Avalonia.Controls;
-using System.Reactive.Linq;
using Avalonia.Input;
-using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.Platform;
@@ -13,8 +9,8 @@ namespace SimpleNote;
public partial class MainWindow : Window
{
- private ViewModel viewModel;
- private PixelRect? screen;
+ private ViewModel _viewModel;
+ private PixelRect? _screen;
public MainWindow()
{
if (Screens.Primary == null)
@@ -25,25 +21,25 @@ public partial class MainWindow : Window
if (Screens.All[i].Bounds.Width > max.Bounds.Width) max = Screens.All[i];
}
- screen = max.WorkingArea;
+ _screen = max.WorkingArea;
}
else
- screen = Screens.Primary?.WorkingArea;
+ _screen = Screens.Primary?.WorkingArea;
- if (screen == null)
+ if (_screen == null)
{
Console.WriteLine("No screen available.");
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.MaxWidth = screen.Value.Width - 100;
InitializeComponent();
- viewModel = new ViewModel();
- DataContext = viewModel;
-
+ _viewModel = new ViewModel();
+ DataContext = _viewModel;
+
this.GetObservable(Window.WidthProperty)
.Subscribe(width =>
{
@@ -52,23 +48,10 @@ public partial class MainWindow : Window
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)
{
var textBlock = new TextBlock
@@ -78,29 +61,29 @@ public partial class MainWindow : Window
FontFamily = new FontFamily(FontFamily.DefaultFontFamilyName)
};
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)
{
if (sender == null) return;
- ((TextBox)sender).Width = TextWidth(((TextBox)sender).Text);
+ ((TextBox)sender).Width = TextWidth(((TextBox)sender).Text ?? "");
double width = 55;
- foreach (var note in viewModel.Notes)
+ foreach (var note in _viewModel.Notes)
{
width += note.Width + 49;
}
- if (width == 55) width -= 5;
+ if ((int)width == 55) width -= 5;
this.Width = width;
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)
{
- if (e.Key == Key.Enter)
- this.Focus();
+ if (e.Key == Key.Enter || e.Key == Key.Escape)
+ AddButton.Focus();
}
}
diff --git a/ViewModel.cs b/ViewModel.cs
index 3dd31a9..f84136e 100644
--- a/ViewModel.cs
+++ b/ViewModel.cs
@@ -2,6 +2,7 @@ using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Input;
+using Avalonia.Controls;
using Avalonia.Interactivity;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
@@ -13,6 +14,7 @@ public class ViewModel : ObservableObject
private double _windowWidth = 200;
public static double _fontSize = 20;
private double _noteWidth;
+ public object? LastFocusedNote;
public ObservableCollection Notes { get; set; } = new ObservableCollection();
public ICommand AddButtonPressedCommand { get; }
@@ -42,7 +44,6 @@ public class ViewModel : ObservableObject
private void AddButtonPressedCommandEvent(object? sender)
{
- // TODO: generate new Note
AddNote();
}