summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-12-14 16:43:10 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-12-14 16:43:10 +0200
commit0ea78766ba6d189cb70c94acc798c4f4c74be935 (patch)
tree2e6ef15e787016a44d03db9f3b363eb8b3d48d0e /src
parent649986b3832403f119a0a615c74c31a158bec646 (diff)
Widget: More efficient size change notifications
Only notify once, after the arrangement is done.
Diffstat (limited to 'src')
-rw-r--r--src/ui/widget.c26
-rw-r--r--src/ui/widget.h1
2 files changed, 21 insertions, 6 deletions
diff --git a/src/ui/widget.c b/src/ui/widget.c
index 0c3b1c8a..8cb2cf02 100644
--- a/src/ui/widget.c
+++ b/src/ui/widget.c
@@ -126,6 +126,7 @@ void init_Widget(iWidget *d) {
126 d->flags = 0; 126 d->flags = 0;
127 d->flags2 = 0; 127 d->flags2 = 0;
128 d->rect = zero_Rect(); 128 d->rect = zero_Rect();
129 d->oldSize = zero_I2();
129 d->minSize = zero_I2(); 130 d->minSize = zero_I2();
130 d->sizeRef = NULL; 131 d->sizeRef = NULL;
131 d->offsetRef = NULL; 132 d->offsetRef = NULL;
@@ -420,9 +421,10 @@ static iBool setWidth_Widget_(iWidget *d, int width) {
420 if (d->rect.size.x != width) { 421 if (d->rect.size.x != width) {
421 d->rect.size.x = width; 422 d->rect.size.x = width;
422 TRACE(d, "width has changed to %d", width); 423 TRACE(d, "width has changed to %d", width);
423 if (class_Widget(d)->sizeChanged) { 424// if (~d->flags2 & undefinedWidth_WidgetFlag2 && class_Widget(d)->sizeChanged) {
424 class_Widget(d)->sizeChanged(d); 425// class_Widget(d)->sizeChanged(d);
425 } 426// }
427// d->flags2 &= ~undefinedWidth_WidgetFlag2;
426 return iTrue; 428 return iTrue;
427 } 429 }
428 } 430 }
@@ -443,9 +445,10 @@ static iBool setHeight_Widget_(iWidget *d, int height) {
443 if (d->rect.size.y != height) { 445 if (d->rect.size.y != height) {
444 d->rect.size.y = height; 446 d->rect.size.y = height;
445 TRACE(d, "height has changed to %d", height); 447 TRACE(d, "height has changed to %d", height);
446 if (class_Widget(d)->sizeChanged) { 448// if (~d->flags2 & undefinedHeight_WidgetFlag2 && class_Widget(d)->sizeChanged) {
447 class_Widget(d)->sizeChanged(d); 449// class_Widget(d)->sizeChanged(d);
448 } 450// }
451// d->flags2 &= ~undefinedHeight_WidgetFlag2;
449 return iTrue; 452 return iTrue;
450 } 453 }
451 } 454 }
@@ -842,6 +845,7 @@ static void arrange_Widget_(iWidget *d) {
842} 845}
843 846
844static void resetArrangement_Widget_(iWidget *d) { 847static void resetArrangement_Widget_(iWidget *d) {
848 d->oldSize = d->rect.size;
845 if (d->flags & resizeToParentWidth_WidgetFlag) { 849 if (d->flags & resizeToParentWidth_WidgetFlag) {
846 d->rect.size.x = 0; 850 d->rect.size.x = 0;
847 } 851 }
@@ -878,6 +882,15 @@ static void resetArrangement_Widget_(iWidget *d) {
878 } 882 }
879} 883}
880 884
885static void notifySizeChanged_Widget_(iWidget *d) {
886 if (class_Widget(d)->sizeChanged && !isEqual_I2(d->rect.size, d->oldSize)) {
887 class_Widget(d)->sizeChanged(d);
888 }
889 iForEach(ObjectList, child, d->children) {
890 notifySizeChanged_Widget_(child.object);
891 }
892}
893
881void arrange_Widget(iWidget *d) { 894void arrange_Widget(iWidget *d) {
882 if (d) { 895 if (d) {
883#if !defined (NDEBUG) 896#if !defined (NDEBUG)
@@ -887,6 +900,7 @@ void arrange_Widget(iWidget *d) {
887#endif 900#endif
888 resetArrangement_Widget_(d); /* back to initial default sizes */ 901 resetArrangement_Widget_(d); /* back to initial default sizes */
889 arrange_Widget_(d); 902 arrange_Widget_(d);
903 notifySizeChanged_Widget_(d);
890 } 904 }
891} 905}
892 906
diff --git a/src/ui/widget.h b/src/ui/widget.h
index 9c4c44fb..4ab8d602 100644
--- a/src/ui/widget.h
+++ b/src/ui/widget.h
@@ -146,6 +146,7 @@ struct Impl_Widget {
146 int64_t flags; 146 int64_t flags;
147 int flags2; 147 int flags2;
148 iRect rect; 148 iRect rect;
149 iInt2 oldSize; /* in previous arrangement; for notification */
149 iInt2 minSize; 150 iInt2 minSize;
150 iWidget * sizeRef; 151 iWidget * sizeRef;
151 iWidget * offsetRef; 152 iWidget * offsetRef;