summaryrefslogtreecommitdiff
path: root/src/ui/listwidget.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-06-09 19:01:15 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-06-09 19:01:15 +0300
commitf63ed76597b462c60b3a6ad89f8c165ffb87d00c (patch)
tree2aca3537930bce28acff14c0cee0a11fa1988661 /src/ui/listwidget.c
parent5f9685010addd4a0f04c13f889856084381dd1c6 (diff)
parentee17ef3d0135027fbc4ff816dd9e793b4bb0b883 (diff)
Merge branch 'dev' into work/typesetter
# Conflicts: # src/gmdocument.c # src/ui/documentwidget.c # src/ui/inputwidget.h
Diffstat (limited to 'src/ui/listwidget.c')
-rw-r--r--src/ui/listwidget.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/ui/listwidget.c b/src/ui/listwidget.c
index a3406d48..f7c43a93 100644
--- a/src/ui/listwidget.c
+++ b/src/ui/listwidget.c
@@ -148,11 +148,16 @@ void updateVisible_ListWidget(iListWidget *d) {
148 const int contentSize = size_PtrArray(&d->items) * d->itemHeight; 148 const int contentSize = size_PtrArray(&d->items) * d->itemHeight;
149 const iRect bounds = innerBounds_Widget(as_Widget(d)); 149 const iRect bounds = innerBounds_Widget(as_Widget(d));
150 const iBool wasVisible = isVisible_Widget(d->scroll); 150 const iBool wasVisible = isVisible_Widget(d->scroll);
151 if (area_Rect(bounds) == 0) { 151 if (width_Rect(bounds) <= 0 || height_Rect(bounds) <= 0) {
152 return; 152 return;
153 } 153 }
154 /* The scroll widget's visibility depends on it having a valid non-zero size.
155 However, this may be called during arrangement (sizeChanged_ListWidget_),
156 which means the child hasn't been arranged yet. The child cannot update
157 its visibility unless it knows its correct size. */
158 arrange_Widget(as_Widget(d->scroll));
154 setMax_SmoothScroll(&d->scrollY, scrollMax_ListWidget_(d)); 159 setMax_SmoothScroll(&d->scrollY, scrollMax_ListWidget_(d));
155 setRange_ScrollWidget(d->scroll, (iRangei){ 0, d->scrollY.max }); 160 setRange_ScrollWidget(d->scroll, (iRangei){ 0, d->scrollY.max });
156 setThumb_ScrollWidget(d->scroll, 161 setThumb_ScrollWidget(d->scroll,
157 pos_SmoothScroll(&d->scrollY), 162 pos_SmoothScroll(&d->scrollY),
158 contentSize > 0 ? height_Rect(bounds_Widget(as_Widget(d->scroll))) * 163 contentSize > 0 ? height_Rect(bounds_Widget(as_Widget(d->scroll))) *
@@ -369,6 +374,13 @@ static iBool processEvent_ListWidget_(iListWidget *d, const SDL_Event *ev) {
369 return processEvent_Widget(w, ev); 374 return processEvent_Widget(w, ev);
370} 375}
371 376
377iRect itemRect_ListWidget(const iListWidget *d, size_t index) {
378 const iRect bounds = innerBounds_Widget(constAs_Widget(d));
379 const int scrollY = pos_SmoothScroll(&d->scrollY);
380 return (iRect){ addY_I2(topLeft_Rect(bounds), d->itemHeight * (int) index - scrollY),
381 init_I2(width_Rect(bounds), d->itemHeight) };
382}
383
372static void draw_ListWidget_(const iListWidget *d) { 384static void draw_ListWidget_(const iListWidget *d) {
373 const iWidget *w = constAs_Widget(d); 385 const iWidget *w = constAs_Widget(d);
374 const iRect bounds = innerBounds_Widget(w); 386 const iRect bounds = innerBounds_Widget(w);