Coerce property values
This commit is contained in:
Родитель
610ccc6663
Коммит
118c594109
|
@ -6,7 +6,12 @@ namespace ThemeEditor.Controls.ColorPicker.Props;
|
|||
public class AlphaProperties : ColorPickerProperties
|
||||
{
|
||||
public static readonly StyledProperty<double> AlphaProperty =
|
||||
AvaloniaProperty.Register<AlphaProperties, double>(nameof(Alpha), 100.0, validate: ValidateAlpha);
|
||||
AvaloniaProperty.Register<AlphaProperties, double>(nameof(Alpha), 100.0, validate: ValidateAlpha, coerce: CoerceAlpha);
|
||||
|
||||
private static double CoerceAlpha(IAvaloniaObject arg1, double arg2)
|
||||
{
|
||||
return ColorPickerHelpers.Clamp(arg2, 0.0, 100.0);
|
||||
}
|
||||
|
||||
private static bool ValidateAlpha(double alpha)
|
||||
{
|
||||
|
|
|
@ -7,16 +7,36 @@ namespace ThemeEditor.Controls.ColorPicker.Props;
|
|||
public class CmykProperties : ColorPickerProperties
|
||||
{
|
||||
public static readonly StyledProperty<double> CyanProperty =
|
||||
AvaloniaProperty.Register<CmykProperties, double>(nameof(Cyan), 0.0, validate: ValidateCyan);
|
||||
AvaloniaProperty.Register<CmykProperties, double>(nameof(Cyan), 0.0, validate: ValidateCyan, coerce: CoerceCyan);
|
||||
|
||||
public static readonly StyledProperty<double> MagentaProperty =
|
||||
AvaloniaProperty.Register<CmykProperties, double>(nameof(Magenta), 100.0, validate: ValidateMagenta);
|
||||
AvaloniaProperty.Register<CmykProperties, double>(nameof(Magenta), 100.0, validate: ValidateMagenta, coerce: CoerceMagenta);
|
||||
|
||||
public static readonly StyledProperty<double> YellowProperty =
|
||||
AvaloniaProperty.Register<CmykProperties, double>(nameof(Yellow), 100.0, validate: ValidateYellow);
|
||||
AvaloniaProperty.Register<CmykProperties, double>(nameof(Yellow), 100.0, validate: ValidateYellow, coerce: CoerceYellow);
|
||||
|
||||
public static readonly StyledProperty<double> BlackKeyProperty =
|
||||
AvaloniaProperty.Register<CmykProperties, double>(nameof(BlackKey), 0.0, validate: ValidateBlackKey);
|
||||
AvaloniaProperty.Register<CmykProperties, double>(nameof(BlackKey), 0.0, validate: ValidateBlackKey, coerce: CoerceBlackKey);
|
||||
|
||||
private static double CoerceCyan(IAvaloniaObject arg1, double arg2)
|
||||
{
|
||||
return ColorPickerHelpers.Clamp(arg2, 0.0, 100.0);
|
||||
}
|
||||
|
||||
private static double CoerceMagenta(IAvaloniaObject arg1, double arg2)
|
||||
{
|
||||
return ColorPickerHelpers.Clamp(arg2, 0.0, 100.0);
|
||||
}
|
||||
|
||||
private static double CoerceYellow(IAvaloniaObject arg1, double arg2)
|
||||
{
|
||||
return ColorPickerHelpers.Clamp(arg2, 0.0, 100.0);
|
||||
}
|
||||
|
||||
private static double CoerceBlackKey(IAvaloniaObject arg1, double arg2)
|
||||
{
|
||||
return ColorPickerHelpers.Clamp(arg2, 0.0, 100.0);
|
||||
}
|
||||
|
||||
private static bool ValidateCyan(double cyan)
|
||||
{
|
||||
|
|
|
@ -7,7 +7,12 @@ namespace ThemeEditor.Controls.ColorPicker.Props;
|
|||
public class HexProperties : ColorPickerProperties
|
||||
{
|
||||
public static readonly StyledProperty<string> HexProperty =
|
||||
AvaloniaProperty.Register<HexProperties, string>(nameof(Hex), "#FFFF0000", validate: ValidateHex);
|
||||
AvaloniaProperty.Register<HexProperties, string>(nameof(Hex), "#FFFF0000", validate: ValidateHex, coerce: CoerceHex);
|
||||
|
||||
private static string CoerceHex(IAvaloniaObject arg1, string arg2)
|
||||
{
|
||||
return arg2;
|
||||
}
|
||||
|
||||
private static bool ValidateHex(string hex)
|
||||
{
|
||||
|
|
|
@ -6,13 +6,28 @@ namespace ThemeEditor.Controls.ColorPicker.Props;
|
|||
public class HsvProperties : ColorPickerProperties
|
||||
{
|
||||
public static readonly StyledProperty<double> HueProperty =
|
||||
AvaloniaProperty.Register<HsvProperties, double>(nameof(Hue), 0.0, validate: ValidateHue);
|
||||
AvaloniaProperty.Register<HsvProperties, double>(nameof(Hue), 0.0, validate: ValidateHue, coerce: CoerceHue);
|
||||
|
||||
public static readonly StyledProperty<double> SaturationProperty =
|
||||
AvaloniaProperty.Register<HsvProperties, double>(nameof(Saturation), 100.0, validate: ValidateSaturation);
|
||||
AvaloniaProperty.Register<HsvProperties, double>(nameof(Saturation), 100.0, validate: ValidateSaturation, coerce: CoerceSaturation);
|
||||
|
||||
public static readonly StyledProperty<double> ValueProperty =
|
||||
AvaloniaProperty.Register<HsvProperties, double>(nameof(Value), 100.0, validate: ValidateValue);
|
||||
AvaloniaProperty.Register<HsvProperties, double>(nameof(Value), 100.0, validate: ValidateValue, coerce: CoerceValue);
|
||||
|
||||
private static double CoerceHue(IAvaloniaObject arg1, double arg2)
|
||||
{
|
||||
return ColorPickerHelpers.Clamp(arg2, 0.0, 360.0);
|
||||
}
|
||||
|
||||
private static double CoerceSaturation(IAvaloniaObject arg1, double arg2)
|
||||
{
|
||||
return ColorPickerHelpers.Clamp(arg2, 0.0, 100.0);
|
||||
}
|
||||
|
||||
private static double CoerceValue(IAvaloniaObject arg1, double arg2)
|
||||
{
|
||||
return ColorPickerHelpers.Clamp(arg2, 0.0, 100.0);
|
||||
}
|
||||
|
||||
private static bool ValidateHue(double hue)
|
||||
{
|
||||
|
|
|
@ -7,13 +7,28 @@ namespace ThemeEditor.Controls.ColorPicker.Props;
|
|||
public class RgbProperties : ColorPickerProperties
|
||||
{
|
||||
public static readonly StyledProperty<byte> RedProperty =
|
||||
AvaloniaProperty.Register<RgbProperties, byte>(nameof(Red), 0xFF, validate: ValidateRed);
|
||||
AvaloniaProperty.Register<RgbProperties, byte>(nameof(Red), 0xFF, validate: ValidateRed, coerce: CoerceRed);
|
||||
|
||||
public static readonly StyledProperty<byte> GreenProperty =
|
||||
AvaloniaProperty.Register<RgbProperties, byte>(nameof(Green), 0x00, validate: ValidateGreen);
|
||||
AvaloniaProperty.Register<RgbProperties, byte>(nameof(Green), 0x00, validate: ValidateGreen, coerce: CoerceGreen);
|
||||
|
||||
public static readonly StyledProperty<byte> BlueProperty =
|
||||
AvaloniaProperty.Register<RgbProperties, byte>(nameof(Blue), 0x00, validate: ValidateBlue);
|
||||
AvaloniaProperty.Register<RgbProperties, byte>(nameof(Blue), 0x00, validate: ValidateBlue, coerce: CoerceBlue);
|
||||
|
||||
private static byte CoerceRed(IAvaloniaObject arg1, byte arg2)
|
||||
{
|
||||
return ColorPickerHelpers.Clamp(arg2, 0, 255);
|
||||
}
|
||||
|
||||
private static byte CoerceGreen(IAvaloniaObject arg1, byte arg2)
|
||||
{
|
||||
return ColorPickerHelpers.Clamp(arg2, 0, 255);
|
||||
}
|
||||
|
||||
private static byte CoerceBlue(IAvaloniaObject arg1, byte arg2)
|
||||
{
|
||||
return ColorPickerHelpers.Clamp(arg2, 0, 255);
|
||||
}
|
||||
|
||||
private static bool ValidateRed(byte red)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче