From f90cf5b026ac9c5c3eac6803e10e9d9d10695248 Mon Sep 17 00:00:00 2001 From: Yousef Khadadeh Date: Wed, 1 Apr 2026 22:28:48 +0300 Subject: [PATCH] Fixed more issues in file picker --- src/GUIStuff/ElementHelpers/ScrollAreaHelpers.cpp | 4 ++-- src/GUIStuff/ElementHelpers/ScrollAreaHelpers.hpp | 2 +- src/GUIStuff/Elements/SVGIcon.cpp | 1 + src/GUIStuff/Elements/ScrollArea.cpp | 4 ++++ src/GUIStuff/Elements/ScrollArea.hpp | 1 + src/GUIStuff/GUIManager.hpp | 4 ++-- src/Toolbar.cpp | 7 ++++++- src/Toolbar.hpp | 2 ++ 8 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/GUIStuff/ElementHelpers/ScrollAreaHelpers.cpp b/src/GUIStuff/ElementHelpers/ScrollAreaHelpers.cpp index 787ff5e..5222861 100644 --- a/src/GUIStuff/ElementHelpers/ScrollAreaHelpers.cpp +++ b/src/GUIStuff/ElementHelpers/ScrollAreaHelpers.cpp @@ -3,8 +3,8 @@ namespace GUIStuff { namespace ElementHelpers { -void scroll_area_many_entries(GUIManager& gui, const char* id, const ScrollBarManyEntriesOptions& options) { - gui.clipping_element(id, ScrollArea::Options{ +ScrollArea* scroll_area_many_entries(GUIManager& gui, const char* id, const ScrollBarManyEntriesOptions& options) { + return gui.clipping_element(id, ScrollArea::Options{ .scrollVertical = true, .clipHorizontal = options.clipHorizontal, .clipVertical = true, diff --git a/src/GUIStuff/ElementHelpers/ScrollAreaHelpers.hpp b/src/GUIStuff/ElementHelpers/ScrollAreaHelpers.hpp index 5bf07c0..08bd835 100644 --- a/src/GUIStuff/ElementHelpers/ScrollAreaHelpers.hpp +++ b/src/GUIStuff/ElementHelpers/ScrollAreaHelpers.hpp @@ -11,6 +11,6 @@ struct ScrollBarManyEntriesOptions { std::function innerContentExtraCallback; }; -void scroll_area_many_entries(GUIManager& gui, const char* id, const ScrollBarManyEntriesOptions& options); +ScrollArea* scroll_area_many_entries(GUIManager& gui, const char* id, const ScrollBarManyEntriesOptions& options); }} diff --git a/src/GUIStuff/Elements/SVGIcon.cpp b/src/GUIStuff/Elements/SVGIcon.cpp index 1075daa..afe4367 100644 --- a/src/GUIStuff/Elements/SVGIcon.cpp +++ b/src/GUIStuff/Elements/SVGIcon.cpp @@ -4,6 +4,7 @@ #include #include #include "../GUIManager.hpp" +#include "Helpers/MathExtras.hpp" namespace GUIStuff { diff --git a/src/GUIStuff/Elements/ScrollArea.cpp b/src/GUIStuff/Elements/ScrollArea.cpp index 63bde99..a401146 100644 --- a/src/GUIStuff/Elements/ScrollArea.cpp +++ b/src/GUIStuff/Elements/ScrollArea.cpp @@ -138,6 +138,10 @@ void ScrollArea::layout(const Clay_ElementId& id, const Options& options) { } } +void ScrollArea::reset_scroll() { + scrollOffset = {0.0f, 0.0f}; +} + bool ScrollArea::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) { return Element::input_mouse_button_callback(button, mouseHovering); } diff --git a/src/GUIStuff/Elements/ScrollArea.hpp b/src/GUIStuff/Elements/ScrollArea.hpp index 805b985..f423810 100644 --- a/src/GUIStuff/Elements/ScrollArea.hpp +++ b/src/GUIStuff/Elements/ScrollArea.hpp @@ -26,6 +26,7 @@ class ScrollArea : public Element { }; void layout(const Clay_ElementId& id, const Options& options); + void reset_scroll(); virtual bool input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override; virtual bool input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override; diff --git a/src/GUIStuff/GUIManager.hpp b/src/GUIStuff/GUIManager.hpp index 16ae6a6..c19b708 100644 --- a/src/GUIStuff/GUIManager.hpp +++ b/src/GUIStuff/GUIManager.hpp @@ -40,8 +40,8 @@ class GUIManager { ElementType* elem = insert_element(); Clay_ElementId clayId = strArena.elem_id_from_id_stack(idStack); elem->set_parent_clipping_region(clippingRegion); - elem->set_bounding_box_from_elem_data(Clay_GetElementData(clayId)); elem->layout(clayId, a...); + elem->set_bounding_box_from_elem_data(Clay_GetElementData(clayId)); // Setting bounding box after layout ensures that the element will have its bounding box set if it's set to be drawn. pop_id(); return elem; } @@ -50,7 +50,6 @@ class GUIManager { push_id(id); ElementType* elem = insert_element(); Clay_ElementId clayId = strArena.elem_id_from_id_stack(idStack); - elem->set_bounding_box_from_elem_data(Clay_GetElementData(clayId)); elem->set_parent_clipping_region(clippingRegion); auto oldClippingRegion = clippingRegion; if(elem->get_bb().has_value()) { @@ -60,6 +59,7 @@ class GUIManager { clippingRegion = elem->get_bb(); } elem->layout(clayId, a...); + elem->set_bounding_box_from_elem_data(Clay_GetElementData(clayId)); clippingRegion = oldClippingRegion; pop_id(); return elem; diff --git a/src/Toolbar.cpp b/src/Toolbar.cpp index 3e4c9e0..e2af8b2 100644 --- a/src/Toolbar.cpp +++ b/src/Toolbar.cpp @@ -151,6 +151,7 @@ void Toolbar::open_file_selector(const std::string& filePickerName, const std::v filePicker.postSelectionFunc = postSelectionFunc; filePicker.fileName = ""; filePicker.isSaving = isSaving; + filePicker.entriesScrollArea = nullptr; file_picker_gui_refresh_entries(); } } @@ -2055,6 +2056,9 @@ void Toolbar::file_picker_gui_refresh_entries() { return std::lexicographical_compare(aStr.begin(), aStr.end(), bStr.begin(), bStr.end()); }); + if(filePicker.entriesScrollArea) + filePicker.entriesScrollArea->reset_scroll(); + gui.set_to_layout(); } @@ -2065,6 +2069,7 @@ void Toolbar::file_picker_gui_done() { pathToRet = force_extension_on_path(pathToRet, filePicker.extensionFiltersComplete[filePicker.extensionSelected].extensions); filePicker.postSelectionFunc(pathToRet, filePicker.extensionFiltersComplete[filePicker.extensionSelected]); } + filePicker.entriesScrollArea = nullptr; filePicker.isOpen = false; } @@ -2096,7 +2101,7 @@ void Toolbar::file_picker_gui() { .backgroundColor = convert_vec4(io.theme->backColor2) }) { constexpr float entryHeight = 25.0f; - scroll_area_many_entries(gui, "file picker entries", { + filePicker.entriesScrollArea = scroll_area_many_entries(gui, "file picker entries", { .entryHeight = entryHeight, .entryCount = filePicker.entries.size(), .clipHorizontal = false, diff --git a/src/Toolbar.hpp b/src/Toolbar.hpp index 333c7da..efd8130 100644 --- a/src/Toolbar.hpp +++ b/src/Toolbar.hpp @@ -1,4 +1,5 @@ #pragma once +#include "GUIStuff/Elements/ScrollArea.hpp" #include "GUIStuff/GUIManager.hpp" #include "DrawData.hpp" #include "Helpers/FileDownloader.hpp" @@ -196,6 +197,7 @@ class Toolbar { std::string fileName = ""; bool isSaving = false; size_t extensionSelected; + GUIStuff::ScrollArea* entriesScrollArea = nullptr; OpenFileSelectorCallback postSelectionFunc; } filePicker;