From 4e1ab6fc50ad4fb1cb564520c2eda62637870835 Mon Sep 17 00:00:00 2001 From: Yousef Khadadeh Date: Sun, 19 Apr 2026 13:37:16 +0300 Subject: [PATCH] Fixed more issues with grid and scroll area --- src/GUIHolder.cpp | 2 +- src/GUIStuff/ElementHelpers/ScrollAreaHelpers.cpp | 6 ++++-- src/GUIStuff/Elements/GridScrollArea.cpp | 2 +- src/GUIStuff/Elements/SelectableButton.cpp | 4 +--- src/GUIStuff/GUIManager.cpp | 14 +------------- src/Screens/FileSelectScreen.cpp | 10 +--------- 6 files changed, 9 insertions(+), 29 deletions(-) diff --git a/src/GUIHolder.cpp b/src/GUIHolder.cpp index 29df2bd..d840ba9 100644 --- a/src/GUIHolder.cpp +++ b/src/GUIHolder.cpp @@ -125,7 +125,7 @@ void GUIHolder::draw(SkCanvas* canvas, bool skiaAA) { gui.io.redrawSurface = true; } - gui.draw_force(canvas, skiaAA); + gui.draw(canvas, skiaAA); } void GUIHolder::input_paste_callback(const CustomEvents::PasteEvent& paste) { diff --git a/src/GUIStuff/ElementHelpers/ScrollAreaHelpers.cpp b/src/GUIStuff/ElementHelpers/ScrollAreaHelpers.cpp index 81b5087..fac18fa 100644 --- a/src/GUIStuff/ElementHelpers/ScrollAreaHelpers.cpp +++ b/src/GUIStuff/ElementHelpers/ScrollAreaHelpers.cpp @@ -13,10 +13,12 @@ ScrollArea* scroll_area_many_entries(GUIManager& gui, const char* id, const Scro .innerContent = [&](const ScrollArea::InnerContentParameters& params) { if(options.innerContentExtraCallback) options.innerContentExtraCallback(params); + if(params.containerDimensions.y() == 0.0f) + 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 - elementsContainable = std::min(elementsContainable, 100); size_t endPoint = std::min(options.entryCount, startPoint + elementsContainable); if(startPoint != 0) { @@ -29,7 +31,7 @@ ScrollArea* scroll_area_many_entries(GUIManager& gui, const char* id, const Scro gui.new_id("many element list", [&] { for(size_t i = startPoint; i < endPoint; i++) { - gui.new_id(i, [&] { + gui.new_id(i - startPoint, [&] { gui.element("elem", [&] (LayoutElement*, const Clay_ElementId& lId) { CLAY(lId, { .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(options.entryHeight)}} diff --git a/src/GUIStuff/Elements/GridScrollArea.cpp b/src/GUIStuff/Elements/GridScrollArea.cpp index e9f24e6..34e8ded 100644 --- a/src/GUIStuff/Elements/GridScrollArea.cpp +++ b/src/GUIStuff/Elements/GridScrollArea.cpp @@ -34,7 +34,7 @@ void GridScrollArea::layout(const Clay_ElementId& id, const Options& o) { size_t startIndex = rowIndex * entriesPerRow; size_t endIndex = std::min(rowIndex * entriesPerRow + entriesPerRow, o.entryCount); for(size_t i = startIndex; i < endIndex; i++) { - gui.new_id(static_cast(i), [&] { + gui.new_id(static_cast(i - startIndex), [&] { CLAY_AUTO_ID({ .layout = {.sizing = {.width = CLAY_SIZING_FIXED(entryWidth), .height = CLAY_SIZING_FIXED(options.entryHeight)}} }) { diff --git a/src/GUIStuff/Elements/SelectableButton.cpp b/src/GUIStuff/Elements/SelectableButton.cpp index f8835a9..ffe19a3 100644 --- a/src/GUIStuff/Elements/SelectableButton.cpp +++ b/src/GUIStuff/Elements/SelectableButton.cpp @@ -72,10 +72,8 @@ void SelectableButton::input_mouse_button_callback(const InputManager::MouseButt bool oldIsHeld = isHeld; isHeld = mouseHovering && button.button == InputManager::MouseButton::LEFT && button.down; if(isHeld) { - if(instantResponse) { - std::cout << "INSTANT" << std::endl; + if(instantResponse) gui.set_post_callback_func(onClick); - } gui.set_to_layout(); } else if(mouseHovering && oldIsHeld && button.button == InputManager::MouseButton::LEFT && !button.down) { diff --git a/src/GUIStuff/GUIManager.cpp b/src/GUIStuff/GUIManager.cpp index 576976e..0c9eb4b 100644 --- a/src/GUIStuff/GUIManager.cpp +++ b/src/GUIStuff/GUIManager.cpp @@ -7,33 +7,21 @@ #include #include #include "Elements/GUIStuffHelpers.hpp" -#include "Elements/SVGIcon.hpp" -#include "Elements/FontPicker.hpp" -#include "Elements/SelectableButton.hpp" -#include "Elements/RotateWheel.hpp" -#include "Elements/TextParagraph.hpp" -#include "Elements/MovableTabList.hpp" -#include "Elements/Element.hpp" -#include "Elements/TextParagraph.hpp" #include -#include -#include #include -#include -#include #include #include #include #include #include #include -#include "../FontData.hpp" namespace GUIStuff { GUIManager::GUIManager() { Clay_SetMaxMeasureTextCacheWordCount(100000); + Clay_SetMaxElementCount(32768); clayArena = Clay_CreateArenaWithCapacityAndMemory(Clay_MinMemorySize(), malloc(Clay_MinMemorySize())); clayInstance = Clay_Initialize(clayArena, Clay_Dimensions(1.0f, 1.0f), (Clay_ErrorHandler)clay_error_handler); Clay_SetMeasureTextFunction(clay_skia_measure_text, this); diff --git a/src/Screens/FileSelectScreen.cpp b/src/Screens/FileSelectScreen.cpp index 757dcea..bb2e8fb 100644 --- a/src/Screens/FileSelectScreen.cpp +++ b/src/Screens/FileSelectScreen.cpp @@ -23,19 +23,11 @@ void FileSelectScreen::gui_layout_run() { }, }) { text_label(gui, "Test grid"); - //scroll_area_many_entries(gui, "Test scroll", ScrollBarManyEntriesOptions{ - // .entryHeight = 100.0f, - // .entryCount = 2000, - // .clipHorizontal = true, - // .elementContent = [&] (size_t i) { - // text_button_sized(gui, "button", "Square " + std::to_string(i), CLAY_SIZING_GROW(0), CLAY_SIZING_GROW(0)); - // } - //}); gui.element("Test grid", GridScrollArea::Options{ .entryMaximumWidth = 100.0f, .childAlignmentX = CLAY_ALIGN_X_LEFT, .entryHeight = 100.0f, - .entryCount = 200, + .entryCount = 20000, .elementContent = [&](size_t i) { CLAY_AUTO_ID({ .layout = {