16 private const int DefaultIndicatorSize = 20;
17 private const int DefaultLabelGap = 8;
18 private const int MarkInset = 5;
20 private Color _normalColor = Color.FromArgb(255, 48, 48, 56);
21 private Color _hoverColor = Color.FromArgb(255, 66, 66, 76);
22 private Color _markColor = Color.FromArgb(255, 235, 235, 242);
23 private bool _isChecked;
43 bool isChecked =
false,
44 string? nickname =
null)
47 ArgumentNullException.ThrowIfNull(view);
49 Rectangle indicatorBounds = GetIndicatorBounds(bounds);
50 Rectangle markBounds = GetMarkBounds(indicatorBounds);
51 Rectangle labelBounds = GetLabelBounds(bounds, indicatorBounds.Width);
53 Box = CreateBox(renderSurfaceHost, view, indicatorBounds);
54 Mark = CreateMark(renderSurfaceHost, view, markBounds);
55 Label = CreateLabel(renderSurfaceHost, view, labelBounds, text);
61 CompleteInitialization(isChecked);
77 bool isChecked =
false,
78 string? nickname =
null)
81 ArgumentNullException.ThrowIfNull(sceneLayer);
83 Rectangle indicatorBounds = GetIndicatorBounds(bounds);
84 Rectangle markBounds = GetMarkBounds(indicatorBounds);
85 Rectangle labelBounds = GetLabelBounds(bounds, indicatorBounds.Width);
87 Box = CreateBox(renderSurfaceHost, sceneLayer, indicatorBounds);
88 Mark = CreateMark(renderSurfaceHost, sceneLayer, markBounds);
89 Label = CreateLabel(renderSurfaceHost, sceneLayer, labelBounds, text);
95 CompleteInitialization(isChecked);
131 return Rectangle.Union(boxBounds, labelBounds);
142 if (_isChecked == isChecked)
145 _isChecked = isChecked;
146 Mark.Visible = isChecked;
167 Label.SetText(text ??
string.Empty);
182 _normalColor = normal;
186 UpdateBoxColor(
IsFocused ? _hoverColor : _normalColor);
187 Mark.SetColor(_markColor);
199 Label.SetColors(color, SKColors.Transparent);
211 Mark.ZOrder = zOrder + 1;
212 Label.ZOrder = zOrder + 1;
226 base.OnPointerEnter(args);
227 UpdateBoxColor(_hoverColor);
233 base.OnPointerLeave(args);
234 UpdateBoxColor(_normalColor);
240 base.OnPointerClick(args);
252 base.OnKeyboardInput(args);
261 private void CompleteInitialization(
bool isChecked)
263 _isChecked = isChecked;
264 Mark.Visible = isChecked;
271 private void UpdateBoxColor(Color color)
286 return ConfigureBox(
new DirectRectangle(_normalColor, host, view, bounds, $
"{Nickname}.box"));
289 private DirectRectangle CreateBox(RenderSurfaceHostBase host,
293 return ConfigureBox(
new DirectRectangle(_normalColor, host, layer, bounds, $
"{Nickname}.box"));
296 private static DirectRectangle ConfigureBox(DirectRectangle box)
304 private DirectRectangle CreateMark(RenderSurfaceHostBase host,
308 return ConfigureMark(
new DirectRectangle(_markColor, host, view, bounds, $
"{Nickname}.mark"));
311 private DirectRectangle CreateMark(RenderSurfaceHostBase host,
315 return ConfigureMark(
new DirectRectangle(_markColor, host, layer, bounds, $
"{Nickname}.mark"));
318 private static DirectRectangle ConfigureMark(DirectRectangle mark)
325 private static TextBlock CreateLabel(RenderSurfaceHostBase host,
330 return ConfigureLabel(
new TextBlock(host, view, bounds), text);
333 private static TextBlock CreateLabel(RenderSurfaceHostBase host,
338 return ConfigureLabel(
new TextBlock(host, layer, view:
null, worldBounds: bounds), text);
341 private static TextBlock ConfigureLabel(TextBlock label,
string text)
343 return label.
SetText(text ??
string.Empty)
344 .
SetFont(SKTypeface.Default, 16f, minSize: 10f)
345 .
SetColors(SKColors.White, SKColors.Transparent)
346 .
SetAlignment(SKTextAlign.Left, TextBlock.VerticalAlign.Center)
350 private static Rectangle GetIndicatorBounds(Rectangle bounds)
352 int size = Math.Min(DefaultIndicatorSize, Math.Max(10, bounds.Height - 2));
354 bounds.Y + (bounds.Height - size) / 2,
359 private static Rectangle GetMarkBounds(Rectangle indicatorBounds)
361 int inset = Math.Min(MarkInset, Math.Max(2, indicatorBounds.Width / 4));
362 return Rectangle.Inflate(indicatorBounds, -inset, -inset);
365 private static Rectangle GetLabelBounds(Rectangle bounds,
int indicatorWidth)
367 int left = bounds.X + indicatorWidth + DefaultLabelGap;
370 Math.Max(1, bounds.Right - left),
374 private static Rectangle ValidateBounds(Rectangle bounds)
376 if (bounds.Width < 40 || bounds.Height < 12)
377 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.