Gondwana Game Engine Development (master) - 2.6.1
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
StackPanelWidget.cs
1using System.Drawing;
2using System.Numerics;
5
7
11public sealed class StackPanelWidget : ContainerWidget
12{
13 private WidgetOrientation _orientation;
14 private float _spacing;
15 private SizeF _contentSize;
16
27 public StackPanelWidget(RenderSurfaceHostBase renderSurfaceHost,
29 PointF anchor = default,
30 WidgetOrientation orientation = WidgetOrientation.Vertical,
31 float spacing = 0f,
32 string? nickname = null)
33 : base(renderSurfaceHost, mode, anchor, nickname)
34 {
35 _orientation = orientation;
36 Spacing = spacing;
37
38 IsInputEnabled = false;
41 CanReceiveFocus = false;
42 }
43
48 {
49 get => _orientation;
50 set
51 {
52 if (_orientation == value)
53 return;
54
55 _orientation = value;
56 Relayout();
57 }
58 }
59
63 public float Spacing
64 {
65 get => _spacing;
66 set
67 {
68 if (!float.IsFinite(value) || value < 0f)
69 throw new ArgumentOutOfRangeException(nameof(value));
70
71 _spacing = value;
72 Relayout();
73 }
74 }
75
79 public SizeF ContentSize => _contentSize;
80
87 {
88 ArgumentNullException.ThrowIfNull(widget);
89 Add(widget, keepCurrentOffset: false, explicitLocalOffsetPx: Vector2.Zero);
90 return this;
91 }
92
99 public StackPanelWidget RemoveWidget(WidgetBase widget, bool dispose = false)
100 {
101 ArgumentNullException.ThrowIfNull(widget);
102
103 if (RemoveChild(widget, dispose))
104 Relayout();
105
106 return this;
107 }
108
114 {
115 WidgetBase[] widgets = ChildWidgets.ToArray();
116 float cursor = 0f;
117 float cross = 0f;
118
119 for (int index = 0; index < widgets.Length; index++)
120 {
121 WidgetBase widget = widgets[index];
122 Rectangle bounds = Mode == DirectDrawingMode.View
123 ? widget.ScreenBounds
124 : widget.WorldBounds;
125
126 Vector2 offset = _orientation == WidgetOrientation.Vertical
127 ? new Vector2(0f, cursor)
128 : new Vector2(cursor, 0f);
129
130 SetLocalOffset(widget, offset);
131
132 if (_orientation == WidgetOrientation.Vertical)
133 {
134 cursor += bounds.Height;
135 cross = Math.Max(cross, bounds.Width);
136 }
137 else
138 {
139 cursor += bounds.Width;
140 cross = Math.Max(cross, bounds.Height);
141 }
142
143 if (index < widgets.Length - 1)
144 cursor += _spacing;
145 }
146
147 _contentSize = _orientation == WidgetOrientation.Vertical
148 ? new SizeF(cross, cursor)
149 : new SizeF(cursor, cross);
150
151 return this;
152 }
153
156 bool keepCurrentOffset = true,
157 Vector2? explicitLocalOffsetPx = null)
158 {
159 if (child is not WidgetBase)
160 throw new ArgumentException("StackPanelWidget accepts widget children only.", nameof(child));
161
162 DirectComposite result = base.Add(child, keepCurrentOffset, explicitLocalOffsetPx);
163 Relayout();
164 return result;
165 }
166
169 {
170 DirectComposite result = base.Remove(child);
171 Relayout();
172 return result;
173 }
174
176 public override DirectComposite Clear()
177 {
178 DirectComposite result = base.Clear();
179 Relayout();
180 return result;
181 }
182}
DirectComposite SetLocalOffset(IDirectCompositeChild child, Vector2 newLocalOffsetPx)
Changes one child's local offset and reapplies its position.
Rectangle WorldBounds
Gets the union of all visible descendants' world-space bounds.
DirectComposite(RenderSurfaceHostBase renderSurfaceHost, DirectDrawingMode mode, PointF anchor=default, string? nickname=null)
Initializes a new instance of the DirectComposite class.
DirectDrawingMode Mode
Gets the coordinate mode shared by the composite and its children.
Represents a base class for hosting a render surface, providing functionality for managing rendering ...
bool RemoveChild(WidgetBase widget, bool dispose=false)
Removes a child widget from the container.
ContainerWidget(RenderSurfaceHostBase renderSurfaceHost, DirectDrawingMode mode, PointF anchor=default, string? nickname=null)
Initializes a new instance of the ContainerWidget class.
IReadOnlyList< WidgetBase > ChildWidgets
Gets a snapshot of the child widgets directly owned by this container.
float Spacing
Gets or sets the number of pixels placed between adjacent child widgets.
SizeF ContentSize
Gets the current laid-out content size.
override DirectComposite Add(IDirectCompositeChild child, bool keepCurrentOffset=true, Vector2? explicitLocalOffsetPx=null)
Adds a composite-compatible direct drawable as a child.The current composite.
StackPanelWidget AddWidget(WidgetBase widget)
Adds a child widget and immediately recalculates layout.
override DirectComposite Remove(IDirectCompositeChild child)
Removes a child without disposing it.The current composite.
StackPanelWidget(RenderSurfaceHostBase renderSurfaceHost, DirectDrawingMode mode, PointF anchor=default, WidgetOrientation orientation=WidgetOrientation.Vertical, float spacing=0f, string? nickname=null)
Creates a stack panel in the supplied drawing mode. The first child establishes the view or scene-lay...
WidgetOrientation Orientation
Gets or sets the stacking direction.
StackPanelWidget Relayout()
Recalculates every child offset from the current orientation and spacing.
StackPanelWidget RemoveWidget(WidgetBase widget, bool dispose=false)
Removes a child widget and immediately recalculates layout.
override DirectComposite Clear()
Removes every child without disposing them.The current composite.
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(RenderSurfaceHostBase renderSurfaceHost, DirectDrawingMode mode, PointF anchor=default, string? nickname=null)
Initializes a new instance of the WidgetBase class.
Definition WidgetBase.cs:95
bool IsKeyboardInputEnabled
Gets or sets a value indicating whether the widget can receive keyboard input.
bool IsInputEnabled
Gets or sets a value indicating whether the widget can participate in input routing.
Defines a movable direct drawable that may be owned by a DirectComposite.
DirectDrawingMode
Specifies where direct drawing operations are applied within the rendering pipeline.
@ View
Performs direct drawing at the view level using screen-space coordinates.
WidgetOrientation
Defines the primary layout or fill direction used by widgets.
@ Vertical
Arranges content from top to bottom or fills progress from bottom to top.