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 {
|
namespace GUIStuff { namespace ElementHelpers {
|
||||||
|
|
||||||
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) {
|
||||||
gui.clipping_element<ScrollArea>(id, ScrollArea::Options{
|
return gui.clipping_element<ScrollArea>(id, ScrollArea::Options{
|
||||||
.scrollVertical = true,
|
.scrollVertical = true,
|
||||||
.clipHorizontal = options.clipHorizontal,
|
.clipHorizontal = options.clipHorizontal,
|
||||||
.clipVertical = true,
|
.clipVertical = true,
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,6 @@ struct ScrollBarManyEntriesOptions {
|
||||||
std::function<void(const ScrollArea::InnerContentParameters&)> innerContentExtraCallback;
|
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 <include/core/SkColorSpace.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "../GUIManager.hpp"
|
#include "../GUIManager.hpp"
|
||||||
|
#include "Helpers/MathExtras.hpp"
|
||||||
|
|
||||||
namespace GUIStuff {
|
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) {
|
bool ScrollArea::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) {
|
||||||
return Element::input_mouse_button_callback(button, 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 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_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override;
|
||||||
virtual bool input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, 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>();
|
ElementType* elem = insert_element<ElementType>();
|
||||||
Clay_ElementId clayId = strArena.elem_id_from_id_stack(idStack);
|
Clay_ElementId clayId = strArena.elem_id_from_id_stack(idStack);
|
||||||
elem->set_parent_clipping_region(clippingRegion);
|
elem->set_parent_clipping_region(clippingRegion);
|
||||||
elem->set_bounding_box_from_elem_data(Clay_GetElementData(clayId));
|
|
||||||
elem->layout(clayId, a...);
|
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();
|
pop_id();
|
||||||
return elem;
|
return elem;
|
||||||
}
|
}
|
||||||
|
|
@ -50,7 +50,6 @@ class GUIManager {
|
||||||
push_id(id);
|
push_id(id);
|
||||||
ElementType* elem = insert_element<ElementType>();
|
ElementType* elem = insert_element<ElementType>();
|
||||||
Clay_ElementId clayId = strArena.elem_id_from_id_stack(idStack);
|
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);
|
elem->set_parent_clipping_region(clippingRegion);
|
||||||
auto oldClippingRegion = clippingRegion;
|
auto oldClippingRegion = clippingRegion;
|
||||||
if(elem->get_bb().has_value()) {
|
if(elem->get_bb().has_value()) {
|
||||||
|
|
@ -60,6 +59,7 @@ class GUIManager {
|
||||||
clippingRegion = elem->get_bb();
|
clippingRegion = elem->get_bb();
|
||||||
}
|
}
|
||||||
elem->layout(clayId, a...);
|
elem->layout(clayId, a...);
|
||||||
|
elem->set_bounding_box_from_elem_data(Clay_GetElementData(clayId));
|
||||||
clippingRegion = oldClippingRegion;
|
clippingRegion = oldClippingRegion;
|
||||||
pop_id();
|
pop_id();
|
||||||
return elem;
|
return elem;
|
||||||
|
|
|
||||||
|
|
@ -151,6 +151,7 @@ void Toolbar::open_file_selector(const std::string& filePickerName, const std::v
|
||||||
filePicker.postSelectionFunc = postSelectionFunc;
|
filePicker.postSelectionFunc = postSelectionFunc;
|
||||||
filePicker.fileName = "";
|
filePicker.fileName = "";
|
||||||
filePicker.isSaving = isSaving;
|
filePicker.isSaving = isSaving;
|
||||||
|
filePicker.entriesScrollArea = nullptr;
|
||||||
file_picker_gui_refresh_entries();
|
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());
|
return std::lexicographical_compare(aStr.begin(), aStr.end(), bStr.begin(), bStr.end());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if(filePicker.entriesScrollArea)
|
||||||
|
filePicker.entriesScrollArea->reset_scroll();
|
||||||
|
|
||||||
gui.set_to_layout();
|
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);
|
pathToRet = force_extension_on_path(pathToRet, filePicker.extensionFiltersComplete[filePicker.extensionSelected].extensions);
|
||||||
filePicker.postSelectionFunc(pathToRet, filePicker.extensionFiltersComplete[filePicker.extensionSelected]);
|
filePicker.postSelectionFunc(pathToRet, filePicker.extensionFiltersComplete[filePicker.extensionSelected]);
|
||||||
}
|
}
|
||||||
|
filePicker.entriesScrollArea = nullptr;
|
||||||
filePicker.isOpen = false;
|
filePicker.isOpen = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2096,7 +2101,7 @@ void Toolbar::file_picker_gui() {
|
||||||
.backgroundColor = convert_vec4<Clay_Color>(io.theme->backColor2)
|
.backgroundColor = convert_vec4<Clay_Color>(io.theme->backColor2)
|
||||||
}) {
|
}) {
|
||||||
constexpr float entryHeight = 25.0f;
|
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,
|
.entryHeight = entryHeight,
|
||||||
.entryCount = filePicker.entries.size(),
|
.entryCount = filePicker.entries.size(),
|
||||||
.clipHorizontal = false,
|
.clipHorizontal = false,
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "GUIStuff/Elements/ScrollArea.hpp"
|
||||||
#include "GUIStuff/GUIManager.hpp"
|
#include "GUIStuff/GUIManager.hpp"
|
||||||
#include "DrawData.hpp"
|
#include "DrawData.hpp"
|
||||||
#include "Helpers/FileDownloader.hpp"
|
#include "Helpers/FileDownloader.hpp"
|
||||||
|
|
@ -196,6 +197,7 @@ class Toolbar {
|
||||||
std::string fileName = "";
|
std::string fileName = "";
|
||||||
bool isSaving = false;
|
bool isSaving = false;
|
||||||
size_t extensionSelected;
|
size_t extensionSelected;
|
||||||
|
GUIStuff::ScrollArea* entriesScrollArea = nullptr;
|
||||||
OpenFileSelectorCallback postSelectionFunc;
|
OpenFileSelectorCallback postSelectionFunc;
|
||||||
} filePicker;
|
} filePicker;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue