feat: add color pair picker

This commit is contained in:
2025-09-08 15:55:37 +08:00
parent d217a0e6d4
commit 81c46ea0f2
6 changed files with 133 additions and 13 deletions

View File

@ -25,7 +25,7 @@
<TextBox Text="{Binding Name, Mode=TwoWay}" Width="200" HorizontalAlignment="Left" Padding="5" Margin="0,5,0,0"/> <TextBox Text="{Binding Name, Mode=TwoWay}" Width="200" HorizontalAlignment="Left" Padding="5" Margin="0,5,0,0"/>
<TextBlock Text="课程颜色" FontWeight="Bold" Padding="5" Margin="0,10,0,0"/> <TextBlock Text="课程颜色" FontWeight="Bold" Padding="5" Margin="0,10,0,0"/>
<Border x:Name="uiColorPicker" ToolTip="左键单击改变背景色,右键单击改变前景色" Width="200" HorizontalAlignment="Left" BorderBrush="Black" BorderThickness="1" Cursor="Hand" Margin="0,5,0,0" MouseLeftButtonDown="uiColorPicker_MouseLeftButtonDown" MouseRightButtonDown="uiColorPicker_MouseRightButtonDown"> <Border x:Name="uiColorPicker" Width="200" HorizontalAlignment="Left" BorderBrush="Black" BorderThickness="1" Cursor="Hand" Margin="0,5,0,0" MouseDown="uiColorPicker_MouseDown">
<Border.Background> <Border.Background>
<SolidColorBrush Color="{Binding Color.Background, Mode=TwoWay}"/> <SolidColorBrush Color="{Binding Color.Background, Mode=TwoWay}"/>
</Border.Background> </Border.Background>

View File

@ -85,16 +85,10 @@ namespace HFUTCourseSimulation.Dialog {
CurrentCourse.Schedules.Clear(); CurrentCourse.Schedules.Clear();
} }
private void uiColorPicker_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { private void uiColorPicker_MouseDown(object sender, MouseButtonEventArgs e) {
var color = Util.Win32Dialog.PickColor(); var widget = new Widget.ColorPicker();
if (color is null) return; widget.CurrentColor = CurrentCourse.Color;
else CurrentCourse.Color.Background = color.Value; widget.ShowDialog();
}
private void uiColorPicker_MouseRightButtonDown(object sender, MouseButtonEventArgs e) {
var color = Util.Win32Dialog.PickColor();
if (color is null) return;
else CurrentCourse.Color.Foreground = color.Value;
} }
} }

View File

@ -96,6 +96,9 @@
<Compile Include="Util\ColorTrans.cs" /> <Compile Include="Util\ColorTrans.cs" />
<Compile Include="Util\WeekNames.cs" /> <Compile Include="Util\WeekNames.cs" />
<Compile Include="Util\Win32Dialog.cs" /> <Compile Include="Util\Win32Dialog.cs" />
<Compile Include="Widget\ColorPicker.xaml.cs">
<DependentUpon>ColorPicker.xaml</DependentUpon>
</Compile>
<Compile Include="Widget\LogChecker.xaml.cs"> <Compile Include="Widget\LogChecker.xaml.cs">
<DependentUpon>LogChecker.xaml</DependentUpon> <DependentUpon>LogChecker.xaml</DependentUpon>
</Compile> </Compile>
@ -123,6 +126,10 @@
<DependentUpon>MainWindow.xaml</DependentUpon> <DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Page Include="Widget\ColorPicker.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Widget\LogChecker.xaml"> <Page Include="Widget\LogChecker.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>

View File

