diff --git a/src/TrackerCouncil.Smz3.UI/ViewModels/TrackerWindowViewModel.cs b/src/TrackerCouncil.Smz3.UI/ViewModels/TrackerWindowViewModel.cs index d411f7df6..c5c9cca0d 100644 --- a/src/TrackerCouncil.Smz3.UI/ViewModels/TrackerWindowViewModel.cs +++ b/src/TrackerCouncil.Smz3.UI/ViewModels/TrackerWindowViewModel.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Avalonia.Media; using AvaloniaControls.Models; using Material.Icons; @@ -58,6 +59,10 @@ public class TrackerWindowViewModel : ViewModelBase public bool VoiceEnabled { get; set; } public bool DisplayTimer { get; set; } + public int IdealWindowWidth => Panels.Max(x => x.Column) * 34 + 10; + public int IdealWindowHeight => Panels.Max(x => x.Row) * 34 + 10 + 50; + [Reactive] public bool ShowResizeButton { get; set; } + public string SpeechToolTip => VoiceEnabled ? "Confidence of last recognized voice command. Double click to disable voice recognition." : "Voice recognition disabled. Double click to attempt to enable voice recognition."; public MaterialIconKind SpeechIcon => VoiceEnabled ? MaterialIconKind.Microphone : MaterialIconKind.MicOff; diff --git a/src/TrackerCouncil.Smz3.UI/Views/TrackerWindow.axaml b/src/TrackerCouncil.Smz3.UI/Views/TrackerWindow.axaml index a20f7ea66..34d069a0d 100644 --- a/src/TrackerCouncil.Smz3.UI/Views/TrackerWindow.axaml +++ b/src/TrackerCouncil.Smz3.UI/Views/TrackerWindow.axaml @@ -11,40 +11,51 @@ Title="Tracker — SMZ3 Cas' Randomizer" Loaded="Control_OnLoaded" Closing="Window_OnClosing" + Resized="WindowBase_OnResized" Icon="/Assets/smz3.ico"> - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + Resize to Fit + + + + + diff --git a/src/TrackerCouncil.Smz3.UI/Views/TrackerWindow.axaml.cs b/src/TrackerCouncil.Smz3.UI/Views/TrackerWindow.axaml.cs index 4bc820a5f..663443d2c 100644 --- a/src/TrackerCouncil.Smz3.UI/Views/TrackerWindow.axaml.cs +++ b/src/TrackerCouncil.Smz3.UI/Views/TrackerWindow.axaml.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using Avalonia; using Avalonia.Controls; using Avalonia.Input; @@ -110,6 +111,14 @@ private void LayoutMenuItemOnClick(object? sender, RoutedEventArgs e) ITaskService.Run(() => { _service?.SetLayout(layout); + + Dispatcher.UIThread.Invoke(() => + { + if (Math.Abs(Width - _model.IdealWindowWidth) > 1 || Math.Abs(Height - _model.IdealWindowHeight) > 1) + { + _model.ShowResizeButton = true; + } + }); }); } @@ -152,6 +161,11 @@ private void Control_OnLoaded(object? sender, RoutedEventArgs e) }, DispatcherPriority.Background); }); + if (Math.Abs(Width - _model.IdealWindowWidth) > 1 || Math.Abs(Height - _model.IdealWindowHeight) > 1) + { + _model.ShowResizeButton = true; + } + _parentWindow?.Hide(); } @@ -270,5 +284,24 @@ private void SpeechRecognition_OnPointerPressed(object? sender, PointerPressedEv _service?.ToggleSpeechRecognition(); } } + + private void ResizeWindowButton_OnClick(object? sender, RoutedEventArgs e) + { + Width = _model.IdealWindowWidth; + Height = _model.IdealWindowHeight; + _model.ShowResizeButton = false; + } + + private void WindowBase_OnResized(object? sender, WindowResizedEventArgs e) + { + if (Math.Abs(Width - _model.IdealWindowWidth) > 1 || Math.Abs(Height - _model.IdealWindowHeight) > 1) + { + _model.ShowResizeButton = true; + } + else + { + _model.ShowResizeButton = false; + } + } }