16 private const int DefaultIndicatorSize = 20;
17 private const int DefaultLabelGap = 8;
18 private const int MarkInset = 5;
20 private Color _normalColor = Color.FromArgb(
26 private Color _hoverColor = Color.FromArgb(
32 private Color _markColor = Color.FromArgb(
38 private bool _isChecked;
59 bool isChecked =
false,
60 string? nickname =
null)
64 ValidateBounds(bounds).Location,
67 ArgumentNullException.ThrowIfNull(view);
69 Rectangle indicatorBounds = GetIndicatorBounds(bounds);
70 Rectangle markBounds = GetMarkBounds(indicatorBounds);
71 Rectangle labelBounds = GetLabelBounds(bounds, indicatorBounds.Width);
73 Box = CreateBox(renderSurfaceHost, view, indicatorBounds);
74 Mark = CreateMark(renderSurfaceHost, view, markBounds);
86 CompleteInitialization(isChecked);
103 bool isChecked =
false,
104 string? nickname =
null)
108 ValidateBounds(bounds).Location,
111 ArgumentNullException.ThrowIfNull(sceneLayer);
113 Rectangle indicatorBounds = GetIndicatorBounds(bounds);
114 Rectangle markBounds = GetMarkBounds(indicatorBounds);
115 Rectangle labelBounds = GetLabelBounds(bounds, indicatorBounds.Width);
117 Box = CreateBox(renderSurfaceHost, sceneLayer, indicatorBounds);
118 Mark = CreateMark(renderSurfaceHost, sceneLayer, markBounds);
130 CompleteInitialization(isChecked);
166 return Rectangle.Union(boxBounds, labelBounds);
177 if (_isChecked == isChecked)
180 _isChecked = isChecked;
181 Mark.Visible = isChecked;
202 Label.SetText(text ??
string.Empty);
218 _normalColor = normal;
222 UpdateBoxColor(
IsFocused ? _hoverColor : _normalColor);
223 Mark.SetColor(_markColor);
235 Label.SetColors(color, SKColors.Transparent);
247 Mark.ZOrder = zOrder + 1;
248 Label.ZOrder = zOrder + 1;
262 base.OnPointerEnter(args);
263 UpdateBoxColor(_hoverColor);
269 base.OnPointerLeave(args);
270 UpdateBoxColor(_normalColor);
276 base.OnPointerClick(args);
288 base.OnKeyboardInput(args);
297 private void CompleteInitialization(
bool isChecked)
299 _isChecked = isChecked;
300 Mark.Visible = isChecked;
307 private void UpdateBoxColor(Color color)
332 private DirectRectangle CreateBox(
333 RenderSurfaceHostBase host,
346 private static DirectRectangle ConfigureBox(DirectRectangle box)
359 private DirectRectangle CreateMark(
360 RenderSurfaceHostBase host,
364 return ConfigureMark(
370 $
"{Nickname}.mark"));
373 private DirectRectangle CreateMark(
374 RenderSurfaceHostBase host,
378 return ConfigureMark(
384 $
"{Nickname}.mark"));
387 private static DirectRectangle ConfigureMark(DirectRectangle mark)
394 private static TextBlock CreateLabel(
395 RenderSurfaceHostBase host,
400 return ConfigureLabel(
new TextBlock(host, view, bounds), text);
403 private static TextBlock CreateLabel(
404 RenderSurfaceHostBase host,
409 return ConfigureLabel(
414 worldBounds: bounds),
418 private static TextBlock ConfigureLabel(TextBlock label,
string text)
420 return label.
SetText(text ??
string.Empty)
421 .
SetFont(SKTypeface.Default, 16f, minSize: 10f)
422 .
SetColors(SKColors.White, SKColors.Transparent)
423 .
SetAlignment(SKTextAlign.Left, TextBlock.VerticalAlign.Center)
427 private static Rectangle GetIndicatorBounds(Rectangle bounds)
429 int size = Math.Min(DefaultIndicatorSize, Math.Max(10, bounds.Height - 2));
433 bounds.Y + (bounds.Height - size) / 2,
438 private static Rectangle GetMarkBounds(Rectangle indicatorBounds)
440 int inset = Math.Min(MarkInset, Math.Max(2, indicatorBounds.Width / 4));
441 return Rectangle.Inflate(indicatorBounds, -inset, -inset);
444 private static Rectangle GetLabelBounds(Rectangle bounds,
int indicatorWidth)
446 int left = bounds.X + indicatorWidth + DefaultLabelGap;
451 Math.Max(1, bounds.Right - left),
455 private static Rectangle ValidateBounds(Rectangle bounds)
457 if (bounds.Width < 40 || bounds.Height < 12)
458 throw new ArgumentOutOfRangeException(nameof(bounds), bounds,
"Checkbox bounds are too small.");
SceneLayer? SceneLayer
Gets the scene layer shared by all children in scene-layer mode.
View? View
Gets the view shared by all children in view mode.
virtual DirectComposite Add(IDirectCompositeChild child, bool keepCurrentOffset=true, Vector2? explicitLocalOffsetPx=null)
Adds a composite-compatible direct drawable as a child.
DirectDrawingMode Mode
Gets the coordinate mode shared by the composite and its children.
Vector2 GetPosition()
Gets the current position of this direct drawing in pixel coordinates.
void SetPosition(Vector2 p)
Sets the position of this direct drawing to the specified pixel coordinates.
Renders a configurable rectangle with support for fill, border, rounded corners, dash patterns,...
DirectRectangle SetFilled(bool isFilled)
Sets whether the rectangle interior is filled with the base color (or pattern).
DirectRectangle SetBorderColor(Color color)
Sets a distinct border (stroke) color, independent of the fill color.
DirectRectangle SetColor(Color color)
Sets the base color used for both fill and stroke (unless a distinct border color is specified).
DirectRectangle SetStrokeWidth(float width)
Sets the width (thickness) of the rectangle's stroke (outline) in pixels.
DirectRectangle SetCornerRadius(float radius)
Sets the radius for rounded corners in pixels.
A retained-mode text drawable with wrapping, multi-line ( ) support, horizontal/vertical alignment,...
TextBlock SetFont(SKTypeface typeface, float size, float? minSize=null)
Sets the font face and size (and optional minimum size for auto-shrink).
TextBlock EnableWrapping(bool enable=true)
Enables or disables word wrapping when laying out paragraphs.
TextBlock SetAlignment(SKTextAlign h, VerticalAlign v)
Sets the horizontal and vertical alignment used when drawing the laid-out lines within the bounds.
TextBlock SetColors(SKColor fg, SKColor bg)
Sets the foreground (text) and background colors using Skia colors.
TextBlock SetText(string text)
Sets the current text content and rebuilds layout as needed. If no reveal animation is active,...
Represents a base class for hosting a render surface, providing functionality for managing rendering ...
Represents a rendered view of a scene, combining a camera position with a viewport configuration to c...
@ Rectangle
Particles are spawned uniformly within a rectangular area. This is the default distribution.
DirectDrawingMode
Specifies where direct drawing operations are applied within the rendering pipeline.
@ View
Performs direct drawing at the view level using screen-space coordinates.