Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Feb 14, 2025
1 parent 3f800c7 commit 2bf587c
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions JL.Windows/Utilities/WindowsUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -489,31 +489,45 @@ public static Size MeasureTextSize(string text, double fontSize)

public static void ShowColorPicker(Button button)
{
using ColorPicker picker = SingleOpenHelper.CreateControl<ColorPicker>();
ColorPicker picker = SingleOpenHelper.CreateControl<ColorPicker>();
HandyControl.Controls.PopupWindow window = new()
{
PopupElement = picker,
WindowStartupLocation = WindowStartupLocation.CenterScreen
};

picker.SelectedBrush = (SolidColorBrush)button.Tag;
picker.Tag = (window, button);
picker.Canceled += ColorPicker_Cancelled;
picker.Confirmed += ColorPicker_Confirmed;

picker.Canceled += delegate
{
window.Close();
};
window.ShowDialog(picker, false);
}

picker.Confirmed += delegate
private static void ColorPicker_Cancelled(object? sender, EventArgs e)
{
if (sender is not ColorPicker colorPicker)
{
ConfirmColor(button, picker.SelectedBrush, window);
};
return;
}

window.ShowDialog(picker, false);
(HandyControl.Controls.PopupWindow window, _) = ((HandyControl.Controls.PopupWindow, Button))colorPicker.Tag;

window.Close();
colorPicker.Dispose();
}

private static void ConfirmColor(Button button, Brush selectedBrush, Window window)
private static void ColorPicker_Confirmed(object? sender, FunctionEventArgs<Color> e)
{
SetButtonColor(button, selectedBrush);
if (sender is not ColorPicker colorPicker)
{
return;
}

(HandyControl.Controls.PopupWindow window, Button button) = ((HandyControl.Controls.PopupWindow, Button))colorPicker.Tag;
SetButtonColor(button, colorPicker.SelectedBrush);
window.Close();
colorPicker.Dispose();
}

public static void SetButtonColor(Button button, Brush selectedBrush)
Expand Down

0 comments on commit 2bf587c

Please sign in to comment.