Fixed many element scroll area and added color palette picker

This commit is contained in:
Yousef Khadadeh 2026-04-30 14:45:36 +03:00
parent c90c09b169
commit c1cd3e4e49
14 changed files with 156 additions and 124 deletions

View file

@ -1,72 +0,0 @@
#include "ScrollAreaHelpers.hpp"
#include "../GUIManager.hpp"
#include "Helpers/ConvertVec.hpp"
namespace GUIStuff { namespace ElementHelpers {
ScrollArea* scroll_area_many_entries(GUIManager& gui, const char* id, const ScrollBarManyEntriesOptions& options) {
return gui.clipping_element<ScrollArea>(id, ScrollArea::Options{
.scrollVertical = true,
.clipHorizontal = options.clipHorizontal,
.clipVertical = true,
.scrollbarY = options.scrollbar,
.xAlign = options.xAlign,
.yAlign = CLAY_ALIGN_Y_TOP,
.innerContent = [&](const ScrollArea::InnerContentParameters& params) {
if(options.innerContentExtraCallback) options.innerContentExtraCallback(params);
if(params.containerDimensions.y() == 0.0f) {
if(options.growing) {
CLAY_AUTO_ID({
.layout = {
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(1)},
}
}) { }
}
else {
CLAY_AUTO_ID({
.layout = {
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)},
}
}) { }
}
return;
}
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
size_t endPoint = std::min(options.entryCount, startPoint + elementsContainable);
if(startPoint != 0) {
CLAY_AUTO_ID({
.layout = {
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(startPoint * options.entryHeight)},
}
}) { }
}
gui.new_id("many element list", [&] {
for(size_t i = startPoint; i < endPoint; i++) {
gui.new_id(i - startPoint, [&] {
CLAY_AUTO_ID({
.layout = { .sizing = {.width = options.xElementSize, .height = CLAY_SIZING_FIXED(options.entryHeight)}}
}) {
options.elementContent(i);
}
});
}
});
if(endPoint != options.entryCount) {
CLAY_AUTO_ID({
.layout = {
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED((options.entryCount - endPoint) * options.entryHeight)},
}
}) { }
}
}
});
}
}}

View file

@ -1,21 +0,0 @@
#pragma once
#include "../Elements/ScrollArea.hpp"
#include "Helpers/ConvertVec.hpp"
namespace GUIStuff { namespace ElementHelpers {
struct ScrollBarManyEntriesOptions {
float entryHeight;
size_t entryCount;
bool clipHorizontal = false;
bool growing = false; // If set to false, this element has a fixed size. Otherwise, is a growing element.
Clay_LayoutAlignmentX xAlign = CLAY_ALIGN_X_LEFT;
Clay_SizingAxis xElementSize = CLAY_SIZING_GROW(0);
ScrollArea::ScrollbarType scrollbar = ScrollArea::ScrollbarType::NORMAL;
std::function<void(size_t elementIndex)> elementContent;
std::function<void(const ScrollArea::InnerContentParameters&)> innerContentExtraCallback;
};
ScrollArea* scroll_area_many_entries(GUIManager& gui, const char* id, const ScrollBarManyEntriesOptions& options);
}}