{"id":108,"date":"2021-08-02T10:57:57","date_gmt":"2021-08-02T10:57:57","guid":{"rendered":"https:\/\/blogs.scummvm.org\/av-dx\/?p=108"},"modified":"2021-08-02T10:57:57","modified_gmt":"2021-08-02T10:57:57","slug":"implementing-grouping-in-grid-view-week-8-progress","status":"publish","type":"post","link":"https:\/\/blogs.scummvm.org\/av-dx\/2021\/08\/02\/implementing-grouping-in-grid-view-week-8-progress\/","title":{"rendered":"Implementing grouping in Grid View (Week 8 progress)"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Task 1: Rendering &#8220;<em>Groups<\/em>&#8220;<\/h2>\n\n\n\n<p>I had already acquired the technology to group elements in array form, and the grid internally uses a linear array to store the entries as well. So &#8220;forming&#8221; groups is borderline copy paste.<\/p>\n\n\n\n<p>So I can easily add a generic &#8220;attribute&#8221; parameter to the struct (which may well be some already known parameter like engineid or gameid, I don&#8217;t worry about data redundancy here). This is the attribute to form groups on.<\/p>\n\n\n\n<p>Now everything to render on the grid is arranged in the form of a list internally, so just take the grouped list and read it linearly, and convert it to a grid.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/GroupGridRendering-1024x576.png\" alt=\"\" class=\"wp-image-109\" srcset=\"https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/GroupGridRendering-1024x576.png 1024w, https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/GroupGridRendering-300x169.png 300w, https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/GroupGridRendering-768x432.png 768w, https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/GroupGridRendering-1536x864.png 1536w, https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/GroupGridRendering-1568x882.png 1568w, https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/GroupGridRendering.png 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Mockup of how the system creates a grid out of a list<\/figcaption><\/figure>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/Screenshot-from-2021-07-29-01-52-28-1024x984.png\" alt=\"\" class=\"wp-image-110\" width=\"289\" height=\"277\" srcset=\"https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/Screenshot-from-2021-07-29-01-52-28-1024x984.png 1024w, https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/Screenshot-from-2021-07-29-01-52-28-300x288.png 300w, https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/Screenshot-from-2021-07-29-01-52-28-768x738.png 768w, https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/Screenshot-from-2021-07-29-01-52-28.png 1085w\" sizes=\"auto, (max-width: 289px) 100vw, 289px\" \/><\/figure>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/Screenshot-from-2021-07-29-01-57-40-1020x1024.png\" alt=\"\" class=\"wp-image-111\" width=\"278\" height=\"279\" srcset=\"https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/Screenshot-from-2021-07-29-01-57-40-1020x1024.png 1020w, https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/Screenshot-from-2021-07-29-01-57-40-300x300.png 300w, https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/Screenshot-from-2021-07-29-01-57-40-150x150.png 150w, https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/Screenshot-from-2021-07-29-01-57-40-768x771.png 768w, https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/Screenshot-from-2021-07-29-01-57-40.png 1039w\" sizes=\"auto, (max-width: 278px) 100vw, 278px\" \/><\/figure>\n<\/div>\n<\/div>\n\n\n\n<p>So the group rendering &#8230; works, but obviously headers are supposed to have different style, a different height, as seen in the mockup. But this simple problem of having items not have all the same height, requires us to come up with a new rendering algorithm for the grid.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Task 2: Variable height grid entries<\/h2>\n\n\n\n<p>Having all entries have the same height simplifies the calculations significantly. Just using linear maths, we can determine given a y coordinate (and the window height), exactly what elements are to be displayed. But when we don&#8217;t know beforehand the size of these entries, how do we find out given a random scroll position (y value), which entries should be drawn?<\/p>\n\n\n\n<p>We additionally need to store the size and position (on the scrolling page, not where to render) of the entry not within the rendering widget, but within the list itself.<\/p>\n\n\n\n<p>We run binary search to figure out the first visible item on the grid. It will have y value of just less than our scroll position. Then we interpret the list as a grid.<\/p>\n\n\n\n<p>Then during drawWidget() function, we just a boolean to use different rendering methods to draw the different kinds of items.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"856\" height=\"1024\" src=\"https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/Screenshot-from-2021-08-02-14-58-04-856x1024.png\" alt=\"\" class=\"wp-image-112\" srcset=\"https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/Screenshot-from-2021-08-02-14-58-04-856x1024.png 856w, https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/Screenshot-from-2021-08-02-14-58-04-251x300.png 251w, https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/Screenshot-from-2021-08-02-14-58-04-768x919.png 768w, https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/Screenshot-from-2021-08-02-14-58-04.png 922w\" sizes=\"auto, (max-width: 856px) 100vw, 856px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Task 3: Collapsible groups, improving the look<\/h2>\n\n\n\n<p>The toggling of groups is still the same as it was in grouped list, we modify the internal array, and reinterpret the grid from that list.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"803\" height=\"1024\" src=\"https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/Screenshot-from-2021-08-01-15-49-56-803x1024.png\" alt=\"\" class=\"wp-image-113\" srcset=\"https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/Screenshot-from-2021-08-01-15-49-56-803x1024.png 803w, https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/Screenshot-from-2021-08-01-15-49-56-235x300.png 235w, https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/Screenshot-from-2021-08-01-15-49-56-768x979.png 768w, https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/Screenshot-from-2021-08-01-15-49-56.png 960w\" sizes=\"auto, (max-width: 803px) 100vw, 803px\" \/><\/figure>\n\n\n\n<p>Now that we have allowed our grid items to have different heights, we can also remove the reservation of static space of two lines under the thumbnail (notice how in the above, there is one line of empty space between &#8220;Mystery House&#8221; and the tray). This was done earlier to accommodate for longer titles, but now we can dynamically allocate space for titles, we can save on vertical space where it&#8217;s not required.<\/p>\n\n\n\n<p>Further improvement was made to the look of the headers, restoring the triangle for fold indicators, and giving them a background color (which I plan to make theme configurable) so that the distinction between groups is clear.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"823\" height=\"1024\" src=\"https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/Screenshot-from-2021-08-02-16-24-22-1-823x1024.png\" alt=\"\" class=\"wp-image-116\" srcset=\"https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/Screenshot-from-2021-08-02-16-24-22-1-823x1024.png 823w, https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/Screenshot-from-2021-08-02-16-24-22-1-241x300.png 241w, https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/Screenshot-from-2021-08-02-16-24-22-1-768x956.png 768w, https:\/\/blogs.scummvm.org\/av-dx\/wp-content\/uploads\/sites\/6\/2021\/08\/Screenshot-from-2021-08-02-16-24-22-1.png 1153w\" sizes=\"auto, (max-width: 823px) 100vw, 823px\" \/><figcaption>Improved look of the grid widget<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Task 1: Rendering &#8220;Groups&#8220; I had already acquired the technology to group elements in array form, and the grid internally uses a linear array to store the entries as well. So &#8220;forming&#8221; groups is borderline copy paste. So I can easily add a generic &#8220;attribute&#8221; parameter to the struct (which may well be some already&hellip; <a class=\"more-link\" href=\"https:\/\/blogs.scummvm.org\/av-dx\/2021\/08\/02\/implementing-grouping-in-grid-view-week-8-progress\/\">Continue reading <span class=\"screen-reader-text\">Implementing grouping in Grid View (Week 8 progress)<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-108","post","type-post","status-publish","format-standard","hentry","category-uncategorized","entry"],"_links":{"self":[{"href":"https:\/\/blogs.scummvm.org\/av-dx\/wp-json\/wp\/v2\/posts\/108","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.scummvm.org\/av-dx\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.scummvm.org\/av-dx\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/av-dx\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/av-dx\/wp-json\/wp\/v2\/comments?post=108"}],"version-history":[{"count":3,"href":"https:\/\/blogs.scummvm.org\/av-dx\/wp-json\/wp\/v2\/posts\/108\/revisions"}],"predecessor-version":[{"id":118,"href":"https:\/\/blogs.scummvm.org\/av-dx\/wp-json\/wp\/v2\/posts\/108\/revisions\/118"}],"wp:attachment":[{"href":"https:\/\/blogs.scummvm.org\/av-dx\/wp-json\/wp\/v2\/media?parent=108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/av-dx\/wp-json\/wp\/v2\/categories?post=108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/av-dx\/wp-json\/wp\/v2\/tags?post=108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}