improve:计时器UI

This commit is contained in:
2025-10-06 16:53:00 +08:00
parent adc2d02fbb
commit 20d5dd2668
2 changed files with 265 additions and 76 deletions
+179 -68
View File
@@ -388,70 +388,11 @@
<Grid HorizontalAlignment="Right" VerticalAlignment="Center"
x:Name="QuickOptionsGrid" Width="350" Margin="30,0,0,0">
<StackPanel Orientation="Vertical" HorizontalAlignment="Center">
<!-- 第一排:5min, 10min -->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,0,0,15">
<Button x:Name="Quick5MinBtn" Width="80" Height="50" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
BorderThickness="0" Click="Quick5Min_Click" Cursor="Hand" Margin="0,0,15,0">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" CornerRadius="8">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Button.Template>
<TextBlock Text="5分钟" FontSize="16" FontWeight="Bold"
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}"/>
</Button>
<Button x:Name="Quick10MinBtn" Width="80" Height="50" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
BorderThickness="0" Click="Quick10Min_Click" Cursor="Hand">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" CornerRadius="8">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Button.Template>
<TextBlock Text="10分钟" FontSize="16" FontWeight="Bold"
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}"/>
</Button>
</StackPanel>
<!-- 第二排:15min, 20min -->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,0,0,15">
<Button x:Name="Quick15MinBtn" Width="80" Height="50" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
BorderThickness="0" Click="Quick15Min_Click" Cursor="Hand" Margin="0,0,15,0">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" CornerRadius="8">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Button.Template>
<TextBlock Text="15分钟" FontSize="16" FontWeight="Bold"
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}"/>
</Button>
<Button x:Name="Quick20MinBtn" Width="80" Height="50" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
BorderThickness="0" Click="Quick20Min_Click" Cursor="Hand">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" CornerRadius="8">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Button.Template>
<TextBlock Text="20分钟" FontSize="16" FontWeight="Bold"
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}"/>
</Button>
</StackPanel>
<!-- 第三排:最近两次计时 -->
<StackPanel Orientation="Vertical" HorizontalAlignment="Center">
<TextBlock Text="最近计时" FontSize="14" FontWeight="Bold"
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}"
HorizontalAlignment="Center" Margin="0,0,0,10"/>
<!-- Tab切换区域 -->
<Grid Margin="0,0,0,20">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button x:Name="RecentTimer1Btn" Width="80" Height="40" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
BorderThickness="0" Click="RecentTimer1_Click" Cursor="Hand" Margin="0,0,10,0">
<Button x:Name="CommonTabBtn" Width="100" Height="35" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
BorderThickness="0" Click="CommonTab_Click" Cursor="Hand" Margin="0,0,10,0">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" CornerRadius="6">
@@ -459,11 +400,11 @@
</Border>
</ControlTemplate>
</Button.Template>
<TextBlock x:Name="RecentTimer1Text" Text="--:--" FontSize="14" FontWeight="Bold"
<TextBlock Text="常用" FontSize="14" FontWeight="Bold"
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}"/>
</Button>
<Button x:Name="RecentTimer2Btn" Width="80" Height="40" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
BorderThickness="0" Click="RecentTimer2_Click" Cursor="Hand">
<Button x:Name="RecentTabBtn" Width="100" Height="35" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
BorderThickness="0" Click="RecentTab_Click" Cursor="Hand">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" CornerRadius="6">
@@ -471,11 +412,181 @@
</Border>
</ControlTemplate>
</Button.Template>
<TextBlock x:Name="RecentTimer2Text" Text="--:--" FontSize="14" FontWeight="Bold"
<TextBlock Text="最近" FontSize="14" FontWeight="Bold"
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}"/>
</Button>
</StackPanel>
</StackPanel>
</Grid>
<!-- 常用计时区域 -->
<Grid x:Name="CommonTimersGrid" Visibility="Visible">
<StackPanel Orientation="Vertical" HorizontalAlignment="Center">
<!-- 第一排:5分钟, 10分钟, 15分钟 -->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,0,0,10">
<Button x:Name="Common5MinBtn" Width="70" Height="40" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
BorderThickness="0" Click="Common5Min_Click" Cursor="Hand" Margin="0,0,8,0">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" CornerRadius="6">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Button.Template>
<TextBlock Text="05:00" FontSize="12" FontWeight="Bold"
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}"/>
</Button>
<Button x:Name="Common10MinBtn" Width="70" Height="40" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
BorderThickness="0" Click="Common10Min_Click" Cursor="Hand" Margin="0,0,8,0">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" CornerRadius="6">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Button.Template>
<TextBlock Text="10:00" FontSize="12" FontWeight="Bold"
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}"/>
</Button>
<Button x:Name="Common15MinBtn" Width="70" Height="40" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
BorderThickness="0" Click="Common15Min_Click" Cursor="Hand">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" CornerRadius="6">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Button.Template>
<TextBlock Text="15:00" FontSize="12" FontWeight="Bold"
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}"/>
</Button>
</StackPanel>
<!-- 第二排:30分钟, 45分钟, 60分钟 -->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button x:Name="Common30MinBtn" Width="70" Height="40" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
BorderThickness="0" Click="Common30Min_Click" Cursor="Hand" Margin="0,0,8,0">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" CornerRadius="6">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Button.Template>
<TextBlock Text="30:00" FontSize="12" FontWeight="Bold"
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}"/>
</Button>
<Button x:Name="Common45MinBtn" Width="70" Height="40" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
BorderThickness="0" Click="Common45Min_Click" Cursor="Hand" Margin="0,0,8,0">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" CornerRadius="6">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Button.Template>
<TextBlock Text="45:00" FontSize="12" FontWeight="Bold"
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}"/>
</Button>
<Button x:Name="Common60MinBtn" Width="70" Height="40" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
BorderThickness="0" Click="Common60Min_Click" Cursor="Hand">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" CornerRadius="6">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Button.Template>
<TextBlock Text="60:00" FontSize="12" FontWeight="Bold"
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}"/>
</Button>
</StackPanel>
</StackPanel>
</Grid>
<!-- 最近计时区域 -->
<Grid x:Name="RecentTimersGrid" Visibility="Collapsed">
<StackPanel Orientation="Vertical" HorizontalAlignment="Center">
<!-- 第一排:最近3个 -->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,0,0,10">
<Button x:Name="RecentTimer1Btn" Width="70" Height="40" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
BorderThickness="0" Click="RecentTimer1_Click" Cursor="Hand" Margin="0,0,8,0">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" CornerRadius="6">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Button.Template>
<TextBlock x:Name="RecentTimer1Text" Text="--:--" FontSize="12" FontWeight="Bold"
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}"/>
</Button>
<Button x:Name="RecentTimer2Btn" Width="70" Height="40" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
BorderThickness="0" Click="RecentTimer2_Click" Cursor="Hand" Margin="0,0,8,0">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" CornerRadius="6">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Button.Template>
<TextBlock x:Name="RecentTimer2Text" Text="--:--" FontSize="12" FontWeight="Bold"
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}"/>
</Button>
<Button x:Name="RecentTimer3Btn" Width="70" Height="40" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
BorderThickness="0" Click="RecentTimer3_Click" Cursor="Hand">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" CornerRadius="6">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Button.Template>
<TextBlock x:Name="RecentTimer3Text" Text="--:--" FontSize="12" FontWeight="Bold"
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}"/>
</Button>
</StackPanel>
<!-- 第二排:最近3个 -->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button x:Name="RecentTimer4Btn" Width="70" Height="40" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
BorderThickness="0" Click="RecentTimer4_Click" Cursor="Hand" Margin="0,0,8,0">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" CornerRadius="6">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Button.Template>
<TextBlock x:Name="RecentTimer4Text" Text="--:--" FontSize="12" FontWeight="Bold"
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}"/>
</Button>
<Button x:Name="RecentTimer5Btn" Width="70" Height="40" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
BorderThickness="0" Click="RecentTimer5_Click" Cursor="Hand" Margin="0,0,8,0">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" CornerRadius="6">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Button.Template>
<TextBlock x:Name="RecentTimer5Text" Text="--:--" FontSize="12" FontWeight="Bold"
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}"/>
</Button>
<Button x:Name="RecentTimer6Btn" Width="70" Height="40" Background="{DynamicResource SeewoTimerWindowButtonBackground}"
BorderThickness="0" Click="RecentTimer6_Click" Cursor="Hand">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" CornerRadius="6">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Button.Template>
<TextBlock x:Name="RecentTimer6Text" Text="--:--" FontSize="12" FontWeight="Bold"
Foreground="{DynamicResource SeewoTimerWindowButtonForeground}"/>
</Button>
</StackPanel>
</StackPanel>
</Grid>
</StackPanel>
</Grid>
</Grid>
@@ -90,10 +90,18 @@ namespace Ink_Canvas
// 最近计时记录
private string recentTimer1 = "--:--";
private string recentTimer2 = "--:--";
private string recentTimer3 = "--:--";
private string recentTimer4 = "--:--";
private string recentTimer5 = "--:--";
private string recentTimer6 = "--:--";
// 最近计时记录的注册表键名
private const string RecentTimer1Key = "SeewoTimer_RecentTimer1";
private const string RecentTimer2Key = "SeewoTimer_RecentTimer2";
private const string RecentTimer3Key = "SeewoTimer_RecentTimer3";
private const string RecentTimer4Key = "SeewoTimer_RecentTimer4";
private const string RecentTimer5Key = "SeewoTimer_RecentTimer5";
private const string RecentTimer6Key = "SeewoTimer_RecentTimer6";
private void InitializeUI()
{
@@ -553,31 +561,57 @@ namespace Ink_Canvas
DragMove();
}
// 快捷选项事件处理
private void Quick5Min_Click(object sender, RoutedEventArgs e)
// Tab切换事件处理
private void CommonTab_Click(object sender, RoutedEventArgs e)
{
CommonTimersGrid.Visibility = Visibility.Visible;
RecentTimersGrid.Visibility = Visibility.Collapsed;
}
private void RecentTab_Click(object sender, RoutedEventArgs e)
{
CommonTimersGrid.Visibility = Visibility.Collapsed;
RecentTimersGrid.Visibility = Visibility.Visible;
}
// 常用计时事件处理
private void Common5Min_Click(object sender, RoutedEventArgs e)
{
if (isTimerRunning && !isPaused) return;
SetQuickTime(0, 5, 0);
}
private void Quick10Min_Click(object sender, RoutedEventArgs e)
private void Common10Min_Click(object sender, RoutedEventArgs e)
{
if (isTimerRunning && !isPaused) return;
SetQuickTime(0, 10, 0);
}
private void Quick15Min_Click(object sender, RoutedEventArgs e)
private void Common15Min_Click(object sender, RoutedEventArgs e)
{
if (isTimerRunning && !isPaused) return;
SetQuickTime(0, 15, 0);
}
private void Quick20Min_Click(object sender, RoutedEventArgs e)
private void Common30Min_Click(object sender, RoutedEventArgs e)
{
if (isTimerRunning && !isPaused) return;
SetQuickTime(0, 20, 0);
SetQuickTime(0, 30, 0);
}
private void Common45Min_Click(object sender, RoutedEventArgs e)
{
if (isTimerRunning && !isPaused) return;
SetQuickTime(0, 45, 0);
}
private void Common60Min_Click(object sender, RoutedEventArgs e)
{
if (isTimerRunning && !isPaused) return;
SetQuickTime(1, 0, 0);
}
// 最近计时事件处理
private void RecentTimer1_Click(object sender, RoutedEventArgs e)
{
if ((isTimerRunning && !isPaused) || recentTimer1 == "--:--") return;
@@ -590,6 +624,30 @@ namespace Ink_Canvas
ApplyRecentTimer(recentTimer2);
}
private void RecentTimer3_Click(object sender, RoutedEventArgs e)
{
if ((isTimerRunning && !isPaused) || recentTimer3 == "--:--") return;
ApplyRecentTimer(recentTimer3);
}
private void RecentTimer4_Click(object sender, RoutedEventArgs e)
{
if ((isTimerRunning && !isPaused) || recentTimer4 == "--:--") return;
ApplyRecentTimer(recentTimer4);
}
private void RecentTimer5_Click(object sender, RoutedEventArgs e)
{
if ((isTimerRunning && !isPaused) || recentTimer5 == "--:--") return;
ApplyRecentTimer(recentTimer5);
}
private void RecentTimer6_Click(object sender, RoutedEventArgs e)
{
if ((isTimerRunning && !isPaused) || recentTimer6 == "--:--") return;
ApplyRecentTimer(recentTimer6);
}
// 设置快捷时间
private void SetQuickTime(int h, int m, int s)
{
@@ -630,11 +688,15 @@ namespace Ink_Canvas
// 如果当前时间与最近记录不同,则更新
if (currentTime != recentTimer1)
{
// 向后移动所有记录
recentTimer6 = recentTimer5;
recentTimer5 = recentTimer4;
recentTimer4 = recentTimer3;
recentTimer3 = recentTimer2;
recentTimer2 = recentTimer1;
recentTimer1 = currentTime;
UpdateRecentTimerDisplays();
// 保存到注册表
SaveRecentTimersToRegistry();
}
}
@@ -646,6 +708,10 @@ namespace Ink_Canvas
{
RecentTimer1Text.Text = recentTimer1;
RecentTimer2Text.Text = recentTimer2;
RecentTimer3Text.Text = recentTimer3;
RecentTimer4Text.Text = recentTimer4;
RecentTimer5Text.Text = recentTimer5;
RecentTimer6Text.Text = recentTimer6;
}
catch
{
@@ -664,6 +730,10 @@ namespace Ink_Canvas
{
recentTimer1 = key.GetValue(RecentTimer1Key, "--:--")?.ToString() ?? "--:--";
recentTimer2 = key.GetValue(RecentTimer2Key, "--:--")?.ToString() ?? "--:--";
recentTimer3 = key.GetValue(RecentTimer3Key, "--:--")?.ToString() ?? "--:--";
recentTimer4 = key.GetValue(RecentTimer4Key, "--:--")?.ToString() ?? "--:--";
recentTimer5 = key.GetValue(RecentTimer5Key, "--:--")?.ToString() ?? "--:--";
recentTimer6 = key.GetValue(RecentTimer6Key, "--:--")?.ToString() ?? "--:--";
}
}
}
@@ -672,6 +742,10 @@ namespace Ink_Canvas
// 如果读取注册表失败,使用默认值
recentTimer1 = "--:--";
recentTimer2 = "--:--";
recentTimer3 = "--:--";
recentTimer4 = "--:--";
recentTimer5 = "--:--";
recentTimer6 = "--:--";
}
}
@@ -686,6 +760,10 @@ namespace Ink_Canvas
{
key.SetValue(RecentTimer1Key, recentTimer1);
key.SetValue(RecentTimer2Key, recentTimer2);
key.SetValue(RecentTimer3Key, recentTimer3);
key.SetValue(RecentTimer4Key, recentTimer4);
key.SetValue(RecentTimer5Key, recentTimer5);
key.SetValue(RecentTimer6Key, recentTimer6);
}
}
}