Files
Libation/Source/LibationAvalonia/Dialogs/DescriptionDisplayDialog.axaml.cs
Michael Bucari-Tovo 3ab1edc076 Code Cleanup
Make fields readonly
Remove unnecessary casts
Format document
Remove unnecessary usings
Sort usings
Use file-level namespaces
Order modifiers
2026-02-05 12:48:44 -07:00

54 lines
1.6 KiB
C#

using Avalonia;
using Avalonia.Controls;
using System;
using System.Linq;
namespace LibationAvalonia.Dialogs;
public partial class DescriptionDisplayDialog : Window
{
public Point SpawnLocation { get; set; }
public string? DescriptionText { get; init; }
public DescriptionDisplayDialog()
{
InitializeComponent();
DescriptionTextBox = this.FindControl<TextBox>(nameof(DescriptionTextBox));
this.Activated += DescriptionDisplay_Activated;
Opened += DescriptionDisplay_Opened;
}
private void DescriptionDisplay_Opened(object? sender, EventArgs e)
{
DescriptionTextBox.Focus();
}
private void DescriptionDisplay_Activated(object? sender, EventArgs e)
{
DataContext = this;
var workingHeight = (Screens.ScreenFromTopLevel(this) ?? Screens.Primary ?? Screens.All.FirstOrDefault())?.WorkingArea.Height ?? 1080;
DescriptionTextBox.Measure(new Size(DescriptionTextBox.MinWidth, workingHeight * 0.8));
this.Width = DescriptionTextBox.DesiredSize.Width;
this.Height = DescriptionTextBox.DesiredSize.Height;
this.MinWidth = this.Width;
this.MaxWidth = this.Width;
this.MinHeight = this.Height;
this.MaxHeight = this.Height;
DescriptionTextBox.Width = this.Width;
DescriptionTextBox.Height = this.Height;
DescriptionTextBox.MinWidth = this.Width;
DescriptionTextBox.MaxWidth = this.Width;
DescriptionTextBox.MinHeight = this.Height;
DescriptionTextBox.MaxHeight = this.Height;
this.Position = new PixelPoint((int)SpawnLocation.X, (int)Math.Min(SpawnLocation.Y, workingHeight - DescriptionTextBox.DesiredSize.Height));
}
private void DescriptionTextBox_LostFocus(object sender, Avalonia.Interactivity.RoutedEventArgs e)
{
Close();
}
}