summaryrefslogtreecommitdiff
path: root/src/ui/widget.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-10-29 14:10:20 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-10-29 14:10:20 +0200
commit0257f0b53d9a6baed3719159b721abdc31d44715 (patch)
tree60f16f89177d69718b621c75ad7c024eb42a6e5d /src/ui/widget.c
parentb12399bf941f9de46798e84a818c9cffded6debe (diff)
LabelWidget: Flag for wrapping text
Widgets now have an optional virtual method that gets called when the size of the widget changes during arranging. Wrapped text in LabelWidget uses this to update its height.
Diffstat (limited to 'src/ui/widget.c')
-rw-r--r--src/ui/widget.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/src/ui/widget.c b/src/ui/widget.c
index ea2e3fe2..d10d73e1 100644
--- a/src/ui/widget.c
+++ b/src/ui/widget.c
@@ -65,6 +65,10 @@ void destroyPending_Widget(void) {
65 } 65 }
66} 66}
67 67
68void releaseChildren_Widget(iWidget *d) {
69 iReleasePtr(&d->children);
70}
71
68iDefineObjectConstruction(Widget) 72iDefineObjectConstruction(Widget)
69 73
70void init_Widget(iWidget *d) { 74void init_Widget(iWidget *d) {
@@ -80,7 +84,7 @@ void init_Widget(iWidget *d) {
80} 84}
81 85
82void deinit_Widget(iWidget *d) { 86void deinit_Widget(iWidget *d) {
83 iReleasePtr(&d->children); 87 releaseChildren_Widget(d);
84 deinit_String(&d->id); 88 deinit_String(&d->id);
85} 89}
86 90
@@ -191,14 +195,29 @@ static int widestChild_Widget_(const iWidget *d) {
191static void setWidth_Widget_(iWidget *d, int width) { 195static void setWidth_Widget_(iWidget *d, int width) {
192 iAssert(width >= 0); 196 iAssert(width >= 0);
193 if (~d->flags & fixedWidth_WidgetFlag || d->flags & collapse_WidgetFlag) { 197 if (~d->flags & fixedWidth_WidgetFlag || d->flags & collapse_WidgetFlag) {
194 d->rect.size.x = width; 198 if (d->rect.size.x != width) {
199 d->rect.size.x = width;
200 if (class_Widget(d)->sizeChanged) {
201 const int oldHeight = d->rect.size.y;
202 class_Widget(d)->sizeChanged(d);
203 if (d->rect.size.y != oldHeight) {
204 /* Widget updated its height. */
205 arrange_Widget(d->parent);
206 }
207 }
208 }
195 } 209 }
196} 210}
197 211
198static void setHeight_Widget_(iWidget *d, int height) { 212static void setHeight_Widget_(iWidget *d, int height) {
199 iAssert(height >= 0); 213 iAssert(height >= 0);
200 if (~d->flags & fixedHeight_WidgetFlag || d->flags & collapse_WidgetFlag) { 214 if (~d->flags & fixedHeight_WidgetFlag || d->flags & collapse_WidgetFlag) {
201 d->rect.size.y = height; 215 if (d->rect.size.y != height) {
216 d->rect.size.y = height;
217 if (class_Widget(d)->sizeChanged) {
218 class_Widget(d)->sizeChanged(d);
219 }
220 }
202 } 221 }
203} 222}
204 223
@@ -274,7 +293,7 @@ void arrange_Widget(iWidget *d) {
274 iWidget *child = as_Widget(c.object); 293 iWidget *child = as_Widget(c.object);
275 if (isCollapsed_Widget_(child)) { 294 if (isCollapsed_Widget_(child)) {
276 if (d->flags & arrangeHorizontal_WidgetFlag) { 295 if (d->flags & arrangeHorizontal_WidgetFlag) {
277 setWidth_Widget_(child, 0); 296 setWidth_Widget_(child, 0);
278 } 297 }
279 if (d->flags & arrangeVertical_WidgetFlag) { 298 if (d->flags & arrangeVertical_WidgetFlag) {
280 setHeight_Widget_(child, 0); 299 setHeight_Widget_(child, 0);