diff options
Diffstat (limited to 'src/ui/widget.c')
-rw-r--r-- | src/ui/widget.c | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/src/ui/widget.c b/src/ui/widget.c index 9320659c..31544cf8 100644 --- a/src/ui/widget.c +++ b/src/ui/widget.c | |||
@@ -77,6 +77,7 @@ void init_Widget(iWidget *d) { | |||
77 | d->rect = zero_Rect(); | 77 | d->rect = zero_Rect(); |
78 | d->bgColor = none_ColorId; | 78 | d->bgColor = none_ColorId; |
79 | d->frameColor = none_ColorId; | 79 | d->frameColor = none_ColorId; |
80 | init_Anim(&d->visualOffset, 0.0f); | ||
80 | d->children = NULL; | 81 | d->children = NULL; |
81 | d->parent = NULL; | 82 | d->parent = NULL; |
82 | d->commandHandler = NULL; | 83 | d->commandHandler = NULL; |
@@ -86,6 +87,10 @@ void init_Widget(iWidget *d) { | |||
86 | void deinit_Widget(iWidget *d) { | 87 | void deinit_Widget(iWidget *d) { |
87 | releaseChildren_Widget(d); | 88 | releaseChildren_Widget(d); |
88 | deinit_String(&d->id); | 89 | deinit_String(&d->id); |
90 | // printf("widget %p deleted (on top:%d)\n", d, d->flags & keepOnTop_WidgetFlag ? 1 : 0); | ||
91 | if (d->flags & keepOnTop_WidgetFlag) { | ||
92 | removeAll_PtrArray(onTop_RootData_(), d); | ||
93 | } | ||
89 | } | 94 | } |
90 | 95 | ||
91 | static void aboutToBeDestroyed_Widget_(iWidget *d) { | 96 | static void aboutToBeDestroyed_Widget_(iWidget *d) { |
@@ -166,8 +171,33 @@ void setPadding_Widget(iWidget *d, int left, int top, int right, int bottom) { | |||
166 | d->padding[3] = bottom; | 171 | d->padding[3] = bottom; |
167 | } | 172 | } |
168 | 173 | ||
174 | static void visualOffsetAnimation_Widget_(void *ptr) { | ||
175 | iWidget *d = ptr; | ||
176 | postRefresh_App(); | ||
177 | if (!isFinished_Anim(&d->visualOffset)) { | ||
178 | addTicker_App(visualOffsetAnimation_Widget_, ptr); | ||
179 | } | ||
180 | else { | ||
181 | setFlags_Widget(d, visualOffset_WidgetFlag, iFalse); | ||
182 | } | ||
183 | } | ||
184 | |||
185 | void setVisualOffset_Widget(iWidget *d, int value, uint32_t span, int animFlags) { | ||
186 | setFlags_Widget(d, visualOffset_WidgetFlag, iTrue); | ||
187 | if (span == 0) { | ||
188 | init_Anim(&d->visualOffset, value); | ||
189 | } | ||
190 | else { | ||
191 | setValue_Anim(&d->visualOffset, value, span); | ||
192 | d->visualOffset.flags = animFlags; | ||
193 | addTicker_App(visualOffsetAnimation_Widget_, d); | ||
194 | } | ||
195 | } | ||
196 | |||
169 | void setBackgroundColor_Widget(iWidget *d, int bgColor) { | 197 | void setBackgroundColor_Widget(iWidget *d, int bgColor) { |
170 | d->bgColor = bgColor; | 198 | if (d) { |
199 | d->bgColor = bgColor; | ||
200 | } | ||
171 | } | 201 | } |
172 | 202 | ||
173 | void setFrameColor_Widget(iWidget *d, int frameColor) { | 203 | void setFrameColor_Widget(iWidget *d, int frameColor) { |
@@ -456,8 +486,15 @@ void arrange_Widget(iWidget *d) { | |||
456 | 486 | ||
457 | iRect bounds_Widget(const iWidget *d) { | 487 | iRect bounds_Widget(const iWidget *d) { |
458 | iRect bounds = d->rect; | 488 | iRect bounds = d->rect; |
489 | if (d->flags & visualOffset_WidgetFlag) { | ||
490 | bounds.pos.y += iRound(value_Anim(&d->visualOffset)); | ||
491 | } | ||
459 | for (const iWidget *w = d->parent; w; w = w->parent) { | 492 | for (const iWidget *w = d->parent; w; w = w->parent) { |
460 | addv_I2(&bounds.pos, w->rect.pos); | 493 | iInt2 pos = w->rect.pos; |
494 | if (w->flags & visualOffset_WidgetFlag) { | ||
495 | pos.y += iRound(value_Anim(&w->visualOffset)); | ||
496 | } | ||
497 | addv_I2(&bounds.pos, pos); | ||
461 | } | 498 | } |
462 | return bounds; | 499 | return bounds; |
463 | } | 500 | } |
@@ -677,11 +714,17 @@ void drawBackground_Widget(const iWidget *d) { | |||
677 | } | 714 | } |
678 | } | 715 | } |
679 | 716 | ||
717 | iLocalDef iBool isDrawn_Widget_(const iWidget *d) { | ||
718 | return ~d->flags & hidden_WidgetFlag || d->flags & visualOffset_WidgetFlag; | ||
719 | } | ||
720 | |||
680 | void drawChildren_Widget(const iWidget *d) { | 721 | void drawChildren_Widget(const iWidget *d) { |
681 | if (d->flags & hidden_WidgetFlag) return; | 722 | if (!isDrawn_Widget_(d)) { |
723 | return; | ||
724 | } | ||
682 | iConstForEach(ObjectList, i, d->children) { | 725 | iConstForEach(ObjectList, i, d->children) { |
683 | const iWidget *child = constAs_Widget(i.object); | 726 | const iWidget *child = constAs_Widget(i.object); |
684 | if (~child->flags & keepOnTop_WidgetFlag && ~child->flags & hidden_WidgetFlag) { | 727 | if (~child->flags & keepOnTop_WidgetFlag && isDrawn_Widget_(child)) { |
685 | class_Widget(child)->draw(child); | 728 | class_Widget(child)->draw(child); |
686 | } | 729 | } |
687 | } | 730 | } |