diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-06 09:27:14 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-06 09:27:14 +0300 |
commit | 6bd9fbffec920c103d27bf780d60de314316bbd5 (patch) | |
tree | d87aa9226a1a1ed7a6a77652266aae4bbd78cb14 /src/ui/listwidget.c | |
parent | 8d249e27e6dda6423af93aa4368a81b13cd3f451 (diff) |
Added a LookupWidget with background thread
Diffstat (limited to 'src/ui/listwidget.c')
-rw-r--r-- | src/ui/listwidget.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/ui/listwidget.c b/src/ui/listwidget.c index 64e509ef..3c061bdc 100644 --- a/src/ui/listwidget.c +++ b/src/ui/listwidget.c | |||
@@ -62,7 +62,6 @@ struct Impl_ListWidget { | |||
62 | SDL_Texture *visBuffer[2]; | 62 | SDL_Texture *visBuffer[2]; |
63 | int visBufferIndex; | 63 | int visBufferIndex; |
64 | int visBufferScrollY; | 64 | int visBufferScrollY; |
65 | // iBool visBufferValid; | ||
66 | enum iBufferValidity visBufferValid; | 65 | enum iBufferValidity visBufferValid; |
67 | }; | 66 | }; |
68 | 67 | ||
@@ -70,6 +69,7 @@ void init_ListWidget(iListWidget *d) { | |||
70 | iWidget *w = as_Widget(d); | 69 | iWidget *w = as_Widget(d); |
71 | init_Widget(w); | 70 | init_Widget(w); |
72 | setId_Widget(w, "list"); | 71 | setId_Widget(w, "list"); |
72 | setBackgroundColor_Widget(w, uiBackground_ColorId); /* needed for filling visbuffer */ | ||
73 | setFlags_Widget(w, hover_WidgetFlag, iTrue); | 73 | setFlags_Widget(w, hover_WidgetFlag, iTrue); |
74 | addChild_Widget(w, iClob(d->scroll = new_ScrollWidget())); | 74 | addChild_Widget(w, iClob(d->scroll = new_ScrollWidget())); |
75 | setThumb_ScrollWidget(d->scroll, 0, 0); | 75 | setThumb_ScrollWidget(d->scroll, 0, 0); |
@@ -150,7 +150,6 @@ int scrollPos_ListWidget(const iListWidget *d) { | |||
150 | void setScrollPos_ListWidget(iListWidget *d, int pos) { | 150 | void setScrollPos_ListWidget(iListWidget *d, int pos) { |
151 | d->scrollY = pos; | 151 | d->scrollY = pos; |
152 | d->hoverItem = iInvalidPos; | 152 | d->hoverItem = iInvalidPos; |
153 | // invalidate_ListWidget(d); | ||
154 | d->visBufferValid = partial_BufferValidity; | 153 | d->visBufferValid = partial_BufferValidity; |
155 | refresh_Widget(as_Widget(d)); | 154 | refresh_Widget(as_Widget(d)); |
156 | } | 155 | } |
@@ -166,7 +165,6 @@ void scrollOffset_ListWidget(iListWidget *d, int offset) { | |||
166 | if (oldScroll != d->scrollY) { | 165 | if (oldScroll != d->scrollY) { |
167 | d->hoverItem = iInvalidPos; | 166 | d->hoverItem = iInvalidPos; |
168 | updateVisible_ListWidget(d); | 167 | updateVisible_ListWidget(d); |
169 | //invalidate_ListWidget(d); | ||
170 | d->visBufferValid = partial_BufferValidity; | 168 | d->visBufferValid = partial_BufferValidity; |
171 | refresh_Widget(as_Widget(d)); | 169 | refresh_Widget(as_Widget(d)); |
172 | } | 170 | } |
@@ -178,6 +176,9 @@ static int visCount_ListWidget_(const iListWidget *d) { | |||
178 | } | 176 | } |
179 | 177 | ||
180 | static iRanges visRange_ListWidget_(const iListWidget *d) { | 178 | static iRanges visRange_ListWidget_(const iListWidget *d) { |
179 | if (d->itemHeight == 0) { | ||
180 | return (iRanges){ 0, 0 }; | ||
181 | } | ||
181 | iRanges vis = { d->scrollY / d->itemHeight, 0 }; | 182 | iRanges vis = { d->scrollY / d->itemHeight, 0 }; |
182 | vis.end = iMin(size_PtrArray(&d->items), vis.start + visCount_ListWidget_(d)); | 183 | vis.end = iMin(size_PtrArray(&d->items), vis.start + visCount_ListWidget_(d)); |
183 | return vis; | 184 | return vis; |
@@ -186,7 +187,7 @@ static iRanges visRange_ListWidget_(const iListWidget *d) { | |||
186 | size_t itemIndex_ListWidget(const iListWidget *d, iInt2 pos) { | 187 | size_t itemIndex_ListWidget(const iListWidget *d, iInt2 pos) { |
187 | const iRect bounds = innerBounds_Widget(constAs_Widget(d)); | 188 | const iRect bounds = innerBounds_Widget(constAs_Widget(d)); |
188 | pos.y -= top_Rect(bounds) - d->scrollY; | 189 | pos.y -= top_Rect(bounds) - d->scrollY; |
189 | if (pos.y < 0) return iInvalidPos; | 190 | if (pos.y < 0 || !d->itemHeight) return iInvalidPos; |
190 | size_t index = pos.y / d->itemHeight; | 191 | size_t index = pos.y / d->itemHeight; |
191 | if (index >= size_Array(&d->items)) return iInvalidPos; | 192 | if (index >= size_Array(&d->items)) return iInvalidPos; |
192 | return index; | 193 | return index; |