2025-07-06 20:43:53 +03:00
|
|
|
#include "SelectableButton.hpp"
|
|
|
|
|
#include "Helpers/ConvertVec.hpp"
|
|
|
|
|
|
|
|
|
|
namespace GUIStuff {
|
|
|
|
|
|
2025-11-01 16:07:19 +03:00
|
|
|
void SelectableButton::update(UpdateInputData& io, DrawType drawType, const std::function<void(SelectionHelper&, bool)>& elemUpdate, bool isSelected) {
|
2025-11-02 09:38:15 +03:00
|
|
|
SkColor4f borderColor;
|
2025-11-01 16:07:19 +03:00
|
|
|
SkColor4f backgroundColorHighlight;
|
|
|
|
|
SkColor4f backgroundColor;
|
|
|
|
|
|
2025-11-02 09:38:15 +03:00
|
|
|
if(selection.held || ((isSelected || selection.hovered) && drawType == DrawType::TRANSPARENT_BORDER))
|
|
|
|
|
borderColor = io.theme->fillColor1;
|
|
|
|
|
else if(drawType == DrawType::TRANSPARENT_BORDER)
|
|
|
|
|
borderColor = io.theme->backColor2;
|
|
|
|
|
else
|
|
|
|
|
borderColor = SkColor4f{0.0f, 0.0f, 0.0f, 0.0f};
|
|
|
|
|
|
2025-11-01 16:07:19 +03:00
|
|
|
if(isSelected)
|
|
|
|
|
backgroundColorHighlight = color_mul_alpha(io.theme->fillColor1, 0.4f);
|
|
|
|
|
else if(selection.hovered || selection.held)
|
|
|
|
|
backgroundColorHighlight = color_mul_alpha(io.theme->fillColor1, 0.2f);
|
|
|
|
|
else
|
|
|
|
|
backgroundColorHighlight = {0.0f, 0.0f, 0.0f, 0.0f};
|
|
|
|
|
|
|
|
|
|
if(drawType == DrawType::TRANSPARENT || drawType == DrawType::TRANSPARENT_BORDER)
|
|
|
|
|
backgroundColor = {0.0f, 0.0f, 0.0f, 0.0f};
|
|
|
|
|
else if(drawType == DrawType::FILLED)
|
|
|
|
|
backgroundColor = io.theme->backColor2;
|
|
|
|
|
else
|
|
|
|
|
backgroundColor = io.theme->fillColor2;
|
|
|
|
|
|
|
|
|
|
CLAY({.layout = {
|
|
|
|
|
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)},
|
|
|
|
|
.childGap = 0,
|
|
|
|
|
.childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER }
|
|
|
|
|
},
|
|
|
|
|
.backgroundColor = convert_vec4<Clay_Color>(backgroundColor),
|
|
|
|
|
.cornerRadius = CLAY_CORNER_RADIUS(4),
|
|
|
|
|
.border = {
|
|
|
|
|
.color = convert_vec4<Clay_Color>(borderColor),
|
|
|
|
|
.width = CLAY_BORDER_OUTSIDE(1)
|
|
|
|
|
}
|
|
|
|
|
}) {
|
2025-07-06 20:43:53 +03:00
|
|
|
CLAY({.layout = {
|
|
|
|
|
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)},
|
2025-11-01 16:07:19 +03:00
|
|
|
.padding = (drawType == DrawType::TRANSPARENT_BORDER) ? CLAY_PADDING_ALL(0) : CLAY_PADDING_ALL(4),
|
2025-07-06 20:43:53 +03:00
|
|
|
.childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER },
|
|
|
|
|
},
|
2025-11-01 16:07:19 +03:00
|
|
|
.backgroundColor = convert_vec4<Clay_Color>(backgroundColorHighlight),
|
|
|
|
|
.cornerRadius = CLAY_CORNER_RADIUS(4)
|
2025-07-06 20:43:53 +03:00
|
|
|
}) {
|
|
|
|
|
selection.update(Clay_Hovered(), io.mouse.leftClick, io.mouse.leftHeld);
|
|
|
|
|
elemUpdate(selection, isSelected);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SelectableButton::clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|