Added some scroll area and grid fixes

This commit is contained in:
Yousef Khadadeh 2026-04-19 10:03:57 +03:00
parent 886fd313a4
commit 0853df4d2a
7 changed files with 224 additions and 23 deletions

View file

@ -1,5 +1,6 @@
#include "ScrollAreaHelpers.hpp"
#include "../GUIManager.hpp"
#include "../Elements/LayoutElement.hpp"
namespace GUIStuff { namespace ElementHelpers {
@ -15,6 +16,7 @@ ScrollArea* scroll_area_many_entries(GUIManager& gui, const char* id, const Scro
float absScrollAmount = std::fabs(params.scrollOffset->y());
size_t startPoint = absScrollAmount / options.entryHeight;
size_t elementsContainable = (params.containerDimensions.y() / options.entryHeight) + 2; // Displaying 2 more elements ensures that there isn't any empty space in the container
elementsContainable = std::min<size_t>(elementsContainable, 100);
size_t endPoint = std::min(options.entryCount, startPoint + elementsContainable);
if(startPoint != 0) {
@ -25,8 +27,19 @@ ScrollArea* scroll_area_many_entries(GUIManager& gui, const char* id, const Scro
}) { }
}
for(size_t i = startPoint; i < endPoint; i++)
gui.new_id(i, [&] { options.elementContent(i); });
gui.new_id("many element list", [&] {
for(size_t i = startPoint; i < endPoint; i++) {
gui.new_id(i, [&] {
gui.element<LayoutElement>("elem", [&] (LayoutElement*, const Clay_ElementId& lId) {
CLAY(lId, {
.layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(options.entryHeight)}}
}) {
options.elementContent(i);
}
});
});
}
});
if(endPoint != options.entryCount) {
CLAY_AUTO_ID({