feat: defined Toggle element
This commit is contained in:
parent
6f94b64a1f
commit
847c0bded5
|
|
@ -10,15 +10,60 @@ void TextButton(Clay_String text, Clay_Color color, OnHoveredFn onHovered, intpt
|
|||
.padding = style::buttonPadding,
|
||||
.childAlignment = { CLAY_ALIGN_X_CENTER, CLAY_ALIGN_Y_CENTER },
|
||||
},
|
||||
.backgroundColor = Clay_Hovered() ? hovered : color,
|
||||
.backgroundColor = Clay_Hovered()
|
||||
? hovered
|
||||
: color,
|
||||
.cornerRadius = style::buttonRadii,
|
||||
.border = { style::ToHoveredColor(Clay_Hovered() ? hovered : color), CLAY_BORDER_ALL(1) },
|
||||
}) {
|
||||
Clay_OnHover(onHovered, onHoveredData);
|
||||
elements::Body(text, {
|
||||
.textColor = style::TextColors(0),
|
||||
.textAlignment = CLAY_TEXT_ALIGN_CENTER,
|
||||
});
|
||||
Clay_OnHover(onHovered, onHoveredData);
|
||||
}
|
||||
}
|
||||
|
||||
void ToggleHovered(Clay_ElementId element, Clay_PointerData pointer, intptr_t data) {
|
||||
bool *hovered{ (bool*)data };
|
||||
if (pointer.state == CLAY_POINTER_DATA_PRESSED_THIS_FRAME) {
|
||||
*hovered = !(*hovered);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Toggle(Clay_String label, Clay_Color selected, bool &state) {
|
||||
CLAY_AUTO_ID({
|
||||
.layout = {
|
||||
.sizing = { CLAY_SIZING_GROW(), CLAY_SIZING_GROW() },
|
||||
.childGap = 10,
|
||||
.childAlignment = { CLAY_ALIGN_X_LEFT, CLAY_ALIGN_Y_CENTER },
|
||||
},
|
||||
}) {
|
||||
Clay_Color color{Clay_Hovered()
|
||||
? style::ToHoveredColor(selected)
|
||||
: selected
|
||||
};
|
||||
Clay_OnHover(&ToggleHovered, (intptr_t)(&state));
|
||||
CLAY_AUTO_ID({
|
||||
.layout = {
|
||||
.sizing = {
|
||||
CLAY_SIZING_FIXED(20), CLAY_SIZING_FIXED(20)
|
||||
}
|
||||
},
|
||||
.backgroundColor = (state
|
||||
? selected
|
||||
: style::color::transparent
|
||||
),
|
||||
.cornerRadius = style::buttonRadii,
|
||||
.border = {
|
||||
color,
|
||||
CLAY_BORDER_OUTSIDE(3)
|
||||
},
|
||||
}) { }
|
||||
Body(label, {
|
||||
.textColor = style::TextColors(0)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,9 @@ namespace elements {
|
|||
typedef void(*OnHoveredFn)(Clay_ElementId element, Clay_PointerData pointer, intptr_t data);
|
||||
|
||||
void TextButton(Clay_String text, Clay_Color color, OnHoveredFn onHovered, intptr_t onHoveredData = 0);
|
||||
void Body(Clay_String string, Clay_TextElementConfig baseCfg);
|
||||
void Header(Clay_String string, size_t header, Clay_TextElementConfig baseCfg);
|
||||
void Toggle(Clay_String label, Clay_Color selected, bool &state);
|
||||
void Body(Clay_String string, Clay_TextElementConfig baseCfg = {});
|
||||
void Header(Clay_String string, size_t header, Clay_TextElementConfig baseCfg = {});
|
||||
}
|
||||
|
||||
#endif // !ELEMENTS_H
|
||||
|
|
|
|||
|
|
@ -97,6 +97,12 @@ constexpr Clay_CornerRadius defaultRadiusAll = {
|
|||
defaultRadius, defaultRadius
|
||||
};
|
||||
|
||||
namespace color {
|
||||
constexpr Clay_Color transparent{ 255, 255, 255, 0 };
|
||||
constexpr Clay_Color black{ 0, 0, 0, 255 };
|
||||
constexpr Clay_Color white{ 255, 255, 255, 255 };
|
||||
}
|
||||
|
||||
Clay_Color PanelBackground(size_t idx);
|
||||
Clay_Color PanelBorder(size_t idx);
|
||||
Clay_Color TextColors(size_t idx);
|
||||
|
|
|
|||
Loading…
Reference in a new issue