Fixed more issues in file picker
This commit is contained in:
parent
10217e97f4
commit
f90cf5b026
8 changed files with 19 additions and 6 deletions
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
namespace GUIStuff { namespace ElementHelpers {
|
||||
|
||||
void scroll_area_many_entries(GUIManager& gui, const char* id, const ScrollBarManyEntriesOptions& options) {
|
||||
gui.clipping_element<ScrollArea>(id, ScrollArea::Options{
|
||||
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,
|
||||
|
|
|
|||
|
|
@ -11,6 +11,6 @@ struct ScrollBarManyEntriesOptions {
|
|||
std::function<void(const ScrollArea::InnerContentParameters&)> 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);
|
||||
|
||||
}}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include <include/core/SkColorSpace.h>
|
||||
#include <iostream>
|
||||
#include "../GUIManager.hpp"
|
||||
#include "Helpers/MathExtras.hpp"
|
||||
|
||||
namespace GUIStuff {
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -40,8 +40,8 @@ class GUIManager {
|
|||
ElementType* elem = insert_element<ElementType>();
|
||||
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<ElementType>();
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -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<Clay_Color>(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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue