2025-07-06 20:43:53 +03:00
|
|
|
#include "RadioButton.hpp"
|
|
|
|
|
|
|
|
|
|
namespace GUIStuff {
|
|
|
|
|
|
|
|
|
|
void RadioButton::update(UpdateInputData& io, bool newIsTicked, const std::function<void()>& elemUpdate) {
|
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-04 13:50:15 +03:00
|
|
|
selection.update(Clay_Hovered(), io.mouse.leftClick, io.mouse.leftHeld, io.mouse.pos);
|
2025-07-06 20:43:53 +03:00
|
|
|
if(isTicked != newIsTicked) {
|
|
|
|
|
hoverAnimation2 = RADIOBUTTON_ANIMATION_TIME;
|
|
|
|
|
isTicked = newIsTicked;
|
|
|
|
|
}
|
|
|
|
|
if(elemUpdate)
|
|
|
|
|
elemUpdate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-20 20:53:59 +03:00
|
|
|
void RadioButton::clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) {
|
2025-07-06 20:43:53 +03:00
|
|
|
auto bb = get_bb(command);
|
|
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
|
canvas->translate(bb.min.x(), bb.min.y());
|
|
|
|
|
canvas->scale(bb.width(), bb.height());
|
|
|
|
|
canvas->translate(0.5f, 0.5f);
|
|
|
|
|
|
|
|
|
|
if(isTicked) {
|
|
|
|
|
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);
|
|
|
|
|
float lerpTime2 = easeRadius(smooth_two_way_time(hoverAnimation2, io.deltaTime, selection.hovered, RADIOBUTTON_ANIMATION_TIME));
|
|
|
|
|
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);
|
2025-11-01 16:07:19 +03:00
|
|
|
p.setColor4f(convert_vec4<SkColor4f>(selection.hovered ? 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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|