2025-07-06 20:43:53 +03:00
|
|
|
#include "RadioButton.hpp"
|
2026-03-27 09:51:53 +03:00
|
|
|
#include "../GUIManager.hpp"
|
2025-07-06 20:43:53 +03:00
|
|
|
|
|
|
|
|
namespace GUIStuff {
|
|
|
|
|
|
2026-03-27 09:51:53 +03:00
|
|
|
RadioButton::RadioButton(GUIManager& gui):
|
|
|
|
|
Element(gui) {}
|
|
|
|
|
|
|
|
|
|
void RadioButton::layout(const std::function<bool()>& isTicked, const std::function<void()>& onClick) {
|
|
|
|
|
this->onClick = onClick;
|
|
|
|
|
this->isTicked = isTicked;
|
|
|
|
|
|
2025-12-02 16:09:30 +03:00
|
|
|
CLAY_AUTO_ID({
|
2025-07-06 20:43:53 +03:00
|
|
|
.layout = {
|
|
|
|
|
.sizing = {.width = CLAY_SIZING_FIXED(20), .height = CLAY_SIZING_FIXED(20)}
|
|
|
|
|
},
|
|
|
|
|
.custom = { .customData = this }
|
2026-03-27 09:51:53 +03:00
|
|
|
}) {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RadioButton::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) {
|
|
|
|
|
isHovering = mouseHovering;
|
|
|
|
|
if(isHovering && button.button == InputManager::MouseButton::LEFT && button.down)
|
|
|
|
|
gui.set_post_callback_func([&] { if(onClick) onClick(); });
|
|
|
|
|
return Element::input_mouse_button_callback(button, mouseHovering);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RadioButton::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) {
|
|
|
|
|
isHovering = mouseHovering;
|
|
|
|
|
return Element::input_mouse_motion_callback(motion, mouseHovering);
|
2025-07-06 20:43:53 +03:00
|
|
|
}
|
|
|
|
|
|
2026-03-20 20:53:59 +03:00
|
|
|
void RadioButton::clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) {
|
2026-03-27 09:51:53 +03:00
|
|
|
auto& bb = boundingBox.value();
|
2025-07-06 20:43:53 +03:00
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
|
canvas->translate(bb.min.x(), bb.min.y());
|
|
|
|
|
canvas->scale(bb.width(), bb.height());
|
|
|
|
|
canvas->translate(0.5f, 0.5f);
|
|
|
|
|
|
2026-03-27 09:51:53 +03:00
|
|
|
if(isTicked()) {
|
2025-07-06 20:43:53 +03:00
|
|
|
SkPaint p;
|
2026-03-20 20:53:59 +03:00
|
|
|
p.setAntiAlias(skiaAA);
|
2025-07-06 20:43:53 +03:00
|
|
|
p.setColor4f(convert_vec4<SkColor4f>(io.theme->fillColor1));
|
|
|
|
|
p.setStyle(SkPaint::kFill_Style);
|
|
|
|
|
canvas->drawCircle(0.0f, 0.0f, 0.5f, p);
|
|
|
|
|
|
|
|
|
|
SkPaint innerCircleP;
|
2026-03-20 20:53:59 +03:00
|
|
|
innerCircleP.setAntiAlias(skiaAA);
|
2025-07-06 20:43:53 +03:00
|
|
|
innerCircleP.setColor4f(convert_vec4<SkColor4f>(io.theme->backColor2));
|
|
|
|
|
innerCircleP.setStyle(SkPaint::kFill_Style);
|
|
|
|
|
|
|
|
|
|
static BezierEasing easeRadius(0.68, -2.55, 0.265, 3.55);
|
2026-03-27 09:51:53 +03:00
|
|
|
float lerpTime2 = easeRadius(smooth_two_way_time(hoverAnimation2, io.deltaTime, isHovering, RADIOBUTTON_ANIMATION_TIME));
|
2025-07-06 20:43:53 +03:00
|
|
|
float innerCircleRadius = lerp_vec(0.3f, 0.2f, lerpTime2);
|
|
|
|
|
|
|
|
|
|
canvas->drawCircle(0.0f, 0.0f, innerCircleRadius, innerCircleP);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
SkPaint p;
|
2026-03-20 20:53:59 +03:00
|
|
|
p.setAntiAlias(skiaAA);
|
2026-03-27 09:51:53 +03:00
|
|
|
p.setColor4f(convert_vec4<SkColor4f>(isHovering ? io.theme->fillColor1 : io.theme->backColor2));
|
2025-07-06 20:43:53 +03:00
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
|
p.setStrokeWidth(0.15f);
|
|
|
|
|
canvas->drawCircle(0.0f, 0.0f, 0.5f, p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
canvas->restore();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|