#pragma once #include #include #include "GUIManagerID.hpp" #include #include "Elements/Element.hpp" using namespace Eigen; namespace GUIStuff { class GUIManager { public: struct ElementContainer { std::unique_ptr elem; bool isUsedThisFrame; }; GUIManager(); void draw(SkCanvas* canvas, bool skiaAA); void set_to_layout(); void layout_if_necessary(); void update_window(const Vector2f& windowPos, const Vector2f& windowSize, float guiScaleMultiplier); std::shared_ptr io; GUIManagerIDStack idStack; std::unordered_map elements; void new_id(const char* id, const std::function& f); void new_id(int64_t id, const std::function& f); void set_post_callback_func(const std::function& f); int16_t zIndex = 0; template ElementType* element(const char* id, const Args&... a) { push_id(id); ElementType* elem = insert_element(); elem->layout(a...); pop_id(); return elem; } DefaultStringArena strArena; private: void layout(); void update_element_bounding_boxes(); void layout_begin(); void layout_end(); void single_layout_run(); template NewElement* insert_element() { auto [it, inserted] = elements.emplace(idStack, ElementContainer()); auto& container = it->second; if(inserted) container = {std::make_unique(*this)}; container.elem->zIndex = zIndex; container.isUsedThisFrame = true; return static_cast(it->second.elem.get()); } static void clay_error_handler(Clay_ErrorData errorData); static Clay_Dimensions clay_skia_measure_text(Clay_StringSlice str, Clay_TextElementConfig* config, void* userData); void push_id(int64_t id); void push_id(const char* id); void pop_id(); std::function postCallbackFunc; Clay_Context* clayInstance; Clay_Arena clayArena; Clay_RenderCommandArray renderCommands; bool setToLayout; }; }