Skip to content

Commit 73de6dd

Browse files
committed
[core] Fixed widget positioning logic in GUI containers.
Also added Update() implementation for GUI_Container
1 parent 18cce12 commit 73de6dd

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

include/SDL/SDL_gui.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ class GUI_Container : public GUI_Widget
574574
GUI_Container(const char *name, int x, int y, int w, int h);
575575
virtual ~GUI_Container(void);
576576

577+
virtual void Update(int force);
577578
int ContainsWidget(GUI_Widget *widget);
578579
void AddWidget(GUI_Widget *widget);
579580
virtual void RemoveWidget(GUI_Widget *widget);

lib/SDL_gui/Container.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ void GUI_Container::AddWidget(GUI_Widget *widget)
9797
SDL_Rect parea = widgets[n_widgets - 1]->GetArea();
9898

9999
if((parea.x + parea.w + warea.w) > area.w) {
100+
warea.x = 0;
100101
warea.y = parea.y + parea.h;
101102
} else {
102103
warea.x = parea.x + parea.w;
@@ -149,6 +150,7 @@ void GUI_Container::AddWidget(GUI_Widget *widget)
149150

150151
widgets[n_widgets++] = widget;
151152
UpdateLayout();
153+
MarkChanged();
152154
}
153155

154156
void GUI_Container::RemoveWidget(GUI_Widget *widget)
@@ -172,6 +174,7 @@ void GUI_Container::RemoveWidget(GUI_Widget *widget)
172174
}
173175
n_widgets = j;
174176
UpdateLayout();
177+
MarkChanged();
175178
}
176179

177180
void GUI_Container::RemoveAllWidgets()
@@ -186,6 +189,7 @@ void GUI_Container::RemoveAllWidgets()
186189

187190
n_widgets = 0;
188191
UpdateLayout();
192+
MarkChanged();
189193
}
190194

191195
void GUI_Container::UpdateLayout(void)
@@ -328,6 +332,29 @@ void GUI_Container::SetEnabled(int flag)
328332
MarkChanged();
329333
}
330334

335+
void GUI_Container::Update(int force)
336+
{
337+
if (flags & WIDGET_HIDDEN) return;
338+
339+
if (flags & WIDGET_CHANGED)
340+
{
341+
force = 1;
342+
flags &= ~WIDGET_CHANGED;
343+
}
344+
345+
if (force)
346+
{
347+
Erase(&area);
348+
}
349+
350+
for (int i = 0; i < n_widgets; i++)
351+
{
352+
if(IsVisibleWidget(widgets[i])) {
353+
widgets[i]->DoUpdate(force);
354+
}
355+
}
356+
}
357+
331358
extern "C"
332359
{
333360

0 commit comments

Comments
 (0)