From 0daaa854b7d95e8b03b027a43ee615981a0d7e21 Mon Sep 17 00:00:00 2001 From: Ano-sys Date: Wed, 12 Feb 2025 14:55:57 +0100 Subject: [PATCH] Initial push --- App.axaml | 10 ++++++ App.axaml.cs | 23 ++++++++++++++ MainWindow.axaml | 56 +++++++++++++++++++++++++++++++++ MainWindow.axaml.cs | 76 +++++++++++++++++++++++++++++++++++++++++++++ Program.cs | 21 +++++++++++++ SimpleNote.csproj | 20 ++++++++++++ app.manifest | 18 +++++++++++ 7 files changed, 224 insertions(+) create mode 100644 App.axaml create mode 100644 App.axaml.cs create mode 100644 MainWindow.axaml create mode 100644 MainWindow.axaml.cs create mode 100644 Program.cs create mode 100644 SimpleNote.csproj create mode 100644 app.manifest diff --git a/App.axaml b/App.axaml new file mode 100644 index 0000000..8f90d5d --- /dev/null +++ b/App.axaml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/App.axaml.cs b/App.axaml.cs new file mode 100644 index 0000000..18f6d8a --- /dev/null +++ b/App.axaml.cs @@ -0,0 +1,23 @@ +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Markup.Xaml; +using System; + +namespace SimpleNote; + +public partial class App : Application +{ + public override void Initialize() + { + AvaloniaXamlLoader.Load(this); + } + + public override void OnFrameworkInitializationCompleted() + { + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + desktop.MainWindow = new MainWindow(desktop.Args); + } + base.OnFrameworkInitializationCompleted(); + } +} \ No newline at end of file diff --git a/MainWindow.axaml b/MainWindow.axaml new file mode 100644 index 0000000..0b0c2a6 --- /dev/null +++ b/MainWindow.axaml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + diff --git a/MainWindow.axaml.cs b/MainWindow.axaml.cs new file mode 100644 index 0000000..fb3b1fe --- /dev/null +++ b/MainWindow.axaml.cs @@ -0,0 +1,76 @@ +using System; +using System.ComponentModel; +using Avalonia; +using Avalonia.Controls; +using System.Reactive.Linq; +using Avalonia.Media; + +namespace SimpleNote; + +public partial class MainWindow : Window +{ + private MainViewModel ViewModel; + public MainWindow(string[]? args) + { + if (args == null || args.Length < 1) + { + Console.WriteLine("Call with Note as Argument!"); + Environment.Exit(1); + } + InitializeComponent(); + ViewModel = new MainViewModel(); + DataContext = ViewModel; + + this.GetObservable(Window.WidthProperty) + .Subscribe(width => + { + if (DataContext is MainViewModel vm) + { + vm.WindowWidth = (double)width; + } + }); + + init_TextField(args[0]); + } + + 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 class MainViewModel : INotifyPropertyChanged +{ + private double _windowWidth = 200; + private double _fontSize = 24; + + public double WindowWidth + { + get => _windowWidth; + set + { + _windowWidth = value; + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(WindowWidth))); + } + } + + public double FontSize + { + get => _fontSize; + set + { + _fontSize = value; + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(FontSize))); + } + } + + public event PropertyChangedEventHandler? PropertyChanged; +} \ No newline at end of file diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..792b580 --- /dev/null +++ b/Program.cs @@ -0,0 +1,21 @@ +using Avalonia; +using System; + +namespace SimpleNote; + +class Program +{ + // Initialization code. Don't use any Avalonia, third-party APIs or any + // SynchronizationContext-reliant code before AppMain is called: things aren't initialized + // yet and stuff might break. + [STAThread] + public static void Main(string[] args) => BuildAvaloniaApp() + .StartWithClassicDesktopLifetime(args); + + // Avalonia configuration, don't remove; also used by visual designer. + public static AppBuilder BuildAvaloniaApp() + => AppBuilder.Configure() + .UsePlatformDetect() + .WithInterFont() + .LogToTrace(); +} diff --git a/SimpleNote.csproj b/SimpleNote.csproj new file mode 100644 index 0000000..0c9baa2 --- /dev/null +++ b/SimpleNote.csproj @@ -0,0 +1,20 @@ + + + WinExe + net9.0 + enable + true + app.manifest + true + + + + + + + + + + + + diff --git a/app.manifest b/app.manifest new file mode 100644 index 0000000..3f2443b --- /dev/null +++ b/app.manifest @@ -0,0 +1,18 @@ + + + + + + + + + + + + + +