17 private const int DefaultDropDownHeight = 144;
19 private readonly DropDownChevronDrawing _chevron;
20 private bool _isDropDownOpen;
21 private bool _disposed;
22 private string _placeholder =
"Select...";
42 IEnumerable<string>? items =
null,
43 int dropDownHeight = DefaultDropDownHeight,
44 string? nickname =
null)
48 ValidateBounds(bounds).Location,
51 ArgumentNullException.ThrowIfNull(view);
52 ValidateDropDownHeight(dropDownHeight);
59 $
"{Nickname}.header");
72 _chevron =
new DropDownChevronDrawing(
75 ResolveChevronBounds(bounds),
76 $
"{Nickname}.chevron");
78 CompleteInitialization(bounds);
94 IEnumerable<string>? items =
null,
95 int dropDownHeight = DefaultDropDownHeight,
96 string? nickname =
null)
100 ValidateBounds(bounds).Location,
103 ArgumentNullException.ThrowIfNull(sceneLayer);
104 ValidateDropDownHeight(dropDownHeight);
111 $
"{Nickname}.header");
124 _chevron =
new DropDownChevronDrawing(
127 ResolveChevronBounds(bounds),
128 $
"{Nickname}.chevron");
130 CompleteInitialization(bounds);
159 set => DropDown.SelectedIndex = value;
175 _placeholder = value ??
string.Empty;
209 if (_isDropDownOpen ||
Items.Count == 0)
212 _isDropDownOpen =
true;
215 WidgetInputRouterRegistry.TryFocus(
DropDown);
225 CollapseDropDown(restoreHeaderFocus:
true);
245 Header.SetButtonZOrder(zOrder);
246 _chevron.ZOrder = zOrder + 2;
247 DropDown.SetListBoxZOrder(zOrder + 10);
258 Header.SetTextColor(color);
259 _chevron.SetColor(color);
270 Header.Clicked -= OnHeaderClicked;
271 DropDown.SelectedIndexChanged -= OnSelectedIndexChanged;
272 DropDown.SelectionCommitted -= OnDropDownSelectionCommitted;
273 DropDown.FocusLost -= OnDropDownFocusLost;
282 if (!_isDropDownOpen)
289 _isDropDownOpen =
false;
290 base.ProcessHidden();
293 private void CompleteInitialization(Rectangle bounds)
295 ConfigureHeaderContentBounds(bounds);
300 Header.Clicked += OnHeaderClicked;
301 DropDown.SelectedIndexChanged += OnSelectedIndexChanged;
302 DropDown.SelectionCommitted += OnDropDownSelectionCommitted;
303 DropDown.FocusLost += OnDropDownFocusLost;
315 private void OnHeaderClicked()
320 private void OnSelectedIndexChanged(
int index)
326 private void OnDropDownSelectionCommitted(
int index)
332 private void OnDropDownFocusLost()
334 if (!_isDropDownOpen)
343 if (ReferenceEquals(focusedWidget,
Header) || ReferenceEquals(focusedWidget,
DropDown))
346 CollapseDropDown(restoreHeaderFocus:
false);
349 private void CollapseDropDown(
bool restoreHeaderFocus)
351 if (!_isDropDownOpen)
354 _isDropDownOpen =
false;
357 if (!restoreHeaderFocus)
361 WidgetInputRouterRegistry.TryFocus(
Header);
364 private void RefreshHeaderText()
369 private void ConfigureHeaderContentBounds(Rectangle bounds)
374 Math.Max(1, bounds.Width - 28),
378 Header.Label.ScreenBounds = labelBounds;
380 Header.Label.WorldBounds = labelBounds;
383 private static Rectangle ResolveChevronBounds(Rectangle bounds)
385 const int width = 18;
388 Math.Max(bounds.Left, bounds.Right - width - 4),
390 Math.Min(width, bounds.Width),
394 private static Rectangle ValidateBounds(Rectangle bounds)
396 if (bounds.Width < 60 || bounds.Height < 20)
397 throw new ArgumentOutOfRangeException(nameof(bounds), bounds,
"Combo-box bounds are too small.");
402 private static void ValidateDropDownHeight(
int height)
405 throw new ArgumentOutOfRangeException(nameof(height),
"Drop-down height must be at least 28 pixels.");
408 private sealed class DropDownChevronDrawing : DirectDrawingMovableBase
410 private SKColor _color = SKColors.White;
412 internal DropDownChevronDrawing(
413 RenderSurfaceHostBase host,
428 internal DropDownChevronDrawing(
429 RenderSurfaceHostBase host,
444 internal void SetColor(Color color)
446 _color =
new SKColor(
456 protected override void OnDraw(BackbufferBase backbuffer, RectangleF destRectScreen)
458 float width = Math.Min(8f, destRectScreen.Width - 4f);
459 float centerX = destRectScreen.Left + destRectScreen.Width / 2f;
460 float centerY = destRectScreen.Top + destRectScreen.Height / 2f;
462 using var paint =
new SKPaint
466 Style = SKPaintStyle.Stroke,
468 StrokeCap = SKStrokeCap.Round,
469 StrokeJoin = SKStrokeJoin.Round
472 using var path =
new SKPath();
474 path.MoveTo(centerX - width / 2f, centerY - 2f);
475 path.LineTo(centerX, centerY + 2f);
476 path.LineTo(centerX + width / 2f, centerY - 2f);
478 backbuffer.
Canvas.DrawPath(path, paint);
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.
DirectDrawingMode Mode
Gets the coordinate mode shared by the composite and its children.
View? View
Gets the view to which this direct drawing is attached, or null if the drawing is in scene-layer mode...
SceneLayer? SceneLayer
Gets the scene layer to which this direct drawing is attached, or null if the drawing is in view mode...
SKCanvas Canvas
Gets the SkiaSharp canvas used for drawing operations on this backbuffer.
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.