16 private readonly HashSet<RadioButtonWidget> _buttons = [];
25 ArgumentNullException.ThrowIfNull(button);
34 ArgumentNullException.ThrowIfNull(button);
35 _buttons.Remove(button);
38 internal void Select(RadioButtonWidget selected)
40 ArgumentNullException.ThrowIfNull(selected);
42 foreach (RadioButtonWidget button
in _buttons.ToArray())
43 button.SetSelectedFromGroup(ReferenceEquals(button, selected));
52 private const int DefaultIndicatorSize = 20;
53 private const int DefaultLabelGap = 8;
54 private const int DotInset = 6;
56 private Color _normalColor = Color.FromArgb(
62 private Color _hoverColor = Color.FromArgb(
68 private Color _dotColor = Color.FromArgb(
75 private bool _isSelected;
76 private bool _disposed;
99 bool isSelected =
false,
100 string? nickname =
null)
104 ValidateBounds(bounds).Location,
107 ArgumentNullException.ThrowIfNull(view);
109 Rectangle indicatorBounds = GetIndicatorBounds(bounds);
110 Rectangle dotBounds = GetDotBounds(indicatorBounds);
111 Rectangle labelBounds = GetLabelBounds(bounds, indicatorBounds.Width);
113 Ring = CreateRing(renderSurfaceHost, view, indicatorBounds);
114 Dot = CreateDot(renderSurfaceHost, view, dotBounds);
126 CompleteInitialization(group, isSelected);
145 bool isSelected =
false,
146 string? nickname =
null)
150 ValidateBounds(bounds).Location,
153 ArgumentNullException.ThrowIfNull(sceneLayer);
155 Rectangle indicatorBounds = GetIndicatorBounds(bounds);
156 Rectangle dotBounds = GetDotBounds(indicatorBounds);
157 Rectangle labelBounds = GetLabelBounds(bounds, indicatorBounds.Width);
159 Ring = CreateRing(renderSurfaceHost, sceneLayer, indicatorBounds);
160 Dot = CreateDot(renderSurfaceHost, sceneLayer, dotBounds);
172 CompleteInitialization(group, isSelected);
198 if (ReferenceEquals(_group, value))
201 _group?.Unregister(
this);
203 _group?.Register(
this);
223 if (isSelected &&
Group is not
null)
229 SetSelectedFromGroup(isSelected);
249 Label.SetText(text ??
string.Empty);
265 _normalColor = normal;
269 UpdateRingColor(_normalColor);
270 Dot.SetColor(_dotColor);
282 Label.SetColors(color, SKColors.Transparent);
293 Ring.ZOrder = zOrder;
294 Dot.ZOrder = zOrder + 1;
295 Label.ZOrder = zOrder + 1;
320 base.OnPointerEnter(args);
321 UpdateRingColor(_hoverColor);
327 base.OnPointerLeave(args);
328 UpdateRingColor(_normalColor);
334 base.OnPointerClick(args);
346 base.OnKeyboardInput(args);
355 internal void SetSelectedFromGroup(
bool isSelected)
357 if (_isSelected == isSelected)
360 _isSelected = isSelected;
361 Dot.Visible = isSelected;
365 private void CompleteInitialization(RadioButtonGroup? group,
bool isSelected)
367 _isSelected = isSelected;
368 Dot.Visible = isSelected;
377 private void UpdateRingColor(Color color)
388 private DirectRectangle CreateRing(
389 RenderSurfaceHostBase host,
393 return ConfigureRing(
403 private DirectRectangle CreateRing(
404 RenderSurfaceHostBase host,
408 return ConfigureRing(
418 private static DirectRectangle ConfigureRing(DirectRectangle ring,
int size)
431 private DirectRectangle CreateDot(
432 RenderSurfaceHostBase host,
446 private DirectRectangle CreateDot(
447 RenderSurfaceHostBase host,
461 private static DirectRectangle ConfigureDot(DirectRectangle dot,
int size)
468 private static TextBlock CreateLabel(
469 RenderSurfaceHostBase host,
474 return ConfigureLabel(
new TextBlock(host, view, bounds), text);
477 private static TextBlock CreateLabel(
478 RenderSurfaceHostBase host,
483 return ConfigureLabel(
488 worldBounds: bounds),
492 private static TextBlock ConfigureLabel(TextBlock label,
string text)
494 return label.
SetText(text ??
string.Empty)
495 .
SetFont(SKTypeface.Default, 16f, minSize: 10f)
496 .
SetColors(SKColors.White, SKColors.Transparent)
497 .
SetAlignment(SKTextAlign.Left, TextBlock.VerticalAlign.Center)
501 private static Rectangle GetIndicatorBounds(Rectangle bounds)
503 int size = Math.Min(DefaultIndicatorSize, Math.Max(10, bounds.Height - 2));
507 bounds.Y + (bounds.Height - size) / 2,
512 private static Rectangle GetDotBounds(Rectangle indicatorBounds)
514 int inset = Math.Min(DotInset, Math.Max(2, indicatorBounds.Width / 3));
515 return Rectangle.Inflate(indicatorBounds, -inset, -inset);
518 private static Rectangle GetLabelBounds(Rectangle bounds,
int indicatorWidth)
520 int left = bounds.X + indicatorWidth + DefaultLabelGap;
525 Math.Max(1, bounds.Right - left),
529 private static Rectangle ValidateBounds(Rectangle bounds)
531 if (bounds.Width < 40 || bounds.Height < 12)
532 throw new ArgumentOutOfRangeException(nameof(bounds), bounds,
"Radio-button 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.
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 ...
@ 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.