Fixed rotation wheel

This commit is contained in:
Yousef Khadadeh 2026-03-31 20:52:46 +03:00
parent ed36036aea
commit 80afacfcbd
9 changed files with 50 additions and 33 deletions

View file

@ -18,6 +18,7 @@ template <typename T> void ColorPickerButton<T>::layout(const Clay_ElementId& id
}
});
if(isOpen) {
gui.zIndex++;
ElementHelpers::top_to_bottom_window_popup_layout(gui, "Color Picker", CLAY_SIZING_FIT(300), CLAY_SIZING_FIT(0), [&, val, data = data]() {
ElementHelpers::color_picker_items(gui, "c", val, {
.hasAlpha = data.hasAlpha,
@ -25,11 +26,14 @@ template <typename T> void ColorPickerButton<T>::layout(const Clay_ElementId& id
});
}, {
.mouseButton = [&](const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) {
if(!mouseHovering && button.button == InputManager::MouseButton::LEFT && button.down)
if(!mouseHovering && button.button == InputManager::MouseButton::LEFT && button.down) {
isOpen = false;
gui.set_to_layout();
}
return mouseHovering;
}
});
gui.zIndex--;
}
}

View file

@ -37,21 +37,22 @@ float RotateWheel::wheel_end() {
bool RotateWheel::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) {
isHovering = mouseHovering;
isHeld = isHovering && button.button == InputManager::MouseButton::LEFT && button.down;
update_paint_circle_menu_mouse(button.pos, button.button == InputManager::MouseButton::LEFT && button.down);
isRotateBarHeld = isRotateBarHovered && isHeld;
update_paint_circle_menu_mouse(button.pos);
return Element::input_mouse_button_callback(button, mouseHovering);
}
bool RotateWheel::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) {
update_paint_circle_menu_mouse(motion.pos, false);
isHovering = mouseHovering;
update_paint_circle_menu_mouse(motion.pos);
return Element::input_mouse_motion_callback(motion, mouseHovering);
}
void RotateWheel::update_paint_circle_menu_mouse(const Vector2f& p, bool leftClicked) {
void RotateWheel::update_paint_circle_menu_mouse(const Vector2f& p) {
if(boundingBox.has_value()) {
Vector2f vecFromCenter = (p - boundingBox.value().center()).normalized();
float distFromCenter = vec_distance(p, boundingBox.value().center());
isRotateBarHovered = isHovering && distFromCenter > wheel_start() && distFromCenter < wheel_end();
isRotateBarHeld = isRotateBarHovered && isHeld;
if(isRotateBarHeld) {
gui.set_post_callback_func([&, vecFromCenter] {
@ -67,6 +68,7 @@ void RotateWheel::update_paint_circle_menu_mouse(const Vector2f& p, bool leftCli
}
}
}
onChange();
});
}
}
@ -105,9 +107,9 @@ void RotateWheel::draw_rotate_wheel(SkCanvas* canvas, UpdateInputData& io, bool
SkPaint rotateBarHolderFill;
rotateBarHolderFill.setAntiAlias(skiaAA);
if(selection.held)
if(isRotateBarHeld)
rotateBarHolderFill.setColor4f(io.theme->fillColor1);
else if(selection.hovered)
else if(isRotateBarHovered)
rotateBarHolderFill.setColor4f(io.theme->fillColor2);
else
rotateBarHolderFill.setColor4f(io.theme->frontColor2);

View file

@ -10,7 +10,7 @@ class RotateWheel : public Element {
virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) 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;
SelectionHelper selection;
private:
float wheel_start();
float wheel_end();
@ -23,7 +23,7 @@ class RotateWheel : public Element {
bool isRotateBarHovered = false;
std::function<void()> onChange;
void update_paint_circle_menu_mouse(const Vector2f& p, bool leftClicked);
void update_paint_circle_menu_mouse(const Vector2f& p);
};
}

View file

@ -19,6 +19,8 @@ void ScrollArea::layout(const Clay_ElementId& id, const Options& options) {
containerDimensions = {scrollData.scrollContainerDimensions.width, scrollData.scrollContainerDimensions.height};
}
clamp_scroll();
CLAY(localID, {
.layout = {
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)},
@ -103,12 +105,18 @@ bool ScrollArea::input_mouse_motion_callback(const InputManager::MouseMotionCall
return Element::input_mouse_motion_callback(motion, mouseHovering);
}
void ScrollArea::clamp_scroll() {
scrollOffset.x() = std::clamp(scrollOffset.x(), -std::max(0.0f, contentDimensions.x() - containerDimensions.x()), 0.0f);
scrollOffset.y() = std::clamp(scrollOffset.y(), -std::max(0.0f, contentDimensions.y() - containerDimensions.y()), 0.0f);
}
bool ScrollArea::input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel, bool mouseHovering) {
if(mouseHovering) {
if(opts.scrollVertical)
scrollOffset.y() += wheel.amount.y();
scrollOffset.y() = scrollOffset.y() + wheel.amount.y() * 10.0f;
if(opts.scrollHorizontal)
scrollOffset.x() += wheel.amount.x();
scrollOffset.y() = scrollOffset.x() + wheel.amount.x() * 10.0f;
clamp_scroll();
gui.set_to_layout();
}
return Element::input_mouse_wheel_callback(wheel, mouseHovering);

View file

@ -37,6 +37,7 @@ class ScrollArea : public Element {
Vector2f contentDimensions = {0.0f, 0.0f};
Vector2f containerDimensions = {0.0f, 0.0f};
Vector2f scrollOffset = {0.0f, 0.0f};
void clamp_scroll();
};
}