diff --git a/src/GUIStuff/Elements/ScrollArea.cpp b/src/GUIStuff/Elements/ScrollArea.cpp index 3f6fea2..9a4308f 100644 --- a/src/GUIStuff/Elements/ScrollArea.cpp +++ b/src/GUIStuff/Elements/ScrollArea.cpp @@ -36,7 +36,13 @@ void ScrollArea::layout(const Clay_ElementId& id, const Options& options) { }, .clip = {.horizontal = opts.clipHorizontal, .vertical = opts.clipVertical, .childOffset = {.x = scrollOffset.x(), .y = scrollOffset.y()}} }) { - opts.innerContent({.contentDimensions = contentDimensions, .containerDimensions = containerDimensions, .scrollOffset = &scrollOffset}); + if(scrollData.contentDimensions.height > scrollData.scrollContainerDimensions.height) { + gui.in_dynamic_area([&] { + opts.innerContent({.contentDimensions = contentDimensions, .containerDimensions = containerDimensions, .scrollOffset = &scrollOffset}); + }); + } + else + opts.innerContent({.contentDimensions = contentDimensions, .containerDimensions = containerDimensions, .scrollOffset = &scrollOffset}); clamp_scroll(); } diff --git a/src/GUIStuff/Elements/SelectableButton.cpp b/src/GUIStuff/Elements/SelectableButton.cpp index 68950ed..49030e2 100644 --- a/src/GUIStuff/Elements/SelectableButton.cpp +++ b/src/GUIStuff/Elements/SelectableButton.cpp @@ -14,6 +14,7 @@ void SelectableButton::layout(const Clay_ElementId& id, const Data& d) { SkColor4f backgroundColorHighlight; SkColor4f backgroundColor; + inDynamicArea = gui.is_dynamic_area(); instantResponse = d.instantResponse; onClick = [&, this, d] { if(d.onClickButton) @@ -112,7 +113,7 @@ void SelectableButton::input_finger_touch_callback(const InputManager::FingerTou } void SelectableButton::input_finger_motion_callback(const InputManager::FingerMotionCallbackArgs& motion) { - if(isHovering || isHeld) { + if((isHovering || isHeld) && (inDynamicArea || !mouseHovering)) { isHovering = false; isHeld = false; gui.set_to_layout(); diff --git a/src/GUIStuff/Elements/SelectableButton.hpp b/src/GUIStuff/Elements/SelectableButton.hpp index d1ca940..1cd6921 100644 --- a/src/GUIStuff/Elements/SelectableButton.hpp +++ b/src/GUIStuff/Elements/SelectableButton.hpp @@ -35,6 +35,7 @@ class SelectableButton : public Element { virtual void input_finger_motion_callback(const InputManager::FingerMotionCallbackArgs& motion) override; private: + bool inDynamicArea = false; bool instantResponse = false; bool isHeld = false; bool isHovering = false; diff --git a/src/GUIStuff/GUIManager.cpp b/src/GUIStuff/GUIManager.cpp index 93e4f75..845da4b 100644 --- a/src/GUIStuff/GUIManager.cpp +++ b/src/GUIStuff/GUIManager.cpp @@ -588,6 +588,17 @@ void GUIManager::clay_error_handler(Clay_ErrorData errorData) { Logger::get().log("INFO", "[Clay Error] " + std::string(errorData.errorText.chars)); } +void GUIManager::in_dynamic_area(const std::function& f) { + bool oldDynamicArea = dynamicArea; + dynamicArea = true; + f(); + dynamicArea = oldDynamicArea; +} + +bool GUIManager::is_dynamic_area() { + return dynamicArea; +} + void GUIManager::new_id(const char* id, const std::function& f) { push_id(id); f(); diff --git a/src/GUIStuff/GUIManager.hpp b/src/GUIStuff/GUIManager.hpp index a9ba4b7..1a5a003 100644 --- a/src/GUIStuff/GUIManager.hpp +++ b/src/GUIStuff/GUIManager.hpp @@ -30,6 +30,9 @@ class GUIManager { UpdateInputData io; + void in_dynamic_area(const std::function& f); + bool is_dynamic_area(); + void new_id(const char* id, const std::function& f); void new_id(int64_t id, const std::function& f); @@ -139,6 +142,7 @@ class GUIManager { int16_t zIndex = 0; Element* parentElement = nullptr; + bool dynamicArea = false; std::optional> clippingRegion; std::function postCallbackFunc;