diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-05 16:47:47 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-05 16:47:47 +0300 |
commit | ab193f5f5d23a1606b23ca0defdd29ad67e44bca (patch) | |
tree | 6acbc0c68807d559400a3a87e653dddc345747b0 /src | |
parent | 8cdebce00959705de94295bdbb4b32ec08fc4b70 (diff) |
Fixed issues with the refactored sidebar
Diffstat (limited to 'src')
-rw-r--r-- | src/ui/listwidget.c | 11 | ||||
-rw-r--r-- | src/ui/listwidget.h | 4 | ||||
-rw-r--r-- | src/ui/sidebarwidget.c | 36 |
3 files changed, 36 insertions, 15 deletions
diff --git a/src/ui/listwidget.c b/src/ui/listwidget.c index 3865becc..7651171b 100644 --- a/src/ui/listwidget.c +++ b/src/ui/listwidget.c | |||
@@ -153,7 +153,7 @@ void scrollOffset_ListWidget(iListWidget *d, int offset) { | |||
153 | } | 153 | } |
154 | 154 | ||
155 | static int visCount_ListWidget_(const iListWidget *d) { | 155 | static int visCount_ListWidget_(const iListWidget *d) { |
156 | return iMin(height_Rect(innerBounds_Widget(constAs_Widget(d))) / d->itemHeight, | 156 | return iMin(height_Rect(innerBounds_Widget(constAs_Widget(d))) / d->itemHeight + 1, |
157 | (int) size_PtrArray(&d->items)); | 157 | (int) size_PtrArray(&d->items)); |
158 | } | 158 | } |
159 | 159 | ||
@@ -272,14 +272,16 @@ static void allocVisBuffer_ListWidget_(iListWidget *d) { | |||
272 | } | 272 | } |
273 | 273 | ||
274 | static void draw_ListWidget_(const iListWidget *d) { | 274 | static void draw_ListWidget_(const iListWidget *d) { |
275 | const iWidget *w = constAs_Widget(d); | 275 | const iWidget *w = constAs_Widget(d); |
276 | const iRect bounds = innerBounds_Widget(w); | 276 | const iRect bounds = innerBounds_Widget(w); |
277 | draw_Widget(w); /* background */ | 277 | if (!bounds.size.y || !bounds.size.x) return; |
278 | iPaint p; | 278 | iPaint p; |
279 | init_Paint(&p); | 279 | init_Paint(&p); |
280 | drawBackground_Widget(w); | ||
280 | if (!d->visBufferValid || !isEmpty_IntSet(&d->invalidItems)) { | 281 | if (!d->visBufferValid || !isEmpty_IntSet(&d->invalidItems)) { |
281 | iListWidget *m = iConstCast(iListWidget *, d); | 282 | iListWidget *m = iConstCast(iListWidget *, d); |
282 | allocVisBuffer_ListWidget_(m); | 283 | allocVisBuffer_ListWidget_(m); |
284 | iAssert(d->visBuffer); | ||
283 | beginTarget_Paint(&p, d->visBuffer); | 285 | beginTarget_Paint(&p, d->visBuffer); |
284 | const iRect bufBounds = (iRect){ zero_I2(), bounds.size }; | 286 | const iRect bufBounds = (iRect){ zero_I2(), bounds.size }; |
285 | if (!d->visBufferValid) { | 287 | if (!d->visBufferValid) { |
@@ -310,6 +312,7 @@ static void draw_ListWidget_(const iListWidget *d) { | |||
310 | } | 312 | } |
311 | SDL_RenderCopy( | 313 | SDL_RenderCopy( |
312 | renderer_Window(get_Window()), d->visBuffer, NULL, (const SDL_Rect *) &bounds); | 314 | renderer_Window(get_Window()), d->visBuffer, NULL, (const SDL_Rect *) &bounds); |
315 | drawChildren_Widget(w); | ||
313 | } | 316 | } |
314 | 317 | ||
315 | iBool isMouseDown_ListWidget(const iListWidget *d) { | 318 | iBool isMouseDown_ListWidget(const iListWidget *d) { |
diff --git a/src/ui/listwidget.h b/src/ui/listwidget.h index 38bdebc9..37afe895 100644 --- a/src/ui/listwidget.h +++ b/src/ui/listwidget.h | |||
@@ -35,7 +35,7 @@ iEndDeclareClass(ListItem) | |||
35 | 35 | ||
36 | iDeclareType(ListItem) | 36 | iDeclareType(ListItem) |
37 | 37 | ||
38 | struct Impl_ListItem { | 38 | struct Impl_ListItem { |
39 | iObject object; | 39 | iObject object; |
40 | iBool isSeparator; | 40 | iBool isSeparator; |
41 | iBool isSelected; | 41 | iBool isSelected; |
@@ -52,7 +52,7 @@ void invalidate_ListWidget (iListWidget *); | |||
52 | void clear_ListWidget (iListWidget *); | 52 | void clear_ListWidget (iListWidget *); |
53 | void addItem_ListWidget (iListWidget *, iAnyObject *item); | 53 | void addItem_ListWidget (iListWidget *, iAnyObject *item); |
54 | 54 | ||
55 | iScrollWidget * scroll_ListWidget (iListWidget *); | 55 | iScrollWidget * scroll_ListWidget (iListWidget *); |
56 | 56 | ||
57 | int scrollPos_ListWidget (const iListWidget *); | 57 | int scrollPos_ListWidget (const iListWidget *); |
58 | 58 | ||
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c index 8dada9eb..1d53202b 100644 --- a/src/ui/sidebarwidget.c +++ b/src/ui/sidebarwidget.c | |||
@@ -121,6 +121,7 @@ static iBool isResizing_SidebarWidget_(const iSidebarWidget *d) { | |||
121 | // clear_Array(&d->items); | 121 | // clear_Array(&d->items); |
122 | //} | 122 | //} |
123 | 123 | ||
124 | #if 0 | ||
124 | static iRect contentBounds_SidebarWidget_(const iSidebarWidget *d) { | 125 | static iRect contentBounds_SidebarWidget_(const iSidebarWidget *d) { |
125 | iRect bounds = bounds_Widget(constAs_Widget(d)); | 126 | iRect bounds = bounds_Widget(constAs_Widget(d)); |
126 | const iWidget *scroll = constAs_Widget(scroll_ListWidget(d->list)); | 127 | const iWidget *scroll = constAs_Widget(scroll_ListWidget(d->list)); |
@@ -131,6 +132,7 @@ static iRect contentBounds_SidebarWidget_(const iSidebarWidget *d) { | |||
131 | 0); | 132 | 0); |
132 | return bounds; | 133 | return bounds; |
133 | } | 134 | } |
135 | #endif | ||
134 | 136 | ||
135 | //static int scrollMax_SidebarWidget_(const iSidebarWidget *d) { | 137 | //static int scrollMax_SidebarWidget_(const iSidebarWidget *d) { |
136 | // return iMax(0, | 138 | // return iMax(0, |
@@ -153,6 +155,10 @@ static int cmpTitle_Bookmark_(const iBookmark **a, const iBookmark **b) { | |||
153 | return cmpStringCase_String(&(*a)->title, &(*b)->title); | 155 | return cmpStringCase_String(&(*a)->title, &(*b)->title); |
154 | } | 156 | } |
155 | 157 | ||
158 | static void updateVisible_SidebarWidget_(iSidebarWidget *d) { | ||
159 | updateVisible_ListWidget(d->list); | ||
160 | } | ||
161 | |||
156 | static void updateItems_SidebarWidget_(iSidebarWidget *d) { | 162 | static void updateItems_SidebarWidget_(iSidebarWidget *d) { |
157 | // clearItems_SidebarWidget_(d); | 163 | // clearItems_SidebarWidget_(d); |
158 | clear_ListWidget(d->list); | 164 | clear_ListWidget(d->list); |
@@ -297,7 +303,7 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) { | |||
297 | default: | 303 | default: |
298 | break; | 304 | break; |
299 | } | 305 | } |
300 | updateVisible_ListWidget(d->list); | 306 | updateVisible_SidebarWidget_(d); |
301 | invalidate_ListWidget(d->list); | 307 | invalidate_ListWidget(d->list); |
302 | } | 308 | } |
303 | 309 | ||
@@ -326,6 +332,9 @@ void setMode_SidebarWidget(iSidebarWidget *d, enum iSidebarMode mode) { | |||
326 | setFlags_Widget(as_Widget(d->modeButtons[i]), selected_WidgetFlag, i == d->mode); | 332 | setFlags_Widget(as_Widget(d->modeButtons[i]), selected_WidgetFlag, i == d->mode); |
327 | } | 333 | } |
328 | const float heights[max_SidebarMode] = { 1.333f, 1.333f, 3.5f, 1.2f }; | 334 | const float heights[max_SidebarMode] = { 1.333f, 1.333f, 3.5f, 1.2f }; |
335 | setBackgroundColor_Widget(as_Widget(d->list), | ||
336 | d->mode == documentOutline_SidebarMode ? tmBackground_ColorId | ||
337 | : uiBackground_ColorId); | ||
329 | setItemHeight_ListWidget(d->list, heights[mode] * lineHeight_Text(uiContent_FontId)); | 338 | setItemHeight_ListWidget(d->list, heights[mode] * lineHeight_Text(uiContent_FontId)); |
330 | /* Restore previous scroll position. */ | 339 | /* Restore previous scroll position. */ |
331 | setScrollPos_ListWidget(d->list, d->modeScroll[mode]); | 340 | setScrollPos_ListWidget(d->list, d->modeScroll[mode]); |
@@ -359,26 +368,34 @@ void init_SidebarWidget(iSidebarWidget *d) { | |||
359 | setId_Widget(w, "sidebar"); | 368 | setId_Widget(w, "sidebar"); |
360 | setBackgroundColor_Widget(w, none_ColorId); | 369 | setBackgroundColor_Widget(w, none_ColorId); |
361 | setFlags_Widget(w, | 370 | setFlags_Widget(w, |
362 | hidden_WidgetFlag | arrangeVertical_WidgetFlag | | 371 | collapse_WidgetFlag | hidden_WidgetFlag | arrangeHorizontal_WidgetFlag | |
363 | resizeChildren_WidgetFlag | collapse_WidgetFlag, | 372 | resizeWidthOfChildren_WidgetFlag, |
364 | iTrue); | 373 | iTrue); |
365 | iZap(d->modeScroll); | 374 | iZap(d->modeScroll); |
366 | d->mode = -1; | 375 | d->mode = -1; |
367 | d->width = 60 * gap_UI; | 376 | d->width = 60 * gap_UI; |
368 | setFlags_Widget(w, fixedWidth_WidgetFlag, iTrue); | 377 | setFlags_Widget(w, fixedWidth_WidgetFlag, iTrue); |
369 | d->maxButtonLabelWidth = 0; | 378 | d->maxButtonLabelWidth = 0; |
370 | /* TODO: Add a parent h-div for the mode buttons. */ | 379 | iWidget *vdiv = makeVDiv_Widget(); |
380 | addChildFlags_Widget(w, vdiv, resizeToParentWidth_WidgetFlag | resizeToParentHeight_WidgetFlag); | ||
381 | iWidget *buttons = new_Widget(); | ||
371 | for (int i = 0; i < max_SidebarMode; i++) { | 382 | for (int i = 0; i < max_SidebarMode; i++) { |
372 | d->modeButtons[i] = addChildFlags_Widget( | 383 | d->modeButtons[i] = addChildFlags_Widget( |
373 | w, | 384 | buttons, |
374 | iClob( | 385 | iClob( |
375 | new_LabelWidget(tightModeLabels_[i], 0, 0, format_CStr("sidebar.mode arg:%d", i))), | 386 | new_LabelWidget(tightModeLabels_[i], 0, 0, format_CStr("sidebar.mode arg:%d", i))), |
376 | frameless_WidgetFlag | expand_WidgetFlag); | 387 | frameless_WidgetFlag); |
377 | d->maxButtonLabelWidth = | 388 | d->maxButtonLabelWidth = |
378 | iMaxi(d->maxButtonLabelWidth, | 389 | iMaxi(d->maxButtonLabelWidth, |
379 | 3 * gap_UI + measure_Text(uiLabel_FontId, normalModeLabels_[i]).x); | 390 | 3 * gap_UI + measure_Text(uiLabel_FontId, normalModeLabels_[i]).x); |
380 | } | 391 | } |
381 | addChildFlags_Widget(w, iClob(d->list = new_ListWidget()), expand_WidgetFlag); | 392 | addChildFlags_Widget(vdiv, |
393 | iClob(buttons), | ||
394 | arrangeHorizontal_WidgetFlag | resizeWidthOfChildren_WidgetFlag | | ||
395 | arrangeHeight_WidgetFlag | resizeToParentWidth_WidgetFlag); | ||
396 | d->list = new_ListWidget(); | ||
397 | setPadding_Widget(as_Widget(d->list), 0, gap_UI, 0, gap_UI); | ||
398 | addChildFlags_Widget(vdiv, iClob(d->list), expand_WidgetFlag); | ||
382 | setMode_SidebarWidget(d, documentOutline_SidebarMode); | 399 | setMode_SidebarWidget(d, documentOutline_SidebarMode); |
383 | d->resizer = addChildFlags_Widget( | 400 | d->resizer = addChildFlags_Widget( |
384 | w, | 401 | w, |
@@ -558,7 +575,7 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) | |||
558 | iWidget *w = as_Widget(d); | 575 | iWidget *w = as_Widget(d); |
559 | /* Handle commands. */ | 576 | /* Handle commands. */ |
560 | if (isResize_UserEvent(ev)) { | 577 | if (isResize_UserEvent(ev)) { |
561 | updateVisible_ListWidget(d->list); | 578 | updateVisible_SidebarWidget_(d); |
562 | checkModeButtonLayout_SidebarWidget_(d); | 579 | checkModeButtonLayout_SidebarWidget_(d); |
563 | invalidate_ListWidget(d->list); | 580 | invalidate_ListWidget(d->list); |
564 | } | 581 | } |
@@ -1041,7 +1058,8 @@ static void draw_SidebarWidget_(const iSidebarWidget *d) { | |||
1041 | 1058 | ||
1042 | static void draw_SidebarItem_(const iSidebarItem *d, iPaint *p, iRect itemRect, | 1059 | static void draw_SidebarItem_(const iSidebarItem *d, iPaint *p, iRect itemRect, |
1043 | const iListWidget *list) { | 1060 | const iListWidget *list) { |
1044 | const iSidebarWidget *sidebar = (const iSidebarWidget *) constAs_Widget(list)->parent; | 1061 | const iSidebarWidget *sidebar = findParentClass_Widget(constAs_Widget(list), |
1062 | &Class_SidebarWidget); | ||
1045 | const iBool isPressing = isMouseDown_ListWidget(list); | 1063 | const iBool isPressing = isMouseDown_ListWidget(list); |
1046 | const int font = uiContent_FontId; | 1064 | const int font = uiContent_FontId; |
1047 | const iBool isHover = | 1065 | const iBool isHover = |