Gondwana Game Engine Development (master) - 2.7.0
Gondwana is a cross-platform 2.5D game and rendering engine written in C#/.NET 8. It provides fine-grained control over rendering, timing, and scene composition, with built-in support for parallax, z-ordering, pixel overhang, collision detection, and particle effects. Gondwana targets desktop and web platforms using SkiaSharp for graphics and pluggable audio backends for desktop and browser targets.
Loading...
Searching...
No Matches
MenuDropDownWidget.cs
1using System.Drawing;
2using System.Numerics;
6using SkiaSharp;
7
9
13public sealed class MenuDropDownWidget : ContainerWidget
14{
15 private readonly MenuBarTheme _theme;
16 private readonly MenuBarWidget _bar;
17 private int _zOrder;
18 private int _minimumWidth;
19 internal MenuItemWidget? ParentItem { get; private set; }
20 internal MenuDropDownWidget? ParentMenu { get; private set; }
21 internal MenuDropDownWidget? OpenChild { get; private set; }
22 internal MenuDropDownWidget ActiveMenu => OpenChild?.ActiveMenu ?? this;
23
24 internal MenuItemWidget? SelectedItem =>
25 _selectedIndex >= 0 && _selectedIndex < _items.Count ? _items[_selectedIndex] : null;
26
27 internal bool CanInvoke => !_disposed && _bar.IsAvailable && (ParentItem?.CanInvoke ?? true);
28 private readonly List<Entry> _entries = new();
29 private readonly List<MenuItemWidget> _items = new();
30
31 private EventHandler<DirectDrawingBase>? _closeCompletionHandler;
32 private int _nextChildNicknameSuffix;
33 private int _selectedIndex = -1;
34 private bool _disposed;
35
36 internal MenuDropDownWidget(
38 View view,
39 Point location,
40 MenuBarTheme theme,
41 string? nickname,
42 MenuBarWidget bar)
43 : base(
44 host,
46 location,
47 nickname)
48 {
49 _bar = bar;
50 _theme = theme ?? throw new ArgumentNullException(nameof(theme));
51 _minimumWidth = Width = Math.Max(_theme.MinimumDropDownWidth, _theme.DefaultDropDownWidth);
52
54 _theme.DropDownBackgroundColor,
55 host,
56 view,
57 new Rectangle(
58 location.X,
59 location.Y,
60 Width,
61 1),
62 $"{Nickname}.panel")
63 .SetFilled(true)
64 .SetBorderColor(_theme.DropDownBorderColor)
65 .SetStrokeWidth(_theme.BorderWidth)
66 .SetCornerRadius(_theme.CornerRadius);
67
68 Panel.HideWhenFullyTransparent = false;
69 Add(Panel);
70
73 CanReceiveFocus = false;
74
75 RecalculateLayout();
76 Hide();
77 }
78
80 public DirectRectangle Panel { get; }
81
83 public IReadOnlyList<MenuItemWidget> Items => _items.AsReadOnly();
84
86 public int Width { get; private set; }
87
89 public int Height { get; private set; }
90
92 public bool IsOpen { get; private set; }
93
95 public int SelectedIndex => _selectedIndex;
96
107 public MenuDropDownWidget AddItem(
108 string text,
109 Action? action = null,
110 string? shortcutText = null,
111 bool enabled = true,
112 string? key = null,
113 KeyGesture? shortcut = null,
114 char? mnemonic = null,
115 SKImage? icon = null)
116 {
117 AddEntry(
118 text,
119 action,
120 shortcutText,
121 enabled,
122 key,
123 shortcut,
124 mnemonic,
125 icon);
126
127 return this;
128 }
129
140 public MenuDropDownWidget AddCheckItem(
141 string text,
142 Action<bool>? action = null,
143 bool isChecked = false,
144 bool enabled = true,
145 string? key = null,
146 KeyGesture? shortcut = null,
147 char? mnemonic = null,
148 SKImage? icon = null)
149 {
150 AddEntry(
151 text,
152 null,
153 null,
154 enabled,
155 key,
156 shortcut,
157 mnemonic,
158 icon,
159 checkable: true,
160 checkedAction: action).SetChecked(isChecked);
161
162 return this;
163 }
164
176 public MenuDropDownWidget AddRadioItem(
177 string text,
178 Action? action,
179 string group,
180 bool isChecked = false,
181 bool enabled = true,
182 string? key = null,
183 KeyGesture? shortcut = null,
184 char? mnemonic = null,
185 SKImage? icon = null)
186 {
187 ArgumentException.ThrowIfNullOrWhiteSpace(group);
188
189 AddEntry(
190 text,
191 action,
192 null,
193 enabled,
194 key,
195 shortcut,
196 mnemonic,
197 icon,
198 checkable: true,
199 radioGroup: group).SetChecked(isChecked);
200
201 return this;
202 }
203
212 public MenuDropDownWidget AddSubMenu(
213 string text,
214 Action<MenuDropDownWidget> configure,
215 bool enabled = true,
216 string? key = null,
217 char? mnemonic = null,
218 SKImage? icon = null)
219 {
220 ArgumentNullException.ThrowIfNull(configure);
221
222 ValidateEntry(
223 text,
224 key,
225 null,
226 mnemonic);
227
228 var child = new MenuDropDownWidget(
230 View!,
231 Point.Empty,
232 _theme,
233 CreateChildNickname("submenu"),
234 _bar);
235
236 try
237 {
238 configure(child);
239
240 var item = AddEntry(
241 text,
242 null,
243 null,
244 enabled,
245 key,
246 null,
247 mnemonic,
248 icon,
249 subMenu: child);
250
251 child.ParentMenu = this;
252 child.ParentItem = item;
253 Add(child, Vector2.Zero);
254 child.CloseAnimated(MenuDropDownAnimation.None, 0, immediate: true);
255 child.SetDropDownZOrder(_zOrder + 10);
256 }
257 catch
258 {
259 child.Dispose();
260 throw;
261 }
262
263 return this;
264 }
265
266 private void ValidateEntry(
267 string text,
268 string? key,
269 KeyGesture? shortcut,
270 char? mnemonic)
271 {
272 ObjectDisposedException.ThrowIf(_disposed, this);
273 ArgumentNullException.ThrowIfNull(text);
274 _bar.ValidateRegistration(key, shortcut);
275
276 if (mnemonic is char character && _items.Any(item =>
277 item.Mnemonic is char existing && char.ToUpperInvariant(existing) == char.ToUpperInvariant(character)))
278 throw new ArgumentException($"Duplicate menu mnemonic '{character}'.", nameof(mnemonic));
279 }
280
281 private MenuItemWidget AddEntry(
282 string text,
283 Action? action,
284 string? shortcutText,
285 bool enabled,
286 string? key,
287 KeyGesture? shortcut,
288 char? mnemonic,
289 SKImage? icon,
290 bool checkable = false,
291 string? radioGroup = null,
292 Action<bool>? checkedAction = null,
293 MenuDropDownWidget? subMenu = null)
294 {
295 ValidateEntry(
296 text,
297 key,
298 shortcut,
299 mnemonic);
300
301 var anchor = Point.Round(new PointF(GetPosition().X, GetPosition().Y));
302
303 var item = new MenuItemWidget(
305 View!,
306 new Rectangle(
307 anchor.X,
308 anchor.Y,
309 Width,
310 _theme.ItemHeight),
311 text,
312 shortcutText,
313 action,
314 _theme,
315 CreateChildNickname("item"),
316 this,
317 key,
318 shortcut,
319 mnemonic,
320 icon,
321 checkable,
322 radioGroup,
323 checkedAction,
324 subMenu);
325
326 item.SetEnabled(enabled);
327 item.Hovered += OnItemHovered;
328 _items.Add(item);
329 _entries.Add(Entry.ForItem(item));
330 Add(item, Vector2.Zero);
331 _bar.RegisterItem(item);
332
333 if (!IsOpen)
334 {
335 item.ApplyInputState(false);
336 item.Hide();
337 }
338
339 RecalculateLayout();
340 SetDropDownZOrder(_zOrder);
341 return item;
342 }
343
344 internal void UncheckRadioPeers(MenuItemWidget selected)
345 {
346 foreach (var item in _items)
347 if (!ReferenceEquals(item, selected) && item.RadioGroup == selected.RadioGroup && item.IsChecked)
348 item.SetChecked(false);
349 }
350
351 private string CreateChildNickname(string kind) => $"{Nickname}.{kind}.{_nextChildNicknameSuffix++}";
352
353 internal void UnregisterItem(MenuItemWidget item)
354 {
355 _bar.UnregisterItem(item);
356
357 if (_disposed)
358 return;
359
360 OnItemDisabled(item);
361 item.SubMenu?.Dispose();
362 item.Hovered -= OnItemHovered;
363 _items.Remove(item);
364 _entries.RemoveAll(entry => ReferenceEquals(entry.Item, item));
365 _selectedIndex = -1;
366
367 foreach (var remaining in _items)
368 remaining.SetSelected(false);
369
370 RecalculateLayout();
371 }
372
373 internal void OnItemDisabled(MenuItemWidget item)
374 {
375 if (item.SubMenu is not null && ReferenceEquals(OpenChild, item.SubMenu))
376 CloseChild();
377
378 if (ReferenceEquals(SelectedItem, item))
379 SetSelectedIndex(-1);
380 }
381
382 internal void NotifyInvoked(MenuItemWidget item) => _bar.OnItemInvoked(item);
383
384 internal void OpenSubMenu(MenuItemWidget item, bool selectFirst)
385 {
386 if (!IsOpen || !item.CanInvoke || item.SubMenu is not { } child)
387 return;
388
389 SetSelectedIndex(_items.IndexOf(item));
390
391 if (!ReferenceEquals(OpenChild, child))
392 {
393 CloseChild();
394 var viewport = View!.Viewport.TargetRectPx;
395 var row = item.Background.ScreenBounds;
396 int x = Panel.ScreenBounds.Right + _theme.SubMenuGap;
397
398 if (x + child.Width > viewport.Right)
399 x = Panel.ScreenBounds.Left - child.Width - _theme.SubMenuGap;
400
401 x = Math.Clamp(x, viewport.Left, Math.Max(viewport.Left, viewport.Right - child.Width));
402 int y = Math.Clamp(row.Top, viewport.Top, Math.Max(viewport.Top, viewport.Bottom - child.Height));
403 SetLocalOffset(child, new Vector2(x - GetPosition().X, y - GetPosition().Y));
404 OpenChild = child;
405 child.OpenAnimated(_bar.DropDownAnimation, Math.Max(0, _bar.DropDownAnimationDurationSec));
406 child.Activate();
407 }
408
409 if (selectFirst)
410 child.SelectFirstEnabled();
411 }
412
413 internal void CloseChild()
414 {
415 var child = OpenChild;
416 OpenChild = null;
417 child?.CloseAnimated(MenuDropDownAnimation.None, 0, immediate: true);
418 }
419
421 protected override void ProcessShown()
422 {
423 base.ProcessShown();
424
425 foreach (var item in _items)
426 item.SubMenu?.CloseAnimated(MenuDropDownAnimation.None, 0, immediate: true);
427 }
428
430 protected override void ProcessHidden()
431 {
432 CloseChild();
433 IsOpen = false;
434 SetEntryInputEnabled(false);
435 CancelPendingClose();
436 CancelVisualFades();
437 base.ProcessHidden();
438 }
439
442 public MenuDropDownWidget AddSeparator()
443 {
444 ObjectDisposedException.ThrowIf(_disposed, this);
445 Point anchor = Point.Round(new PointF(GetPosition().X, GetPosition().Y));
446
447 var separator = new DirectRectangle(
448 _theme.SeparatorColor,
450 View!,
451 new Rectangle(
452 anchor.X,
453 anchor.Y,
454 1,
455 1),
456 CreateChildNickname("separator"))
457 .SetFilled(true)
458 .SetStrokeWidth(0f);
459
460 separator.HideWhenFullyTransparent = false;
461 _entries.Add(Entry.ForSeparator(separator));
462 Add(separator, keepCurrentOffset: false, explicitLocalOffsetPx: Vector2.Zero);
463 separator.Visible = IsOpen;
464 separator.ZOrder = _zOrder + 2;
465
466 RecalculateLayout();
467 return this;
468 }
469
473 public MenuDropDownWidget SetWidth(int width)
474 {
475 ObjectDisposedException.ThrowIf(_disposed, this);
476
477 if (width < _theme.MinimumDropDownWidth)
478 {
479 throw new ArgumentOutOfRangeException(
480 nameof(width),
481 width,
482 $"Menu dropdown width must be at least {_theme.MinimumDropDownWidth} pixels.");
483 }
484
485 _minimumWidth = width;
486 RecalculateLayout();
487 return this;
488 }
489
490 internal void OpenAnimated(
491 MenuDropDownAnimation animation,
492 float durationSec)
493 {
494 CancelPendingClose();
495
496 if (!Visible)
497 Show();
498
500 IsOpen = true;
501 SetEntryInputEnabled(true);
502
503 PrepareVisualsForAnimation();
504
505 if (animation == MenuDropDownAnimation.None || durationSec <= 0f)
506 {
507 SetOpacity(1f);
508 SetRevealProgress(1f);
509 return;
510 }
511
512 SetOpacity(0f);
513 SetRevealProgress(animation == MenuDropDownAnimation.FadeAndReveal ? 0f : 1f);
514
515 foreach (var visual in EnumerateVisuals())
516 visual.FadeIn(durationSec);
517
518 if (animation == MenuDropDownAnimation.FadeAndReveal)
519 {
520 foreach (DirectDrawingBase visual in EnumerateVisuals())
521 {
523 .RevealTo(1f, durationSec, EaseOutCubic);
524 }
525 }
526 }
527
528 internal void CloseAnimated(
529 MenuDropDownAnimation animation,
530 float durationSec,
531 bool immediate = false)
532 {
533 CloseChild();
534 IsOpen = false;
535 IsPointerInputEnabled = false;
536 SetEntryInputEnabled(false);
537 SetSelectedIndex(-1);
538 CancelPendingClose();
539
540 if (immediate || animation == MenuDropDownAnimation.None || durationSec <= 0f)
541 {
542 CancelVisualFades();
543 SetOpacity(1f);
544 SetRevealProgress(1f);
545
546 if (Visible)
547 Hide();
548
549 return;
550 }
551
552 _closeCompletionHandler = (_, _) =>
553 {
554 CancelPendingClose();
555
556 if (Visible)
557 Hide();
558 };
559
560 Panel.FadeToCompleted += _closeCompletionHandler;
561
562 // Closing is a clean fade. Any in-progress opening reveal is snapped
563 // fully open so it cannot continue unfolding while disappearing.
564 SetRevealProgress(1f);
565
566 foreach (var visual in EnumerateVisuals())
567 visual.FadeOut(durationSec);
568 }
569
570 internal void SetDropDownZOrder(int zOrder)
571 {
572 _zOrder = zOrder;
573 Panel.ZOrder = zOrder;
574
575 foreach (var item in _items)
576 item.SubMenu?.SetDropDownZOrder(zOrder + 10);
577
578 foreach (Entry entry in _entries)
579 {
580 if (entry.Item is not null)
581 entry.Item.SetItemZOrder(zOrder + 1);
582 else if (entry.Separator is not null)
583 entry.Separator.ZOrder = zOrder + 2;
584 }
585 }
586
587 internal void SelectFirstEnabled()
588 {
589 SetSelectedIndex(FindNextEnabledIndex(-1, 1));
590 }
591
592 internal void SelectNextEnabled()
593 {
594 SetSelectedIndex(FindNextEnabledIndex(_selectedIndex, 1));
595 }
596
597 internal void SelectPreviousEnabled()
598 {
599 int start = _selectedIndex < 0 ? _items.Count : _selectedIndex;
600 SetSelectedIndex(FindNextEnabledIndex(start, -1));
601 }
602
603 internal void InvokeSelectedItem()
604 {
605 if (_selectedIndex < 0 || _selectedIndex >= _items.Count)
606 return;
607
608 _items[_selectedIndex].PerformClick();
609 }
610
612 public override void Dispose()
613 {
614 if (_disposed)
615 return;
616
617 _disposed = true;
618 CloseChild();
619 CancelPendingClose();
620 CancelVisualFades();
621 IsOpen = false;
622
623 foreach (MenuItemWidget item in _items)
624 {
625 item.Hovered -= OnItemHovered;
626 }
627
628 base.Dispose();
629 }
630
631 private void RecalculateLayout()
632 {
633 int markerWidth = _items.Any(item => item.IsCheckable) ? _theme.MarkerColumnWidth : 0;
634 int iconWidth = _items.Any(item => item.Icon is not null) ? _theme.IconSize + _theme.IconGap : 0;
635 int arrowWidth = _items.Any(item => item.SubMenu is not null) ? _theme.SubMenuArrowWidth : 0;
636 int shortcutWidth = _items.Select(item => MeasureText(item.ShortcutText)).DefaultIfEmpty().Max();
637 int labelWidth = _items.Select(item => MeasureText(item.Text)).DefaultIfEmpty().Max();
638
639 Width = Math.Max(
640 _minimumWidth,
641 markerWidth + iconWidth + arrowWidth + shortcutWidth + labelWidth +
642 (shortcutWidth > 0 ? _theme.ShortcutGap : 0) +
643 2 * (_theme.DropDownHorizontalPadding + _theme.ItemHorizontalPadding));
644
645 int y = _theme.DropDownVerticalPadding;
646
647 foreach (Entry entry in _entries)
648 {
649 if (entry.Item is not null)
650 {
651 var offset = new Vector2(_theme.DropDownHorizontalPadding, y);
652 SetLocalOffset(entry.Item, offset);
653
654 Point position = Point.Round(
655 new PointF(
656 GetPosition().X + offset.X,
657 GetPosition().Y + offset.Y));
658
659 entry.Item.SetBounds(
660 new Rectangle(
661 position.X,
662 position.Y,
663 Width - (_theme.DropDownHorizontalPadding * 2),
664 _theme.ItemHeight),
665 markerWidth,
666 iconWidth,
667 shortcutWidth,
668 arrowWidth);
669
670 y += _theme.ItemHeight;
671 continue;
672 }
673
674 if (entry.Separator is not null)
675 {
676 int lineX = _theme.DropDownHorizontalPadding + 5;
677 int lineY = y + (_theme.SeparatorHeight / 2);
678 var offset = new Vector2(lineX, lineY);
679
680 SetLocalOffset(entry.Separator, offset);
681
682 Point position = Point.Round(
683 new PointF(
684 GetPosition().X + offset.X,
685 GetPosition().Y + offset.Y));
686
687 entry.Separator.ScreenBounds = new Rectangle(
688 position.X,
689 position.Y,
690 Math.Max(1, Width - (lineX * 2)),
691 1);
692
693 y += _theme.SeparatorHeight;
694 }
695 }
696
697 Height = Math.Max(1, y + _theme.DropDownVerticalPadding);
698
699 Point panelPosition = Point.Round(new PointF(GetPosition().X, GetPosition().Y));
700
701 Panel.ScreenBounds = new Rectangle(
702 panelPosition.X,
703 panelPosition.Y,
704 Width,
705 Height);
706 }
707
708 private void SetEntryInputEnabled(bool menuAcceptsInput)
709 {
710 foreach (MenuItemWidget item in _items)
711 item.ApplyInputState(menuAcceptsInput);
712 }
713
714 private void SetSelectedIndex(int index)
715 {
716 if (index < -1 || index >= _items.Count)
717 index = -1;
718
719 if (_selectedIndex == index)
720 return;
721
722 if (_selectedIndex >= 0 && _selectedIndex < _items.Count)
723 _items[_selectedIndex].SetSelected(false);
724
725 CloseChild();
726 _selectedIndex = index;
727
728 if (_selectedIndex >= 0)
729 _items[_selectedIndex].SetSelected(true);
730 }
731
732 private int FindNextEnabledIndex(int startIndex, int direction)
733 {
734 if (_items.Count == 0)
735 return -1;
736
737 int index = startIndex;
738
739 for (int attempt = 0; attempt < _items.Count; attempt++)
740 {
741 index = (index + direction + _items.Count) % _items.Count;
742
743 if (_items[index].CanInvoke)
744 return index;
745 }
746
747 return -1;
748 }
749
750 private void OnItemHovered(MenuItemWidget item)
751 {
752 int index = _items.IndexOf(item);
753
754 if (index >= 0)
755 {
756 SetSelectedIndex(index);
757
758 if (item.SubMenu is not null)
759 OpenSubMenu(item, selectFirst: false);
760 }
761 }
762
763 private int MeasureText(string text)
764 {
765 using var font = new SKFont(SKTypeface.Default, _theme.FontSize);
766 return (int)Math.Ceiling(font.MeasureText(text));
767 }
768
769 private void PrepareVisualsForAnimation()
770 {
771 foreach (DirectDrawingBase visual in EnumerateVisuals())
772 {
773 visual.CancelFade();
774 visual.HideWhenFullyTransparent = false;
775 }
776 }
777
778 private void CancelVisualFades()
779 {
780 foreach (DirectDrawingBase visual in EnumerateVisuals())
781 visual.CancelFade().CancelReveal();
782 }
783
784 private void SetRevealProgress(float progress)
785 {
786 foreach (DirectDrawingBase visual in EnumerateVisuals())
787 {
788 visual.CancelReveal()
789 .SetRevealDirection(DirectDrawingBase.RevealDirection.TopToBottom)
790 .SetReveal(progress);
791 }
792 }
793
794 private IEnumerable<DirectDrawingBase> EnumerateVisuals()
795 {
796 return EnumerateVisuals(this);
797 }
798
799 private static IEnumerable<DirectDrawingBase> EnumerateVisuals(IDirectCompositeContainer container)
800 {
801 foreach (IDirectCompositeChild child in container.Children)
802 {
803 if (child is DirectDrawingBase drawing)
804 yield return drawing;
805
806 if (child is IDirectCompositeContainer nestedContainer && child is not MenuDropDownWidget)
807 {
808 foreach (DirectDrawingBase nestedDrawing in EnumerateVisuals(nestedContainer))
809 yield return nestedDrawing;
810 }
811 }
812 }
813
814 private void CancelPendingClose()
815 {
816 if (_closeCompletionHandler is null)
817 return;
818
819 Panel.FadeToCompleted -= _closeCompletionHandler;
820 _closeCompletionHandler = null;
821 }
822
823 private static float EaseOutCubic(float t)
824 {
825 float inverse = 1f - t;
826 return 1f - (inverse * inverse * inverse);
827 }
828
829 private sealed class Entry
830 {
831 private Entry(
832 MenuItemWidget? item,
833 DirectRectangle? separator)
834 {
835 Item = item;
836 Separator = separator;
837 }
838
839 internal MenuItemWidget? Item { get; }
840 internal DirectRectangle? Separator { get; }
841
842 internal static Entry ForItem(MenuItemWidget item) => new(item, null);
843 internal static Entry ForSeparator(DirectRectangle separator) => new(null, separator);
844 }
845}
bool Visible
Gets or sets the visibility of all descendants.
RenderSurfaceHostBase RenderSurfaceHost
Gets the render surface host shared by the composite and its children.
DirectComposite SetOpacity(float opacity)
Applies one opacity to every descendant.
DirectComposite SetLocalOffset(IDirectCompositeChild child, Vector2 newLocalOffsetPx)
Changes one child's local offset and reapplies its position.
View? View
Gets the view shared by all children in view mode.
Vector2 GetPosition()
Gets the current composite anchor.
Provides the base implementation for direct drawing objects that can be rendered to the backbuffer wi...
DirectDrawingBase SetRevealDirection(RevealDirection dir)
Sets the direction from which the reveal animation progresses.
DirectDrawingBase CancelReveal()
Stops an active reveal animation at its current progress.
DirectDrawingBase RevealTo(float t01, float durationSec, Func< float, float >? easing=null)
Initiates a smooth reveal animation to the specified target progress over the given duration,...
DirectDrawingBase SetReveal(float t01)
Instantly sets the reveal progress to the specified value without animation.
DirectDrawingBase CancelFade()
Cancels any active fade transition, leaving the opacity at its current value.
RevealDirection
Defines the direction from which a reveal animation progressively displays the direct drawing.
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 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.
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...
Definition View.cs:14
override DirectComposite Add(IDirectCompositeChild child, bool keepCurrentOffset=true, Vector2? explicitLocalOffsetPx=null)
Adds a composite-compatible direct drawable as a child.The current composite.
ContainerWidget(RenderSurfaceHostBase renderSurfaceHost, DirectDrawingMode mode, PointF anchor=default, string? nickname=null)
Initializes a new instance of the ContainerWidget class.
Provides a view-level menu bar with animated dropdown command lists.
DirectRectangle Panel
Gets the popup panel drawing.
MenuDropDownWidget AddSubMenu(string text, Action< MenuDropDownWidget > configure, bool enabled=true, string? key=null, char? mnemonic=null, SKImage? icon=null)
Adds an owned submenu. Submenus may themselves contain submenus to any depth.
MenuDropDownWidget SetWidth(int width)
Sets a fixed minimum width for this dropdown.
bool IsOpen
Gets whether this dropdown accepts input. False while its close animation finishes.
MenuDropDownWidget AddCheckItem(string text, Action< bool >? action=null, bool isChecked=false, bool enabled=true, string? key=null, KeyGesture? shortcut=null, char? mnemonic=null, SKImage? icon=null)
Adds a check item. Invocation toggles state before passing the resulting value to the callback.
override void ProcessShown()
Performs processing when the widget is shown before notification callbacks are invoked.
IReadOnlyList< MenuItemWidget > Items
Gets the actionable entries in insertion order.
int Width
Gets the current popup width.
MenuDropDownWidget AddRadioItem(string text, Action? action, string group, bool isChecked=false, bool enabled=true, string? key=null, KeyGesture? shortcut=null, char? mnemonic=null, SKImage? icon=null)
Adds a radio command. Group names are scoped to this dropdown; the last checked item wins.
override void Dispose()
Disposes the composite and every child it owns.
int SelectedIndex
Gets the selected actionable-item index, or -1.
MenuDropDownWidget AddItem(string text, Action? action=null, string? shortcutText=null, bool enabled=true, string? key=null, KeyGesture? shortcut=null, char? mnemonic=null, SKImage? icon=null)
Adds a command, preserving fluent construction. Gesture text overrides display-only shortcutText.
override void ProcessHidden()
Performs processing when the widget is hidden before notification callbacks are invoked.
MenuDropDownWidget AddSeparator()
Adds a visual separator.
int Height
Gets the current popup height.
A command, check/radio item, or submenu owner in a menu dropdown.
string Text
Gets the command label.
bool IsCheckable
Gets whether this item has check or radio state.
string ShortcutText
Gets gesture-generated text, or the legacy display-only shortcut text.
MenuDropDownWidget? SubMenu
Gets the child dropdown, if this item owns a submenu.
SKImage? Icon
Gets the caller-owned image. Keep it alive until the item is disposed.
WidgetBase Show()
Shows the widget and registers it for input routing.
bool CanReceiveFocus
Gets or sets a value indicating whether the widget can receive keyboard focus.
bool IsPointerInputEnabled
Gets or sets a value indicating whether the widget can receive pointer input.
WidgetBase Hide()
Hides the widget and releases any routed input state.
bool IsKeyboardInputEnabled
Gets or sets a value indicating whether the widget can receive keyboard input.
IReadOnlyCollection< IDirectCompositeChild > Children
Gets the read-only collection of child elements in this container.
DirectDrawingMode
Specifies where direct drawing operations are applied within the rendering pipeline.
MenuDropDownAnimation
Specifies how a menu dropdown is animated when opened or closed.
record MenuBarTheme
Defines the dimensions and colors used by menu bar widgets.
A host key code and an exact combination of keyboard modifiers.
Definition KeyGesture.cs:9