@ -0,0 +1,59 @@
<Window x:Class="HFUTCourseSimulation.Widget.ColorPicker"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:HFUTCourseSimulation.Widget"
xmlns:uidata="clr-namespace:HFUTCourseSimulation.Kernel.Data.Ui"
mc:Ignorable="d"
x:Name="uiMainWindow"
Title="颜色选择器" Height="500" Width="400" WindowStyle="ToolWindow" Closed="uiMainWindow_Closed" Loaded="uiMainWindow_Loaded">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Grid x:Name="uiPicker" d:DataContext="{d:DesignInstance uidata:ColorPair}" Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<TextBlock Text="背景色" Grid.Column="0" Grid.Row="0" Padding="5" Margin="5"/>
<Border x:Name="uiBackgroundPicker" BorderBrush="Black" BorderThickness="1" Cursor="Hand" Grid.Column="0" Grid.Row="1" Height="30" Padding="5" Margin="5" MouseDown="uiBackgroundPicker_MouseDown">
<Border.Background>
<SolidColorBrush Color="{Binding Background, Mode=TwoWay}"/>
</Border.Background>
</Border>
<TextBlock Text="前景色" Grid.Column="1" Grid.Row="0" Padding="5" Margin="5"/>
<Border x:Name="uiForegroundPicker" BorderBrush="Black" BorderThickness="1" Cursor="Hand" Grid.Column="1" Grid.Row="1" Height="30" Padding="5" Margin="5" MouseDown="uiForegroundPicker_MouseDown">
<Border.Background>
<SolidColorBrush Color="{Binding Foreground, Mode=TwoWay}"/>
</Border.Background>
</Border>
</Grid>
<TabControl Grid.Row="1" Margin="5">
<TabItem Header="Material Design" Padding="5">
<WrapPanel Orientation="Horizontal">
</WrapPanel>
</TabItem>
<TabItem Header="Flat UI" Padding="5"/>
<TabItem Header="Fluent" Padding="5"/>
<TabItem Header="Tailwind" Padding="5"/>
</TabControl>
<StackPanel Orientation="Horizontal" Grid.Row="2" HorizontalAlignment="Center">
<Button x:Name="uiBtnOk" Content="确认" Padding="5" Margin="5" Width="100" IsDefault="True" Click="uiBtnOk_Click"/>
<Button x:Name="uiBtnCancel" Content="取消" Padding="5" Margin="5" Width="100" Click="uiBtnCancel_Click"/>
</StackPanel>
</Grid>
</Window>

View File

@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace HFUTCourseSimulation.Widget {
/// <summary>
/// Interaction logic for ColorPicker.xaml
/// </summary>
public partial class ColorPicker : Window {
public ColorPicker() {
InitializeComponent();
}
public Kernel.Data.Ui.ColorPair CurrentColor { get; set; }
private Color _foregroundBackup, _backgroundBackup;
private void uiMainWindow_Loaded(object sender, RoutedEventArgs e) {
// Set context and backup color for restoring
uiPicker.DataContext = CurrentColor;
_foregroundBackup = CurrentColor.Foreground;
_backgroundBackup = CurrentColor.Background;
}
private void uiMainWindow_Closed(object sender, EventArgs e) {
uiPicker.DataContext = null;
}
private void uiForegroundPicker_MouseDown(object sender, MouseButtonEventArgs e) {
var color = Util.Win32Dialog.PickColor();
if (color is null) return;
else CurrentColor.Foreground = color.Value;
}
private void uiBackgroundPicker_MouseDown(object sender, MouseButtonEventArgs e) {
var color = Util.Win32Dialog.PickColor();
if (color is null) return;
else CurrentColor.Background = color.Value;
}
private void uiBtnOk_Click(object sender, RoutedEventArgs e) {
this.Close();
}
private void uiBtnCancel_Click(object sender, RoutedEventArgs e) {
// Restore and quit
CurrentColor.Foreground = _foregroundBackup;
CurrentColor.Background = _backgroundBackup;
this.Close();
}
}
}

View File

@ -7,7 +7,7 @@
xmlns:uidata="clr-namespace:HFUTCourseSimulation.Kernel" xmlns:uidata="clr-namespace:HFUTCourseSimulation.Kernel"
mc:Ignorable="d" mc:Ignorable="d"
x:Name="uiMainWindow" x:Name="uiMainWindow"
Title="检查器日志" Height="500" Width="400" Closed="uiMainWindow_Closed" Loaded="uiMainWindow_Loaded"> Title="检查器日志" Height="500" Width="400" WindowStyle="ToolWindow" Closed="uiMainWindow_Closed" Loaded="uiMainWindow_Loaded">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="auto"/> <RowDefinition Height="auto"/>
@ -32,6 +32,6 @@
</ListBox.ItemTemplate> </ListBox.ItemTemplate>
</ListBox> </ListBox>
<Button x:Name="uiBtnOk" Content="确认" Grid.Row="2" Width="100" Padding="5" Margin="5" HorizontalAlignment="Right" Click="uiBtnOk_Click"/> <Button x:Name="uiBtnOk" Content="确认" IsDefault="True" Grid.Row="2" Width="100" Padding="5" Margin="5" HorizontalAlignment="Right" Click="uiBtnOk_Click"/>
</Grid> </Grid>
</Window> </Window>