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
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
28 RenderSurfaceHostBase renderSurfaceHost,
30 PointF anchor = default,
31 WidgetOrientation orientation = WidgetOrientation.Vertical,
32 float spacing = 0f,
33 string? nickname = null)
34 : base(
35 renderSurfaceHost,
36 mode,
37 anchor,
38 nickname)
39 {
40 _orientation = orientation;
41 Spacing = spacing;
42
43 IsInputEnabled = false;
46 CanReceiveFocus = false;
47 }
48
53 {
54 get => _orientation;
55 set
56 {
57 if (_orientation == value)
58 return;
59
60 _orientation = value;
61 Relayout();
62 }
63 }
64
68 public float Spacing
69 {
70 get => _spacing;
71 set
72 {
73 if (!float.IsFinite(value) || value < 0f)
74 throw new ArgumentOutOfRangeException(nameof(value));
75
76 _spacing = value;
77 Relayout();
78 }
79 }
80
84 public SizeF ContentSize => _contentSize;
85
92 {
93 ArgumentNullException.ThrowIfNull(widget);
94 Add(widget, keepCurrentOffset: false, explicitLocalOffsetPx: Vector2.Zero);
95 return this;
96 }
97
104 public StackPanelWidget RemoveWidget(WidgetBase widget, bool dispose = false)
105 {
106 ArgumentNullException.ThrowIfNull(widget);
107
108 if (RemoveChild(widget, dispose))
109 Relayout();
110
111 return this;
112 }
113
119 {
120 WidgetBase[] widgets = ChildWidgets.ToArray();
121 float cursor = 0f;
122 float cross = 0f;
123
124 for (int index = 0; index < widgets.Length; index++)
125 {
126 WidgetBase widget = widgets[index];
127
128 Rectangle bounds = Mode == DirectDrawingMode.View
129 ? widget.ScreenBounds
130 : widget.WorldBounds;
131
132 Vector2 offset = _orientation == WidgetOrientation.Vertical
133 ? new Vector2(0f, cursor)
134 : new Vector2(cursor, 0f);
135
136 SetLocalOffset(widget, offset);
137
138 if (_orientation == WidgetOrientation.Vertical)
139 {
140 cursor += bounds.Height;
141 cross = Math.Max(cross, bounds.Width);
142 }
143 else
144 {
145 cursor += bounds.Width;
146 cross = Math.Max(cross, bounds.Height);
147 }
148
149 if (index < widgets.Length - 1)
150 cursor += _spacing;
151 }
152
153 _contentSize = _orientation == WidgetOrientation.Vertical
154 ? new SizeF(cross, cursor)
155 : new SizeF(cursor, cross);
156
157 return this;
158 }
159
161 public override DirectComposite Add(
163 bool keepCurrentOffset = true,
164 Vector2? explicitLocalOffsetPx = null)
165 {
166 if (child is not WidgetBase)
167 throw new ArgumentException("StackPanelWidget accepts widget children only.", nameof(child));
168
169 DirectComposite result = base.Add(child, keepCurrentOffset, explicitLocalOffsetPx);
170 Relayout();
171 return result;
172 }
173
176 {
177 DirectComposite result = base.Remove(child);
178 Relayout();
179 return result;
180 }
181
183 public override DirectComposite Clear()
184 {
185 DirectComposite result = base.Clear();
186 Relayout();
187 return result;
188 }
189}
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.