diff --git a/src/GUIStuff/Elements/CheckBox.cpp b/src/GUIStuff/Elements/CheckBox.cpp index 4e11541..9b7dac6 100644 --- a/src/GUIStuff/Elements/CheckBox.cpp +++ b/src/GUIStuff/Elements/CheckBox.cpp @@ -13,7 +13,7 @@ void CheckBox::update(UpdateInputData& io, bool newIsTicked, const std::function }) { selection.update(Clay_Hovered(), io.mouse.leftClick, io.mouse.leftHeld); if(isTicked != newIsTicked) { - hoverAnimation2 = CHECKBOX_ANIMATION_TIME; + hoverAnimation2 = selection.hovered ? CHECKBOX_ANIMATION_TIME : 0.0f; isTicked = newIsTicked; } if(elemUpdate) diff --git a/src/GUIStuff/Elements/ColorPicker.hpp b/src/GUIStuff/Elements/ColorPicker.hpp index 3b9d5e5..01a409b 100644 --- a/src/GUIStuff/Elements/ColorPicker.hpp +++ b/src/GUIStuff/Elements/ColorPicker.hpp @@ -22,8 +22,9 @@ template class ColorPicker : public Element { CLAY({ .layout = { - .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(bb.width()) } + .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0) } }, + .aspectRatio = 1.0f, .custom = { .customData = this } }) { selection.update(Clay_Hovered(), io.mouse.leftClick, io.mouse.leftHeld); diff --git a/src/GUIStuff/GUIManager.cpp b/src/GUIStuff/GUIManager.cpp index a1a9126..d7e0135 100644 --- a/src/GUIStuff/GUIManager.cpp +++ b/src/GUIStuff/GUIManager.cpp @@ -36,6 +36,9 @@ Clay_Dimensions GUIManager::clay_skia_measure_text(Clay_StringSlice str, Clay_Te } void GUIManager::begin() { + for(auto& [id, e] : elements) + e.isUsedThisFrame = false; + io->mouse.pos = io->mouse.globalPos - windowPos; io->strArena = &strArena; Clay_SetLayoutDimensions(Clay_Dimensions(windowSize.x(), windowSize.y())); @@ -52,6 +55,9 @@ void GUIManager::end() { renderCommands = Clay_EndLayout(); if(!idStack.empty()) throw std::runtime_error("[GUIManager::end] ID Stack is not empty on end (push_id and pop_id calls not equal)"); + std::erase_if(elements, [](auto& p) { + return !p.second.isUsedThisFrame; + }); } void GUIManager::draw(SkCanvas* canvas) { diff --git a/src/GUIStuff/GUIManager.hpp b/src/GUIStuff/GUIManager.hpp index e33ba26..b73b676 100644 --- a/src/GUIStuff/GUIManager.hpp +++ b/src/GUIStuff/GUIManager.hpp @@ -23,6 +23,7 @@ class GUIManager { struct ElementContainer { std::unique_ptr elem; std::any extra; + bool isUsedThisFrame; }; GUIManager(); @@ -90,15 +91,19 @@ class GUIManager { template NewElement* insert_element() { auto [it, inserted] = elements.emplace(idStack, ElementContainer()); + auto& container = it->second; if(inserted) - it->second = {std::make_unique()}; + container = {std::make_unique()}; + container.isUsedThisFrame = true; return static_cast(it->second.elem.get()); } template T& insert_any(const T& def) { auto [it, inserted] = elements.emplace(idStack, ElementContainer()); + auto& container = it->second; if(inserted) it->second.extra = def; + container.isUsedThisFrame = true; return std::any_cast(it->second.extra); }