From cd45d1e8cd8bb3e9e187fc1d2d83b78444e35d76 Mon Sep 17 00:00:00 2001 From: Yousef Khadadeh Date: Tue, 28 Apr 2026 20:55:30 +0300 Subject: [PATCH] Expand width of grid elements to fit longer names --- src/GUIStuff/Elements/GridScrollArea.cpp | 20 ++++++++++++++++---- src/GUIStuff/Elements/GridScrollArea.hpp | 1 + src/Screens/FileSelectScreen.cpp | 1 + 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/GUIStuff/Elements/GridScrollArea.cpp b/src/GUIStuff/Elements/GridScrollArea.cpp index 35f3731..3890ed9 100644 --- a/src/GUIStuff/Elements/GridScrollArea.cpp +++ b/src/GUIStuff/Elements/GridScrollArea.cpp @@ -24,9 +24,21 @@ void GridScrollArea::layout(const Clay_ElementId& id, const Options& o) { size_t entriesPerRow = std::max(rowWidth / options.entryWidth, 1); size_t rowCount = (options.entryCount + entriesPerRow - 1) / entriesPerRow; opts.entryCount = rowCount; + uint16_t xPadding = 0; - if(rowCount > 1 || (rowCount == 1 && ((options.entryCount + entriesPerRow) / entriesPerRow) > 1)) // More than 1 row or 1st row is full - xPadding = static_cast(std::max(rowWidth - (entriesPerRow * options.entryWidth), 0) / (entriesPerRow + 1)); + uint16_t xChildGap = 0; + float entryWidth = options.entryWidth; + if(rowCount > 1 || (rowCount == 1 && ((options.entryCount + entriesPerRow) / entriesPerRow) > 1)) { // More than 1 row or 1st row is full + float padding = std::max(rowWidth - (entriesPerRow * options.entryWidth), 0) / (entriesPerRow + 1); + xChildGap = xPadding = padding; + if(o.entryWidthIsMinimum) { + xPadding = padding / 2; + entryWidth = padding + options.entryWidth; + xChildGap = 0; + } + else + xPadding = xChildGap = padding; + } opts.elementContent = [&] (size_t rowIndex) { gui.new_id("grid row", [&] { @@ -34,7 +46,7 @@ void GridScrollArea::layout(const Clay_ElementId& id, const Options& o) { .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}, .padding = {.left = xPadding, .right = xPadding}, - .childGap = xPadding, + .childGap = xChildGap, .childAlignment = { .x = options.childAlignmentX} } }) { @@ -44,7 +56,7 @@ void GridScrollArea::layout(const Clay_ElementId& id, const Options& o) { gui.new_id(static_cast(i - startIndex), [&] { CLAY_AUTO_ID({ .layout = { - .sizing = {.width = CLAY_SIZING_FIXED(options.entryWidth), .height = CLAY_SIZING_FIXED(options.entryHeight)}, + .sizing = {.width = CLAY_SIZING_FIXED(entryWidth), .height = CLAY_SIZING_FIXED(options.entryHeight)}, } }) { options.elementContent(i); diff --git a/src/GUIStuff/Elements/GridScrollArea.hpp b/src/GUIStuff/Elements/GridScrollArea.hpp index 975f348..2295901 100644 --- a/src/GUIStuff/Elements/GridScrollArea.hpp +++ b/src/GUIStuff/Elements/GridScrollArea.hpp @@ -14,6 +14,7 @@ class GridScrollArea : public Element { Clay_LayoutAlignmentX childAlignmentX = CLAY_ALIGN_X_LEFT; float entryHeight; size_t entryCount; + bool entryWidthIsMinimum = false; std::function elementContent; std::function innerContentExtraCallback; }; diff --git a/src/Screens/FileSelectScreen.cpp b/src/Screens/FileSelectScreen.cpp index e7b7ea4..65a0ab8 100644 --- a/src/Screens/FileSelectScreen.cpp +++ b/src/Screens/FileSelectScreen.cpp @@ -692,6 +692,7 @@ void FileSelectScreen::file_view() { .childAlignmentX = CLAY_ALIGN_X_LEFT, .entryHeight = entrySize.y(), .entryCount = fileList.size(), + .entryWidthIsMinimum = true, .elementContent = [&](size_t i) { fileButton(i, false, iconSize); }