mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-06-22 09:14:25 +08:00
0.1.3
This commit is contained in:
@@ -7,7 +7,8 @@
|
|||||||
d:DesignHeight="70"
|
d:DesignHeight="70"
|
||||||
x:Class="LanMontainDesktop.Views.Components.ClockWidget">
|
x:Class="LanMontainDesktop.Views.Components.ClockWidget">
|
||||||
|
|
||||||
<Border Padding="8"
|
<Border x:Name="RootBorder"
|
||||||
|
Padding="8"
|
||||||
CornerRadius="8"
|
CornerRadius="8"
|
||||||
BorderBrush="#80A5B4FC"
|
BorderBrush="#80A5B4FC"
|
||||||
BorderThickness="1"
|
BorderThickness="1"
|
||||||
@@ -15,6 +16,7 @@
|
|||||||
<TextBlock x:Name="TimeTextBlock"
|
<TextBlock x:Name="TimeTextBlock"
|
||||||
HorizontalAlignment="Center"
|
HorizontalAlignment="Center"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
|
TextAlignment="Center"
|
||||||
FontSize="26"
|
FontSize="26"
|
||||||
FontWeight="SemiBold"
|
FontWeight="SemiBold"
|
||||||
Foreground="White" />
|
Foreground="White" />
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using System;
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Media;
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
|
|
||||||
namespace LanMontainDesktop.Views.Components;
|
namespace LanMontainDesktop.Views.Components;
|
||||||
@@ -44,4 +45,15 @@ public partial class ClockWidget : UserControl
|
|||||||
var now = DateTime.Now;
|
var now = DateTime.Now;
|
||||||
TimeTextBlock.Text = now.ToString("HH:mm:ss", CultureInfo.CurrentCulture);
|
TimeTextBlock.Text = now.ToString("HH:mm:ss", CultureInfo.CurrentCulture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ApplyCellSize(double cellSize)
|
||||||
|
{
|
||||||
|
var padding = Math.Clamp(cellSize * 0.12, 2, 14);
|
||||||
|
RootBorder.Padding = new Thickness(padding);
|
||||||
|
RootBorder.CornerRadius = new CornerRadius(Math.Clamp(cellSize * 0.16, 4, 18));
|
||||||
|
|
||||||
|
// Keep the time legible across dense and sparse grid layouts.
|
||||||
|
TimeTextBlock.FontSize = Math.Clamp(cellSize * 0.42, 10, 56);
|
||||||
|
TimeTextBlock.FontWeight = FontWeight.SemiBold;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@
|
|||||||
HorizontalAlignment="Stretch"
|
HorizontalAlignment="Stretch"
|
||||||
VerticalAlignment="Stretch"
|
VerticalAlignment="Stretch"
|
||||||
Click="OnMinimizeClick"
|
Click="OnMinimizeClick"
|
||||||
Content="回到Windows" />
|
Content="回到Windows" />
|
||||||
</Grid>
|
</Grid>
|
||||||
</Border>
|
</Border>
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@
|
|||||||
Grid.Column="0"
|
Grid.Column="0"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Foreground="#FFE5E7EB"
|
Foreground="#FFE5E7EB"
|
||||||
Text="短边格数" />
|
Text="短边格数" />
|
||||||
<ui:NumberBox x:Name="GridSizeNumberBox"
|
<ui:NumberBox x:Name="GridSizeNumberBox"
|
||||||
Grid.Row="0"
|
Grid.Row="0"
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
@@ -76,7 +76,7 @@
|
|||||||
Grid.Column="2"
|
Grid.Column="2"
|
||||||
Padding="12,6"
|
Padding="12,6"
|
||||||
Click="OnApplyGridSizeClick"
|
Click="OnApplyGridSizeClick"
|
||||||
Content="应用" />
|
Content="应用" />
|
||||||
|
|
||||||
<TextBlock x:Name="GridInfoTextBlock"
|
<TextBlock x:Name="GridInfoTextBlock"
|
||||||
Grid.Row="1"
|
Grid.Row="1"
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using System;
|
|||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
|
using Avalonia.Threading;
|
||||||
|
|
||||||
namespace LanMontainDesktop.Views;
|
namespace LanMontainDesktop.Views;
|
||||||
|
|
||||||
@@ -14,6 +15,7 @@ public partial class MainWindow : Window
|
|||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
PropertyChanged += OnWindowPropertyChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnOpened(EventArgs e)
|
protected override void OnOpened(EventArgs e)
|
||||||
@@ -28,6 +30,7 @@ public partial class MainWindow : Window
|
|||||||
|
|
||||||
protected override void OnClosed(EventArgs e)
|
protected override void OnClosed(EventArgs e)
|
||||||
{
|
{
|
||||||
|
PropertyChanged -= OnWindowPropertyChanged;
|
||||||
DesktopHost.SizeChanged -= OnDesktopHostSizeChanged;
|
DesktopHost.SizeChanged -= OnDesktopHostSizeChanged;
|
||||||
base.OnClosed(e);
|
base.OnClosed(e);
|
||||||
}
|
}
|
||||||
@@ -114,12 +117,49 @@ public partial class MainWindow : Window
|
|||||||
Grid.SetRowSpan(BackToWindowsButton, 1);
|
Grid.SetRowSpan(BackToWindowsButton, 1);
|
||||||
Grid.SetColumnSpan(BackToWindowsButton, Math.Min(4, columnCount));
|
Grid.SetColumnSpan(BackToWindowsButton, Math.Min(4, columnCount));
|
||||||
|
|
||||||
|
ApplyWidgetSizing(cellSize);
|
||||||
|
|
||||||
GridInfoTextBlock.Text =
|
GridInfoTextBlock.Text =
|
||||||
$"Grid: {columnCount} cols x {rowCount} rows | cell {cellSize:F1}px (1:1)";
|
$"Grid: {columnCount} cols x {rowCount} rows | cell {cellSize:F1}px (1:1)";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ApplyWidgetSizing(double cellSize)
|
||||||
|
{
|
||||||
|
var margin = Math.Clamp(cellSize * 0.08, 1.5, 10);
|
||||||
|
var verticalPadding = Math.Clamp(cellSize * 0.08, 2, 12);
|
||||||
|
var horizontalPadding = Math.Clamp(cellSize * 0.20, 4, 22);
|
||||||
|
|
||||||
|
ClockWidget.Margin = new Thickness(margin);
|
||||||
|
ClockWidget.ApplyCellSize(cellSize);
|
||||||
|
|
||||||
|
BackToWindowsButton.Margin = new Thickness(margin);
|
||||||
|
BackToWindowsButton.Padding = new Thickness(horizontalPadding, verticalPadding);
|
||||||
|
BackToWindowsButton.FontSize = Math.Clamp(cellSize * 0.30, 8, 30);
|
||||||
|
}
|
||||||
|
|
||||||
private void OnMinimizeClick(object? sender, RoutedEventArgs e)
|
private void OnMinimizeClick(object? sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
WindowState = WindowState.Minimized;
|
WindowState = WindowState.Minimized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnWindowPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Property != WindowStateProperty)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (WindowState is WindowState.Minimized or WindowState.FullScreen)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Dispatcher.UIThread.Post(() =>
|
||||||
|
{
|
||||||
|
if (WindowState is not (WindowState.Minimized or WindowState.FullScreen))
|
||||||
|
{
|
||||||
|
WindowState = WindowState.FullScreen;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user