feat: added return value to Toggle

This commit is contained in:
Sara Gerretsen 2025-10-27 21:41:19 +01:00
parent 5e16b201c4
commit d54d5add5e
2 changed files with 8 additions and 4 deletions

View file

@ -35,7 +35,8 @@ void ToggleHovered(Clay_ElementId element, Clay_PointerData pointer, intptr_t da
}
void Toggle(Clay_String label, Clay_Color selected, bool &state) {
bool Toggle(Clay_String label, Clay_Color selected, bool &state) {
bool const before{state};
CLAY_AUTO_ID({
.layout = {
.sizing = { CLAY_SIZING_GROW(), CLAY_SIZING_GROW() },
@ -68,10 +69,12 @@ void Toggle(Clay_String label, Clay_Color selected, bool &state) {
.textColor = theme->textColor
});
}
// return if the value changed this frame
return before != state;
}
void Body(Clay_String string, Clay_TextElementConfig baseCfg) {
baseCfg.fontId = cera::FONT_DEFAULT;
baseCfg.fontId = cera::FONT_REGULAR;
baseCfg.fontSize = cera::baseFontSize;
CLAY_TEXT(string, CLAY_TEXT_CONFIG(baseCfg));
}

View file

@ -1,13 +1,14 @@
#ifndef ELEMENTS_H
#define ELEMENTS_H
#include <clay/clay.h>
#include "style.h"
#include <SDL3/SDL_render.h>
#include <clay/clay.h>
namespace cera {
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 Toggle(Clay_String label, Clay_Color selected, bool &state);
bool Toggle(Clay_String label, Clay_Color selected, bool &state);
void Body(Clay_String string, Clay_TextElementConfig baseCfg = {.textColor = theme->textColor});
void Header(Clay_String string, size_t header, Clay_TextElementConfig baseCfg = {.textColor = theme->textColor});
}