diff --git a/src/GUIStuff/Elements/ColorPicker.decl.hpp b/src/GUIStuff/Elements/ColorPicker.decl.hpp index fca2041..626a4fe 100644 --- a/src/GUIStuff/Elements/ColorPicker.decl.hpp +++ b/src/GUIStuff/Elements/ColorPicker.decl.hpp @@ -78,6 +78,7 @@ template class ColorPicker : public Element { static constexpr float BAR_GAP = 5.0; T* data; + std::optional oldData; Vector3f savedHsv; // We save the HSV so that conversion doesnt ruin the UI std::function onChange; bool selectAlpha = false; diff --git a/src/GUIStuff/Elements/ColorPicker.impl.hpp b/src/GUIStuff/Elements/ColorPicker.impl.hpp index fcf9f6d..9cdd747 100644 --- a/src/GUIStuff/Elements/ColorPicker.impl.hpp +++ b/src/GUIStuff/Elements/ColorPicker.impl.hpp @@ -8,7 +8,10 @@ template ColorPicker::ColorPicker(GUIManager& gui): Element(gui) template void ColorPicker::layout(const Clay_ElementId& id, T* data, bool selectAlpha, const std::function& onChange) { this->data = data; - savedHsv = rgb_to_hsv(*data); + if(!oldData.has_value() || oldData.value() != *data) { + savedHsv = rgb_to_hsv(*data); + oldData = *data; + } this->selectAlpha = selectAlpha; this->onChange = onChange; @@ -121,7 +124,7 @@ template void ColorPicker::update_color_picker_pos(const Vector2 savedHsv.y() = newSv.x(); savedHsv.z() = 1.0f - newSv.y(); set_hsv(savedHsv); - gui.set_post_callback_func([&]{if(onChange) onChange();}); + if(onChange) onChange(); break; } case HeldBar::HUE_HELD: { @@ -129,14 +132,15 @@ template void ColorPicker::update_color_picker_pos(const Vector2 Vector2f hueDim = get_hue_bar_dim(); savedHsv.x() = (1.0f - std::clamp((p.y() - huePos.y()) / hueDim.y(), 0.0f, 1.0f)) * 360.0f; set_hsv(savedHsv); - gui.set_post_callback_func([&]{if(onChange) onChange();}); + if(onChange) onChange(); break; } case HeldBar::ALPHA_HELD: { Vector2f alphaPos = get_alpha_bar_pos(); Vector2f alphaDim = get_alpha_bar_dim(); (*data)[3] = std::clamp((p.x() - alphaPos.x()) / alphaDim.x(), 0.0f, 1.0f); - gui.set_post_callback_func([&]{if(onChange) onChange();}); + oldData = *data; + if(onChange) onChange(); break; } } @@ -169,6 +173,7 @@ template void ColorPicker::set_hsv(const Vector3f& hsv) { (*data)[0] = a.x(); (*data)[1] = a.y(); (*data)[2] = a.z(); + oldData = *data; } } diff --git a/src/GUIStuff/Elements/ScrollArea.cpp b/src/GUIStuff/Elements/ScrollArea.cpp index 66b7c16..63bde99 100644 --- a/src/GUIStuff/Elements/ScrollArea.cpp +++ b/src/GUIStuff/Elements/ScrollArea.cpp @@ -120,12 +120,16 @@ void ScrollArea::layout(const Clay_ElementId& id, const Options& options) { gui.set_to_layout(); } if(isScrollbarHeldY) { + float oldScrollOffset = scrollOffset.y(); + float newScrollPosFrac; newScrollPosFrac = std::clamp((scrollerStartPosY - (mouseStartPosY - motion.pos.y()) - sAreaStart - scrollerSize * 0.5f) / (sAreaDim - scrollerSize), 0.0f, 1.0f); scrollOffset.y() = newScrollPosFrac * (-scrollPosMax); clamp_scroll(); - gui.set_to_layout(); + + if(oldScrollOffset != scrollOffset.y()) + gui.set_to_layout(); } return mouseHovering; } @@ -149,12 +153,16 @@ void ScrollArea::clamp_scroll() { bool ScrollArea::input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel, bool mouseHovering) { if(mouseHovering) { + Vector2f oldScrollOffset = scrollOffset; + if(opts.scrollVertical) scrollOffset.y() = scrollOffset.y() + wheel.amount.y() * 10.0f; if(opts.scrollHorizontal) scrollOffset.y() = scrollOffset.x() + wheel.amount.x() * 10.0f; clamp_scroll(); - gui.set_to_layout(); + + if(oldScrollOffset != scrollOffset) + gui.set_to_layout(); } return Element::input_mouse_wheel_callback(wheel, mouseHovering); }