Expand width of grid elements to fit longer names
This commit is contained in:
parent
4c30939882
commit
cd45d1e8cd
3 changed files with 18 additions and 4 deletions
|
|
@ -24,9 +24,21 @@ void GridScrollArea::layout(const Clay_ElementId& id, const Options& o) {
|
||||||
size_t entriesPerRow = std::max<size_t>(rowWidth / options.entryWidth, 1);
|
size_t entriesPerRow = std::max<size_t>(rowWidth / options.entryWidth, 1);
|
||||||
size_t rowCount = (options.entryCount + entriesPerRow - 1) / entriesPerRow;
|
size_t rowCount = (options.entryCount + entriesPerRow - 1) / entriesPerRow;
|
||||||
opts.entryCount = rowCount;
|
opts.entryCount = rowCount;
|
||||||
|
|
||||||
uint16_t xPadding = 0;
|
uint16_t xPadding = 0;
|
||||||
if(rowCount > 1 || (rowCount == 1 && ((options.entryCount + entriesPerRow) / entriesPerRow) > 1)) // More than 1 row or 1st row is full
|
uint16_t xChildGap = 0;
|
||||||
xPadding = static_cast<float>(std::max<float>(rowWidth - (entriesPerRow * options.entryWidth), 0) / (entriesPerRow + 1));
|
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<float>(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) {
|
opts.elementContent = [&] (size_t rowIndex) {
|
||||||
gui.new_id("grid row", [&] {
|
gui.new_id("grid row", [&] {
|
||||||
|
|
@ -34,7 +46,7 @@ void GridScrollArea::layout(const Clay_ElementId& id, const Options& o) {
|
||||||
.layout = {
|
.layout = {
|
||||||
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)},
|
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)},
|
||||||
.padding = {.left = xPadding, .right = xPadding},
|
.padding = {.left = xPadding, .right = xPadding},
|
||||||
.childGap = xPadding,
|
.childGap = xChildGap,
|
||||||
.childAlignment = { .x = options.childAlignmentX}
|
.childAlignment = { .x = options.childAlignmentX}
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
|
|
@ -44,7 +56,7 @@ void GridScrollArea::layout(const Clay_ElementId& id, const Options& o) {
|
||||||
gui.new_id(static_cast<int64_t>(i - startIndex), [&] {
|
gui.new_id(static_cast<int64_t>(i - startIndex), [&] {
|
||||||
CLAY_AUTO_ID({
|
CLAY_AUTO_ID({
|
||||||
.layout = {
|
.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);
|
options.elementContent(i);
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ class GridScrollArea : public Element {
|
||||||
Clay_LayoutAlignmentX childAlignmentX = CLAY_ALIGN_X_LEFT;
|
Clay_LayoutAlignmentX childAlignmentX = CLAY_ALIGN_X_LEFT;
|
||||||
float entryHeight;
|
float entryHeight;
|
||||||
size_t entryCount;
|
size_t entryCount;
|
||||||
|
bool entryWidthIsMinimum = false;
|
||||||
std::function<void(size_t elementIndex)> elementContent;
|
std::function<void(size_t elementIndex)> elementContent;
|
||||||
std::function<void(const ScrollArea::InnerContentParameters&)> innerContentExtraCallback;
|
std::function<void(const ScrollArea::InnerContentParameters&)> innerContentExtraCallback;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -692,6 +692,7 @@ void FileSelectScreen::file_view() {
|
||||||
.childAlignmentX = CLAY_ALIGN_X_LEFT,
|
.childAlignmentX = CLAY_ALIGN_X_LEFT,
|
||||||
.entryHeight = entrySize.y(),
|
.entryHeight = entrySize.y(),
|
||||||
.entryCount = fileList.size(),
|
.entryCount = fileList.size(),
|
||||||
|
.entryWidthIsMinimum = true,
|
||||||
.elementContent = [&](size_t i) {
|
.elementContent = [&](size_t i) {
|
||||||
fileButton(i, false, iconSize);
|
fileButton(i, false, iconSize);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue