Use local IDs instead of global unique IDs in clay

This commit is contained in:
Yousef Khadadeh 2025-12-02 16:09:30 +03:00
parent cf3c8fe956
commit c405a2acc0
17 changed files with 366 additions and 326 deletions

View file

@ -6,7 +6,7 @@
namespace GUIStuff {
void CheckBox::update(UpdateInputData& io, bool newIsTicked, const std::function<void()>& elemUpdate) {
CLAY({
CLAY_AUTO_ID({
.layout = {
.sizing = {.width = CLAY_SIZING_FIXED(15), .height = CLAY_SIZING_FIXED(15)}
},

View file

@ -22,7 +22,7 @@ template <typename T> class ColorPicker : public Element {
force_update_colorpicker(data);
CLAY({
CLAY_AUTO_ID({
.layout = {
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0) }
},

View file

@ -46,7 +46,7 @@ bool GUIStuff::FontPicker::update(UpdateInputData& io, std::string* fontName, GU
const float ENTRY_HEIGHT = 25.0f;
CLAY({
CLAY_AUTO_ID({
.layout = {
.sizing = {.width = CLAY_SIZING_FIXED(250), .height = CLAY_SIZING_FIT(0)},
.childGap = 4
@ -78,7 +78,7 @@ bool GUIStuff::FontPicker::update(UpdateInputData& io, std::string* fontName, GU
clickedOut = false;
}
if(dropdownOpen) {
CLAY({
CLAY_AUTO_ID({
.layout = {
.sizing = {.width = CLAY_SIZING_FIXED(250), .height = CLAY_SIZING_FIT(0, 300)},
.layoutDirection = CLAY_TOP_TO_BOTTOM
@ -129,7 +129,7 @@ bool GUIStuff::FontPicker::update(UpdateInputData& io, std::string* fontName, GU
auto p = pBuilder.Build();
CLAY({
CLAY_AUTO_ID({
.layout = {
.sizing = {.width = CLAY_SIZING_FIXED(250), .height = CLAY_SIZING_FIXED(25)},
.childGap = 1,
@ -144,7 +144,7 @@ bool GUIStuff::FontPicker::update(UpdateInputData& io, std::string* fontName, GU
entryColor = io.theme->backColor2;
else
entryColor = io.theme->backColor1;
CLAY({
CLAY_AUTO_ID({
.layout = {
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(25)},
.padding = {.left = 2, .right = 2},
@ -165,7 +165,7 @@ bool GUIStuff::FontPicker::update(UpdateInputData& io, std::string* fontName, GU
scrollAmount = -static_cast<float>(val) * ENTRY_HEIGHT;
});
#ifdef __EMSCRIPTEN__
CLAY({
CLAY_AUTO_ID({
.layout = {
.padding = CLAY_PADDING_ALL(io.theme->padding1)
}}) {

View file

@ -15,7 +15,7 @@ void MovableTabList::update(UpdateInputData& io, const std::vector<std::pair<std
oldTabNames = tabNames;
}
CLAY({.layout = {
CLAY_AUTO_ID({.layout = {
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(GUIStuff::GUIManager::BIG_BUTTON_SIZE)},
.padding = CLAY_PADDING_ALL(0),
.childGap = 4,
@ -28,12 +28,12 @@ void MovableTabList::update(UpdateInputData& io, const std::vector<std::pair<std
if(elemUpdate)
elemUpdate();
for(size_t i = 0; i < buttons.size(); i++) {
CLAY({.layout = {
CLAY_AUTO_ID({.layout = {
.sizing = {.width = CLAY_SIZING_FIT(200), .height = CLAY_SIZING_GROW(0)},
}
}) {
buttons[i].update(io, SelectableButton::DrawType::FILLED, [&](SelectionHelper& s, bool iS) {
CLAY({.layout = {
CLAY_AUTO_ID({.layout = {
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)},
.padding = CLAY_PADDING_ALL(0),
.childGap = 4,
@ -42,7 +42,7 @@ void MovableTabList::update(UpdateInputData& io, const std::vector<std::pair<std
}
}) {
if(!tabNames[i].first.empty()) {
CLAY({.layout = {
CLAY_AUTO_ID({.layout = {
.sizing = {.width = CLAY_SIZING_FIXED(GUIStuff::GUIManager::SMALL_BUTTON_SIZE), .height = CLAY_SIZING_FIXED(GUIStuff::GUIManager::SMALL_BUTTON_SIZE)},
.childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER },
.layoutDirection = CLAY_LEFT_TO_RIGHT
@ -54,8 +54,8 @@ void MovableTabList::update(UpdateInputData& io, const std::vector<std::pair<std
CLAY_TEXT(io.strArena->std_str_to_clay_str(tabNames[i].second), CLAY_TEXT_CONFIG({.textColor = convert_vec4<Clay_Color>(io.theme->frontColor1), .fontSize = io.fontSize }));
if(s.clicked)
selectedTab = i;
CLAY({.layout = {.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}}}) {}
CLAY({.layout = {
CLAY_AUTO_ID({.layout = {.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}}}) {}
CLAY_AUTO_ID({.layout = {
.sizing = {.width = CLAY_SIZING_FIXED(GUIStuff::GUIManager::SMALL_BUTTON_SIZE), .height = CLAY_SIZING_FIXED(GUIStuff::GUIManager::SMALL_BUTTON_SIZE)},
.childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER },
.layoutDirection = CLAY_LEFT_TO_RIGHT

View file

@ -11,7 +11,7 @@ template <typename T> class NumberSlider : public Element {
min = minNew;
max = maxNew;
CLAY({
CLAY_AUTO_ID({
.layout = {
.sizing = {.width = CLAY_SIZING_GROW(100), .height = CLAY_SIZING_FIXED(10)}
},

View file

@ -11,7 +11,7 @@ constexpr double ROTATE_BAR_SNAP_DISTANCE = 0.2;
constexpr double ROTATE_BAR_SNAP_DISTRIBUTION = std::numbers::pi * 0.25;
void PaintCircleMenu::update(UpdateInputData& io, const Data& data, const std::function<void()>& elemUpdate) {
CLAY({.layout = {
CLAY_AUTO_ID({.layout = {
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}
},
.custom = { .customData = this }

View file

@ -3,7 +3,7 @@
namespace GUIStuff {
void RadioButton::update(UpdateInputData& io, bool newIsTicked, const std::function<void()>& elemUpdate) {
CLAY({
CLAY_AUTO_ID({
.layout = {
.sizing = {.width = CLAY_SIZING_FIXED(20), .height = CLAY_SIZING_FIXED(20)}
},

View file

@ -13,7 +13,7 @@ void RotateWheel::update(UpdateInputData& io, double* newRotationAnglePtr, const
if(!newRotationAnglePtr)
return;
CLAY({.layout = {
CLAY_AUTO_ID({.layout = {
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}
},
.custom = { .customData = this }

View file

@ -15,7 +15,7 @@ void SVGIcon::update(UpdateInputData& io, const std::string& newSvgPath, bool ne
highlighted = newIsHighlighted;
CLAY({
CLAY_AUTO_ID({
.layout = {
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0) }
},

View file

@ -29,7 +29,7 @@ void SelectableButton::update(UpdateInputData& io, DrawType drawType, const std:
else
backgroundColor = io.theme->fillColor2;
CLAY({.layout = {
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 }
@ -41,7 +41,7 @@ void SelectableButton::update(UpdateInputData& io, DrawType drawType, const std:
.width = CLAY_BORDER_OUTSIDE(2)
}
}) {
CLAY({.layout = {
CLAY_AUTO_ID({.layout = {
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)},
.padding = (drawType == DrawType::TRANSPARENT_BORDER) ? CLAY_PADDING_ALL(0) : CLAY_PADDING_ALL(4),
.childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER },

View file

@ -23,7 +23,7 @@ template <typename T> class TextBox : public Element {
textbox->set_width(std::numeric_limits<float>::max());
//textbox->set_text_direction_between(0, 0, textbox->get_suggested_direction(0));
CLAY({
CLAY_AUTO_ID({
.layout = {
.sizing = {.width = CLAY_SIZING_GROW(static_cast<float>(io.fontSize * 2)), .height = CLAY_SIZING_FIXED(static_cast<float>(io.fontSize * 1.25f))}
},

View file

@ -7,7 +7,7 @@ namespace GUIStuff {
void TextParagraph::update(UpdateInputData& io, std::unique_ptr<skia::textlayout::Paragraph> paragraph, float width, const std::function<void()>& elemUpdate) {
data = std::move(paragraph);
data->layout(width);
CLAY({
CLAY_AUTO_ID({
.layout = {
.sizing = {.width = CLAY_SIZING_FIXED(width), .height = CLAY_SIZING_FIXED(data->getHeight())}
},