summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-09-30 11:16:43 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-09-30 11:16:43 +0300
commit965ab7e4394002b3e9af5b65cae3c08f4364f01a (patch)
tree9fbd736b6163c21f71b5e8579cafef712f4f0deb
parent9978d46dfe90f7701b90652a7f8500cdd46eaf31 (diff)
SidebarWidget: Scroll view to newly added items
New bookmarks and folders shouldn't appear outside the visible part of the list.
-rw-r--r--src/app.c2
-rw-r--r--src/ui/listwidget.c10
-rw-r--r--src/ui/listwidget.h3
-rw-r--r--src/ui/lookupwidget.c2
-rw-r--r--src/ui/sidebarwidget.c16
-rw-r--r--src/ui/util.c2
6 files changed, 28 insertions, 7 deletions
diff --git a/src/app.c b/src/app.c
index 3db5cabe..df4a8b0d 100644
--- a/src/app.c
+++ b/src/app.c
@@ -2794,7 +2794,7 @@ iBool handleCommand_App(const char *cmd) {
2794 if (parentId) { 2794 if (parentId) {
2795 get_Bookmarks(d->bookmarks, id)->parentId = parentId; 2795 get_Bookmarks(d->bookmarks, id)->parentId = parentId;
2796 } 2796 }
2797 postCommand_App("bookmarks.changed"); 2797 postCommandf_App("bookmarks.changed added:%zu", id);
2798 } 2798 }
2799 else { 2799 else {
2800 iWidget *dlg = makeValueInput_Widget( 2800 iWidget *dlg = makeValueInput_Widget(
diff --git a/src/ui/listwidget.c b/src/ui/listwidget.c
index 6bb53f2b..3360d71e 100644
--- a/src/ui/listwidget.c
+++ b/src/ui/listwidget.c
@@ -206,7 +206,11 @@ void scrollOffset_ListWidget(iListWidget *d, int offset) {
206 moveSpan_SmoothScroll(&d->scrollY, offset, 0); 206 moveSpan_SmoothScroll(&d->scrollY, offset, 0);
207} 207}
208 208
209void scrollToItem_ListWidget(iListWidget *d, size_t index) { 209void scrollOffsetSpan_ListWidget(iListWidget *d, int offset, uint32_t span) {
210 moveSpan_SmoothScroll(&d->scrollY, offset, span);
211}
212
213void scrollToItem_ListWidget(iListWidget *d, size_t index, uint32_t span) {
210 if (index >= size_PtrArray(&d->items)) { 214 if (index >= size_PtrArray(&d->items)) {
211 return; 215 return;
212 } 216 }
@@ -215,10 +219,10 @@ void scrollToItem_ListWidget(iListWidget *d, size_t index) {
215 int yTop = d->itemHeight * index - pos_SmoothScroll(&d->scrollY); 219 int yTop = d->itemHeight * index - pos_SmoothScroll(&d->scrollY);
216 int yBottom = yTop + d->itemHeight; 220 int yBottom = yTop + d->itemHeight;
217 if (yBottom > height_Rect(rect)) { 221 if (yBottom > height_Rect(rect)) {
218 scrollOffset_ListWidget(d, yBottom - height_Rect(rect)); 222 scrollOffsetSpan_ListWidget(d, yBottom - height_Rect(rect), span);
219 } 223 }
220 else if (yTop < 0) { 224 else if (yTop < 0) {
221 scrollOffset_ListWidget(d, yTop); 225 scrollOffsetSpan_ListWidget(d, yTop, span);
222 } 226 }
223} 227}
224 228
diff --git a/src/ui/listwidget.h b/src/ui/listwidget.h
index dfa24c07..8adf6ac3 100644
--- a/src/ui/listwidget.h
+++ b/src/ui/listwidget.h
@@ -62,8 +62,9 @@ int itemHeight_ListWidget (const iListWidget *);
62int scrollPos_ListWidget (const iListWidget *); 62int scrollPos_ListWidget (const iListWidget *);
63 63
64void setScrollPos_ListWidget (iListWidget *, int pos); 64void setScrollPos_ListWidget (iListWidget *, int pos);
65void scrollToItem_ListWidget (iListWidget *, size_t index); 65void scrollToItem_ListWidget (iListWidget *, size_t index, uint32_t span);
66void scrollOffset_ListWidget (iListWidget *, int offset); 66void scrollOffset_ListWidget (iListWidget *, int offset);
67void scrollOffsetSpan_ListWidget (iListWidget *, int offset, uint32_t span);
67void updateVisible_ListWidget (iListWidget *); 68void updateVisible_ListWidget (iListWidget *);
68void updateMouseHover_ListWidget (iListWidget *); 69void updateMouseHover_ListWidget (iListWidget *);
69void setHoverItem_ListWidget (iListWidget *, size_t index); 70void setHoverItem_ListWidget (iListWidget *, size_t index);
diff --git a/src/ui/lookupwidget.c b/src/ui/lookupwidget.c
index ab649eee..e57a5fdc 100644
--- a/src/ui/lookupwidget.c
+++ b/src/ui/lookupwidget.c
@@ -624,7 +624,7 @@ static void setCursor_LookupWidget_(iLookupWidget *d, size_t index) {
624 item->listItem.isSelected = iTrue; 624 item->listItem.isSelected = iTrue;
625 invalidateItem_ListWidget(d->list, d->cursor); 625 invalidateItem_ListWidget(d->list, d->cursor);
626 } 626 }
627 scrollToItem_ListWidget(d->list, d->cursor); 627 scrollToItem_ListWidget(d->list, d->cursor, 0);
628 } 628 }
629} 629}
630 630
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c
index 4d229c59..4b772eeb 100644
--- a/src/ui/sidebarwidget.c
+++ b/src/ui/sidebarwidget.c
@@ -628,6 +628,17 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) {
628 updateMouseHover_ListWidget(d->list); 628 updateMouseHover_ListWidget(d->list);
629} 629}
630 630
631static size_t findItem_SidebarWidget_(const iSidebarWidget *d, int id) {
632 /* Note that this is O(n), so only meant for infrequent use. */
633 for (size_t i = 0; i < numItems_ListWidget(d->list); i++) {
634 const iSidebarItem *item = constItem_ListWidget(d->list, i);
635 if (item->id == id) {
636 return i;
637 }
638 }
639 return iInvalidPos;
640}
641
631static void updateItemHeight_SidebarWidget_(iSidebarWidget *d) { 642static void updateItemHeight_SidebarWidget_(iSidebarWidget *d) {
632 if (d->list) { 643 if (d->list) {
633 const float heights[max_SidebarMode] = { 1.333f, 2.333f, 1.333f, 3.5f, 1.2f }; 644 const float heights[max_SidebarMode] = { 1.333f, 2.333f, 1.333f, 3.5f, 1.2f };
@@ -1188,6 +1199,11 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
1188 d->mode == feeds_SidebarMode)) { 1199 d->mode == feeds_SidebarMode)) {
1189 if (pointerLabel_Command(cmd, "nosidebar") != d) { 1200 if (pointerLabel_Command(cmd, "nosidebar") != d) {
1190 updateItems_SidebarWidget_(d); 1201 updateItems_SidebarWidget_(d);
1202 if (hasLabel_Command(cmd, "added")) {
1203 const size_t addedId = argLabel_Command(cmd, "added");
1204 const size_t addedIndex = findItem_SidebarWidget_(d, addedId);
1205 scrollToItem_ListWidget(d->list, addedIndex, 200);
1206 }
1191 } 1207 }
1192 } 1208 }
1193 else if (equal_Command(cmd, "idents.changed") && d->mode == identities_SidebarMode) { 1209 else if (equal_Command(cmd, "idents.changed") && d->mode == identities_SidebarMode) {
diff --git a/src/ui/util.c b/src/ui/util.c
index 80bd5d44..adca6269 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -2694,7 +2694,7 @@ static iBool handleBookmarkCreationCommands_SidebarWidget_(iWidget *editor, cons
2694 if (isSelected_Widget(findChild_Widget(editor, "bmed.tag.linksplit"))) { 2694 if (isSelected_Widget(findChild_Widget(editor, "bmed.tag.linksplit"))) {
2695 addTag_Bookmark(bm, linkSplit_BookmarkTag); 2695 addTag_Bookmark(bm, linkSplit_BookmarkTag);
2696 } 2696 }
2697 postCommand_App("bookmarks.changed"); 2697 postCommandf_App("bookmarks.changed added:%zu", id);
2698 } 2698 }
2699 setupSheetTransition_Mobile(editor, iFalse); 2699 setupSheetTransition_Mobile(editor, iFalse);
2700 destroy_Widget(editor); 2700 destroy_Widget(editor);