2025-12-19 09:30:16 +00:00
|
|
|
// Licensed to the .NET Foundation under one or more agreements.
|
|
|
|
|
// The .NET Foundation licenses this file to you under the MIT license.
|
|
|
|
|
|
2026-01-01 13:51:12 -05:00
|
|
|
using System;
|
|
|
|
|
using Microsoft.Maui.Controls;
|
2026-01-16 04:54:03 +00:00
|
|
|
using Microsoft.Maui.Graphics;
|
2025-12-19 09:30:16 +00:00
|
|
|
using SkiaSharp;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.Maui.Platform;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2026-01-16 04:54:03 +00:00
|
|
|
/// Skia-rendered checkbox control with full MAUI compliance.
|
|
|
|
|
/// Implements ICheckBox interface requirements:
|
|
|
|
|
/// - IsChecked property with CheckedChanged event
|
|
|
|
|
/// - Color property (maps to BoxColor when checked)
|
|
|
|
|
/// - Foreground property (maps to CheckColor - the checkmark color)
|
2025-12-19 09:30:16 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public class SkiaCheckBox : SkiaView
|
|
|
|
|
{
|
2026-01-16 04:54:03 +00:00
|
|
|
#region SKColor Helper
|
|
|
|
|
|
|
|
|
|
private static SKColor ToSKColor(Color? color)
|
|
|
|
|
{
|
|
|
|
|
if (color == null) return SKColors.Transparent;
|
2026-01-17 03:36:37 +00:00
|
|
|
return color.ToSKColor();
|
2026-01-16 04:54:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2025-12-21 13:26:56 -05:00
|
|
|
#region BindableProperties
|
2025-12-19 09:30:16 +00:00
|
|
|
|
2025-12-21 13:26:56 -05:00
|
|
|
public static readonly BindableProperty IsCheckedProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(IsChecked),
|
|
|
|
|
typeof(bool),
|
|
|
|
|
typeof(SkiaCheckBox),
|
|
|
|
|
false,
|
2026-01-16 04:54:03 +00:00
|
|
|
BindingMode.TwoWay,
|
2025-12-21 13:26:56 -05:00
|
|
|
propertyChanged: (b, o, n) => ((SkiaCheckBox)b).OnIsCheckedChanged());
|
|
|
|
|
|
2026-01-16 04:54:03 +00:00
|
|
|
public static readonly BindableProperty ColorProperty =
|
2025-12-21 13:26:56 -05:00
|
|
|
BindableProperty.Create(
|
2026-01-16 04:54:03 +00:00
|
|
|
nameof(Color),
|
|
|
|
|
typeof(Color),
|
2025-12-21 13:26:56 -05:00
|
|
|
typeof(SkiaCheckBox),
|
2026-01-16 04:54:03 +00:00
|
|
|
Color.FromRgb(33, 150, 243), // Material Blue
|
2026-01-01 13:51:12 -05:00
|
|
|
BindingMode.TwoWay,
|
2025-12-21 13:26:56 -05:00
|
|
|
propertyChanged: (b, o, n) => ((SkiaCheckBox)b).Invalidate());
|
|
|
|
|
|
2026-01-16 04:54:03 +00:00
|
|
|
public static readonly BindableProperty CheckColorProperty =
|
2025-12-21 13:26:56 -05:00
|
|
|
BindableProperty.Create(
|
2026-01-16 04:54:03 +00:00
|
|
|
nameof(CheckColor),
|
|
|
|
|
typeof(Color),
|
2025-12-21 13:26:56 -05:00
|
|
|
typeof(SkiaCheckBox),
|
2026-01-16 04:54:03 +00:00
|
|
|
Colors.White,
|
2026-01-01 13:51:12 -05:00
|
|
|
BindingMode.TwoWay,
|
2025-12-21 13:26:56 -05:00
|
|
|
propertyChanged: (b, o, n) => ((SkiaCheckBox)b).Invalidate());
|
|
|
|
|
|
|
|
|
|
public static readonly BindableProperty UncheckedBoxColorProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(UncheckedBoxColor),
|
2026-01-16 04:54:03 +00:00
|
|
|
typeof(Color),
|
2025-12-21 13:26:56 -05:00
|
|
|
typeof(SkiaCheckBox),
|
2026-01-16 04:54:03 +00:00
|
|
|
Colors.White,
|
2026-01-01 13:51:12 -05:00
|
|
|
BindingMode.TwoWay,
|
2025-12-21 13:26:56 -05:00
|
|
|
propertyChanged: (b, o, n) => ((SkiaCheckBox)b).Invalidate());
|
|
|
|
|
|
|
|
|
|
public static readonly BindableProperty BorderColorProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(BorderColor),
|
2026-01-16 04:54:03 +00:00
|
|
|
typeof(Color),
|
2025-12-21 13:26:56 -05:00
|
|
|
typeof(SkiaCheckBox),
|
2026-01-16 04:54:03 +00:00
|
|
|
Color.FromRgb(117, 117, 117),
|
2026-01-01 13:51:12 -05:00
|
|
|
BindingMode.TwoWay,
|
2025-12-21 13:26:56 -05:00
|
|
|
propertyChanged: (b, o, n) => ((SkiaCheckBox)b).Invalidate());
|
|
|
|
|
|
|
|
|
|
public static readonly BindableProperty DisabledColorProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(DisabledColor),
|
2026-01-16 04:54:03 +00:00
|
|
|
typeof(Color),
|
2025-12-21 13:26:56 -05:00
|
|
|
typeof(SkiaCheckBox),
|
2026-01-16 04:54:03 +00:00
|
|
|
Color.FromRgb(189, 189, 189),
|
2026-01-01 13:51:12 -05:00
|
|
|
BindingMode.TwoWay,
|
2025-12-21 13:26:56 -05:00
|
|
|
propertyChanged: (b, o, n) => ((SkiaCheckBox)b).Invalidate());
|
|
|
|
|
|
|
|
|
|
public static readonly BindableProperty HoveredBorderColorProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(HoveredBorderColor),
|
2026-01-16 04:54:03 +00:00
|
|
|
typeof(Color),
|
2025-12-21 13:26:56 -05:00
|
|
|
typeof(SkiaCheckBox),
|
2026-01-16 04:54:03 +00:00
|
|
|
Color.FromRgb(33, 150, 243),
|
2026-01-01 13:51:12 -05:00
|
|
|
BindingMode.TwoWay,
|
2025-12-21 13:26:56 -05:00
|
|
|
propertyChanged: (b, o, n) => ((SkiaCheckBox)b).Invalidate());
|
|
|
|
|
|
|
|
|
|
public static readonly BindableProperty BoxSizeProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(BoxSize),
|
2026-01-16 04:54:03 +00:00
|
|
|
typeof(double),
|
2025-12-21 13:26:56 -05:00
|
|
|
typeof(SkiaCheckBox),
|
2026-01-16 04:54:03 +00:00
|
|
|
20.0,
|
2026-01-01 13:51:12 -05:00
|
|
|
BindingMode.TwoWay,
|
2025-12-21 13:26:56 -05:00
|
|
|
propertyChanged: (b, o, n) => ((SkiaCheckBox)b).InvalidateMeasure());
|
|
|
|
|
|
|
|
|
|
public static readonly BindableProperty CornerRadiusProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(CornerRadius),
|
2026-01-16 04:54:03 +00:00
|
|
|
typeof(double),
|
2025-12-21 13:26:56 -05:00
|
|
|
typeof(SkiaCheckBox),
|
2026-01-16 04:54:03 +00:00
|
|
|
3.0,
|
2026-01-01 13:51:12 -05:00
|
|
|
BindingMode.TwoWay,
|
2025-12-21 13:26:56 -05:00
|
|
|
propertyChanged: (b, o, n) => ((SkiaCheckBox)b).Invalidate());
|
|
|
|
|
|
|
|
|
|
public static readonly BindableProperty BorderWidthProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(BorderWidth),
|
2026-01-16 04:54:03 +00:00
|
|
|
typeof(double),
|
2025-12-21 13:26:56 -05:00
|
|
|
typeof(SkiaCheckBox),
|
2026-01-16 04:54:03 +00:00
|
|
|
2.0,
|
2026-01-01 13:51:12 -05:00
|
|
|
BindingMode.TwoWay,
|
2025-12-21 13:26:56 -05:00
|
|
|
propertyChanged: (b, o, n) => ((SkiaCheckBox)b).Invalidate());
|
|
|
|
|
|
|
|
|
|
public static readonly BindableProperty CheckStrokeWidthProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(CheckStrokeWidth),
|
2026-01-16 04:54:03 +00:00
|
|
|
typeof(double),
|
2025-12-21 13:26:56 -05:00
|
|
|
typeof(SkiaCheckBox),
|
2026-01-16 04:54:03 +00:00
|
|
|
2.5,
|
2026-01-01 13:51:12 -05:00
|
|
|
BindingMode.TwoWay,
|
2025-12-21 13:26:56 -05:00
|
|
|
propertyChanged: (b, o, n) => ((SkiaCheckBox)b).Invalidate());
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Properties
|
|
|
|
|
|
2026-01-16 04:54:03 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets whether the checkbox is checked.
|
|
|
|
|
/// </summary>
|
2025-12-19 09:30:16 +00:00
|
|
|
public bool IsChecked
|
|
|
|
|
{
|
2025-12-21 13:26:56 -05:00
|
|
|
get => (bool)GetValue(IsCheckedProperty);
|
|
|
|
|
set => SetValue(IsCheckedProperty, value);
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
2026-01-16 04:54:03 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the color of the checkbox box when checked.
|
|
|
|
|
/// This is the primary MAUI CheckBox.Color property.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Color Color
|
2025-12-21 13:26:56 -05:00
|
|
|
{
|
2026-01-16 04:54:03 +00:00
|
|
|
get => (Color)GetValue(ColorProperty);
|
|
|
|
|
set => SetValue(ColorProperty, value);
|
2025-12-21 13:26:56 -05:00
|
|
|
}
|
|
|
|
|
|
2026-01-16 04:54:03 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the color of the checkmark itself.
|
|
|
|
|
/// Maps to ICheckBox.Foreground in MAUI.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Color CheckColor
|
2025-12-21 13:26:56 -05:00
|
|
|
{
|
2026-01-16 04:54:03 +00:00
|
|
|
get => (Color)GetValue(CheckColorProperty);
|
|
|
|
|
set => SetValue(CheckColorProperty, value);
|
2025-12-21 13:26:56 -05:00
|
|
|
}
|
|
|
|
|
|
2026-01-16 04:54:03 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the color of the checkbox box when unchecked.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Color UncheckedBoxColor
|
2025-12-21 13:26:56 -05:00
|
|
|
{
|
2026-01-16 04:54:03 +00:00
|
|
|
get => (Color)GetValue(UncheckedBoxColorProperty);
|
2025-12-21 13:26:56 -05:00
|
|
|
set => SetValue(UncheckedBoxColorProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-16 04:54:03 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the border color when unchecked.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Color BorderColor
|
2025-12-21 13:26:56 -05:00
|
|
|
{
|
2026-01-16 04:54:03 +00:00
|
|
|
get => (Color)GetValue(BorderColorProperty);
|
2025-12-21 13:26:56 -05:00
|
|
|
set => SetValue(BorderColorProperty, value);
|
|
|
|
|
}
|
2025-12-19 09:30:16 +00:00
|
|
|
|
2026-01-16 04:54:03 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the color used when the control is disabled.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Color DisabledColor
|
2025-12-21 13:26:56 -05:00
|
|
|
{
|
2026-01-16 04:54:03 +00:00
|
|
|
get => (Color)GetValue(DisabledColorProperty);
|
2025-12-21 13:26:56 -05:00
|
|
|
set => SetValue(DisabledColorProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-16 04:54:03 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the border color when hovered.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Color HoveredBorderColor
|
2025-12-21 13:26:56 -05:00
|
|
|
{
|
2026-01-16 04:54:03 +00:00
|
|
|
get => (Color)GetValue(HoveredBorderColorProperty);
|
2025-12-21 13:26:56 -05:00
|
|
|
set => SetValue(HoveredBorderColorProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-16 04:54:03 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the size of the checkbox box in device-independent units.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public double BoxSize
|
2025-12-21 13:26:56 -05:00
|
|
|
{
|
2026-01-16 04:54:03 +00:00
|
|
|
get => (double)GetValue(BoxSizeProperty);
|
2025-12-21 13:26:56 -05:00
|
|
|
set => SetValue(BoxSizeProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-16 04:54:03 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the corner radius of the checkbox box.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public double CornerRadius
|
2025-12-21 13:26:56 -05:00
|
|
|
{
|
2026-01-16 04:54:03 +00:00
|
|
|
get => (double)GetValue(CornerRadiusProperty);
|
2025-12-21 13:26:56 -05:00
|
|
|
set => SetValue(CornerRadiusProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-16 04:54:03 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the border width.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public double BorderWidth
|
2025-12-21 13:26:56 -05:00
|
|
|
{
|
2026-01-16 04:54:03 +00:00
|
|
|
get => (double)GetValue(BorderWidthProperty);
|
2025-12-21 13:26:56 -05:00
|
|
|
set => SetValue(BorderWidthProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-16 04:54:03 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the stroke width of the checkmark.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public double CheckStrokeWidth
|
2025-12-21 13:26:56 -05:00
|
|
|
{
|
2026-01-16 04:54:03 +00:00
|
|
|
get => (double)GetValue(CheckStrokeWidthProperty);
|
2025-12-21 13:26:56 -05:00
|
|
|
set => SetValue(CheckStrokeWidthProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-16 04:54:03 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets whether the control is currently hovered.
|
|
|
|
|
/// </summary>
|
2025-12-19 09:30:16 +00:00
|
|
|
public bool IsHovered { get; private set; }
|
|
|
|
|
|
2025-12-21 13:26:56 -05:00
|
|
|
#endregion
|
|
|
|
|
|
2026-01-16 04:54:03 +00:00
|
|
|
#region Events
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Occurs when the IsChecked property changes.
|
|
|
|
|
/// </summary>
|
2025-12-19 09:30:16 +00:00
|
|
|
public event EventHandler<CheckedChangedEventArgs>? CheckedChanged;
|
|
|
|
|
|
2026-01-16 04:54:03 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Constructor
|
|
|
|
|
|
2025-12-19 09:30:16 +00:00
|
|
|
public SkiaCheckBox()
|
|
|
|
|
{
|
|
|
|
|
IsFocusable = true;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-16 04:54:03 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Event Handlers
|
|
|
|
|
|
2025-12-21 13:26:56 -05:00
|
|
|
private void OnIsCheckedChanged()
|
|
|
|
|
{
|
|
|
|
|
CheckedChanged?.Invoke(this, new CheckedChangedEventArgs(IsChecked));
|
2026-01-01 13:51:12 -05:00
|
|
|
SkiaVisualStateManager.GoToState(this, IsChecked ? "Checked" : "Unchecked");
|
2025-12-21 13:26:56 -05:00
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-16 04:54:03 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Rendering
|
|
|
|
|
|
2025-12-19 09:30:16 +00:00
|
|
|
protected override void OnDraw(SKCanvas canvas, SKRect bounds)
|
|
|
|
|
{
|
2026-01-16 04:54:03 +00:00
|
|
|
var boxSize = (float)BoxSize;
|
|
|
|
|
var cornerRadius = (float)CornerRadius;
|
|
|
|
|
var borderWidth = (float)BorderWidth;
|
|
|
|
|
|
2025-12-19 09:30:16 +00:00
|
|
|
// Center the checkbox box in bounds
|
|
|
|
|
var boxRect = new SKRect(
|
2026-01-16 04:54:03 +00:00
|
|
|
bounds.Left + (bounds.Width - boxSize) / 2f,
|
|
|
|
|
bounds.Top + (bounds.Height - boxSize) / 2f,
|
|
|
|
|
bounds.Left + (bounds.Width - boxSize) / 2f + boxSize,
|
|
|
|
|
bounds.Top + (bounds.Height - boxSize) / 2f + boxSize);
|
2025-12-19 09:30:16 +00:00
|
|
|
|
2026-01-16 04:54:03 +00:00
|
|
|
var roundRect = new SKRoundRect(boxRect, cornerRadius);
|
2025-12-19 09:30:16 +00:00
|
|
|
|
2026-01-16 04:54:03 +00:00
|
|
|
// Get colors as SKColor
|
|
|
|
|
var colorSK = ToSKColor(Color);
|
|
|
|
|
var checkColorSK = ToSKColor(CheckColor);
|
|
|
|
|
var uncheckedBoxColorSK = ToSKColor(UncheckedBoxColor);
|
|
|
|
|
var borderColorSK = ToSKColor(BorderColor);
|
|
|
|
|
var disabledColorSK = ToSKColor(DisabledColor);
|
|
|
|
|
var hoveredBorderColorSK = ToSKColor(HoveredBorderColor);
|
2026-01-01 13:51:12 -05:00
|
|
|
|
2025-12-19 09:30:16 +00:00
|
|
|
// Draw background
|
|
|
|
|
using var bgPaint = new SKPaint
|
|
|
|
|
{
|
2026-01-16 04:54:03 +00:00
|
|
|
Color = !IsEnabled ? disabledColorSK
|
|
|
|
|
: IsChecked ? colorSK
|
|
|
|
|
: uncheckedBoxColorSK,
|
2025-12-19 09:30:16 +00:00
|
|
|
IsAntialias = true,
|
|
|
|
|
Style = SKPaintStyle.Fill
|
|
|
|
|
};
|
|
|
|
|
canvas.DrawRoundRect(roundRect, bgPaint);
|
|
|
|
|
|
|
|
|
|
// Draw border
|
|
|
|
|
using var borderPaint = new SKPaint
|
|
|
|
|
{
|
2026-01-16 04:54:03 +00:00
|
|
|
Color = !IsEnabled ? disabledColorSK
|
|
|
|
|
: IsChecked ? colorSK
|
|
|
|
|
: IsHovered ? hoveredBorderColorSK
|
|
|
|
|
: borderColorSK,
|
2025-12-19 09:30:16 +00:00
|
|
|
IsAntialias = true,
|
|
|
|
|
Style = SKPaintStyle.Stroke,
|
2026-01-16 04:54:03 +00:00
|
|
|
StrokeWidth = borderWidth
|
2025-12-19 09:30:16 +00:00
|
|
|
};
|
|
|
|
|
canvas.DrawRoundRect(roundRect, borderPaint);
|
|
|
|
|
|
|
|
|
|
// Draw focus ring
|
|
|
|
|
if (IsFocused)
|
|
|
|
|
{
|
|
|
|
|
using var focusPaint = new SKPaint
|
|
|
|
|
{
|
2026-01-16 04:54:03 +00:00
|
|
|
Color = colorSK.WithAlpha(80),
|
2025-12-19 09:30:16 +00:00
|
|
|
IsAntialias = true,
|
|
|
|
|
Style = SKPaintStyle.Stroke,
|
2026-01-01 13:51:12 -05:00
|
|
|
StrokeWidth = 3f
|
2025-12-19 09:30:16 +00:00
|
|
|
};
|
2026-01-16 04:54:03 +00:00
|
|
|
var focusRect = new SKRoundRect(boxRect, cornerRadius);
|
2026-01-01 13:51:12 -05:00
|
|
|
focusRect.Inflate(4f, 4f);
|
2025-12-19 09:30:16 +00:00
|
|
|
canvas.DrawRoundRect(focusRect, focusPaint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Draw checkmark
|
|
|
|
|
if (IsChecked)
|
|
|
|
|
{
|
2026-01-16 04:54:03 +00:00
|
|
|
DrawCheckmark(canvas, boxRect, checkColorSK);
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-16 04:54:03 +00:00
|
|
|
private void DrawCheckmark(SKCanvas canvas, SKRect boxRect, SKColor checkColor)
|
2025-12-19 09:30:16 +00:00
|
|
|
{
|
2026-01-16 04:54:03 +00:00
|
|
|
var checkStrokeWidth = (float)CheckStrokeWidth;
|
|
|
|
|
var boxSize = (float)BoxSize;
|
|
|
|
|
|
2025-12-19 09:30:16 +00:00
|
|
|
using var paint = new SKPaint
|
|
|
|
|
{
|
2026-01-16 04:54:03 +00:00
|
|
|
Color = checkColor,
|
2025-12-19 09:30:16 +00:00
|
|
|
IsAntialias = true,
|
|
|
|
|
Style = SKPaintStyle.Stroke,
|
2026-01-16 04:54:03 +00:00
|
|
|
StrokeWidth = checkStrokeWidth,
|
2025-12-19 09:30:16 +00:00
|
|
|
StrokeCap = SKStrokeCap.Round,
|
|
|
|
|
StrokeJoin = SKStrokeJoin.Round
|
|
|
|
|
};
|
|
|
|
|
|
2026-01-16 04:54:03 +00:00
|
|
|
float padding = boxSize * 0.2f;
|
2026-01-01 13:51:12 -05:00
|
|
|
float left = boxRect.Left + padding;
|
|
|
|
|
float right = boxRect.Right - padding;
|
|
|
|
|
float top = boxRect.Top + padding;
|
|
|
|
|
float bottom = boxRect.Bottom - padding;
|
2025-12-19 09:30:16 +00:00
|
|
|
|
|
|
|
|
using var path = new SKPath();
|
|
|
|
|
path.MoveTo(left, boxRect.MidY);
|
|
|
|
|
path.LineTo(boxRect.MidX - padding * 0.3f, bottom - padding * 0.5f);
|
|
|
|
|
path.LineTo(right, top + padding * 0.3f);
|
|
|
|
|
|
|
|
|
|
canvas.DrawPath(path, paint);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-16 04:54:03 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Pointer Events
|
|
|
|
|
|
2025-12-19 09:30:16 +00:00
|
|
|
public override void OnPointerEntered(PointerEventArgs e)
|
|
|
|
|
{
|
2026-01-01 13:51:12 -05:00
|
|
|
if (IsEnabled)
|
|
|
|
|
{
|
|
|
|
|
IsHovered = true;
|
|
|
|
|
SkiaVisualStateManager.GoToState(this, "PointerOver");
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnPointerExited(PointerEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
IsHovered = false;
|
2026-01-01 13:51:12 -05:00
|
|
|
SkiaVisualStateManager.GoToState(this, IsEnabled ? "Normal" : "Disabled");
|
2025-12-19 09:30:16 +00:00
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnPointerPressed(PointerEventArgs e)
|
|
|
|
|
{
|
2026-01-01 13:51:12 -05:00
|
|
|
if (IsEnabled)
|
|
|
|
|
{
|
|
|
|
|
IsChecked = !IsChecked;
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnPointerReleased(PointerEventArgs e)
|
|
|
|
|
{
|
2026-01-16 04:54:03 +00:00
|
|
|
// No action needed
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
2026-01-16 04:54:03 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Keyboard Events
|
|
|
|
|
|
2025-12-19 09:30:16 +00:00
|
|
|
public override void OnKeyDown(KeyEventArgs e)
|
|
|
|
|
{
|
2026-01-01 13:51:12 -05:00
|
|
|
if (IsEnabled && e.Key == Key.Space)
|
2025-12-19 09:30:16 +00:00
|
|
|
{
|
|
|
|
|
IsChecked = !IsChecked;
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-16 04:54:03 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Lifecycle
|
|
|
|
|
|
2025-12-21 13:26:56 -05:00
|
|
|
protected override void OnEnabledChanged()
|
|
|
|
|
{
|
|
|
|
|
base.OnEnabledChanged();
|
2026-01-01 13:51:12 -05:00
|
|
|
SkiaVisualStateManager.GoToState(this, IsEnabled ? "Normal" : "Disabled");
|
2025-12-21 13:26:56 -05:00
|
|
|
}
|
|
|
|
|
|
2026-01-16 04:54:03 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Layout
|
|
|
|
|
|
2025-12-19 09:30:16 +00:00
|
|
|
protected override SKSize MeasureOverride(SKSize availableSize)
|
|
|
|
|
{
|
2026-01-16 04:54:03 +00:00
|
|
|
var boxSize = (float)BoxSize;
|
|
|
|
|
return new SKSize(boxSize + 8f, boxSize + 8f);
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
2026-01-16 04:54:03 +00:00
|
|
|
|
|
|
|
|
#endregion
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|