infinipaint/src/GUIStuff/Elements/SelectableButton.cpp

62 lines
2.5 KiB
C++
Raw Normal View History

2025-07-06 20:43:53 +03:00
#include "SelectableButton.hpp"
#include "Helpers/ConvertVec.hpp"
namespace GUIStuff {
void SelectableButton::update(UpdateInputData& io, DrawType drawType, const std::function<void(SelectionHelper&, bool)>& elemUpdate, bool isSelected) {
SkColor4f borderColor;
SkColor4f backgroundColorHighlight;
SkColor4f backgroundColor;
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};
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};
2025-11-18 21:39:14 +03:00
if(drawType == DrawType::TRANSPARENT_ALL || 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_AUTO_ID({.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),
2025-11-04 10:58:26 +03:00
.width = CLAY_BORDER_OUTSIDE(2)
}
}) {
CLAY_AUTO_ID({.layout = {
2025-07-06 20:43:53 +03:00
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)},
.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 },
},
.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, io.mouse.pos);
2025-07-06 20:43:53 +03:00
elemUpdate(selection, isSelected);
}
}
}
void SelectableButton::clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) {
2025-07-06 20:43:53 +03:00
}
}