feat: added logic for dice adding and removing from active set
This commit is contained in:
parent
62ec32d9b7
commit
a8c79ebac5
|
@ -1,38 +1,126 @@
|
||||||
#include "dice_container.h"
|
#include "dice_container.h"
|
||||||
|
#include <SDL3/SDL_mouse.h>
|
||||||
#include <clay/clay.h>
|
#include <clay/clay.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include "style.h"
|
#include "style.h"
|
||||||
|
#include "dice.h"
|
||||||
|
|
||||||
|
static
|
||||||
|
void HandleAddDieButtonInteraction(Clay_ElementId element, Clay_PointerData pointer, intptr_t die) {
|
||||||
|
if (pointer.state == CLAY_POINTER_DATA_PRESSED_THIS_FRAME) {
|
||||||
|
add_die_to_active((enum die_type)die);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline
|
||||||
|
void AddDieButton(enum die_type die) {
|
||||||
|
CLAY(CLAY_IDI("AddDieButton", die), {
|
||||||
|
.layout = {
|
||||||
|
.sizing = { CLAY_SIZING_FIXED(100), CLAY_SIZING_FIXED(100) },
|
||||||
|
.childAlignment = { CLAY_ALIGN_X_CENTER, CLAY_ALIGN_Y_CENTER },
|
||||||
|
},
|
||||||
|
.backgroundColor = DieButtonColor(die, Clay_Hovered()),
|
||||||
|
}) {
|
||||||
|
Clay_OnHover(&HandleAddDieButtonInteraction, die);
|
||||||
|
CLAY_TEXT(die_to_str(die), CLAY_TEXT_CONFIG({
|
||||||
|
.textColor = TextColors(0),
|
||||||
|
.H(2),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static inline
|
static inline
|
||||||
void DiceSelectorContainer() {
|
void DiceSelectorContainer() {
|
||||||
CLAY(CLAY_ID("DiceSelector"), {
|
CLAY(CLAY_ID("DiceSelector"), {
|
||||||
|
.CONTAINER(0),
|
||||||
|
.layout = {
|
||||||
|
.sizing = { CLAY_SIZING_FIT(), CLAY_SIZING_GROW() },
|
||||||
|
.childAlignment = { CLAY_ALIGN_X_CENTER, CLAY_ALIGN_Y_CENTER },
|
||||||
|
},
|
||||||
|
}) {
|
||||||
|
CLAY(CLAY_ID("DiceSelectorInner"), {
|
||||||
.layout = {
|
.layout = {
|
||||||
.layoutDirection = CLAY_TOP_TO_BOTTOM,
|
.layoutDirection = CLAY_TOP_TO_BOTTOM,
|
||||||
.sizing = { CLAY_SIZING_PERCENT(0.15), CLAY_SIZING_GROW(0) },
|
|
||||||
.padding = containerPadding,
|
|
||||||
.childGap = paragraphGap,
|
.childGap = paragraphGap,
|
||||||
|
.childAlignment = { CLAY_ALIGN_X_CENTER, CLAY_ALIGN_Y_CENTER },
|
||||||
|
.sizing = { CLAY_SIZING_FIT(), CLAY_SIZING_FIT() },
|
||||||
|
.padding = containerPadding,
|
||||||
},
|
},
|
||||||
.INNER_CONTAINER(0),
|
.clip = {
|
||||||
}) { }
|
false, true, Clay_GetScrollOffset(),
|
||||||
|
},
|
||||||
|
}) {
|
||||||
|
AddDieButton(COIN);
|
||||||
|
AddDieButton(D4);
|
||||||
|
AddDieButton(D6);
|
||||||
|
AddDieButton(D8);
|
||||||
|
AddDieButton(D10);
|
||||||
|
AddDieButton(D12);
|
||||||
|
AddDieButton(D20);
|
||||||
|
AddDieButton(D100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void HandleRemoveDieButtonInteraction(Clay_ElementId element, Clay_PointerData pointer, intptr_t index) {
|
||||||
|
if (pointer.state == CLAY_POINTER_DATA_PRESSED_THIS_FRAME) {
|
||||||
|
remove_die_from_active(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline
|
||||||
|
void RemoveDieButton(enum die_type die, int index) {
|
||||||
|
CLAY(CLAY_IDI("RemoveDieButton", index), {
|
||||||
|
.layout = {
|
||||||
|
.sizing = { CLAY_SIZING_FIXED(200), CLAY_SIZING_FIXED(200) },
|
||||||
|
.childAlignment = { CLAY_ALIGN_X_CENTER, CLAY_ALIGN_Y_CENTER },
|
||||||
|
},
|
||||||
|
.backgroundColor = DieButtonColor(die, Clay_Hovered()),
|
||||||
|
}) {
|
||||||
|
Clay_OnHover(&HandleRemoveDieButtonInteraction, index);
|
||||||
|
CLAY_TEXT(die_to_str(die), CLAY_TEXT_CONFIG({
|
||||||
|
.H(1),
|
||||||
|
.textColor = TextColors(0)
|
||||||
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline
|
static inline
|
||||||
void ActiveDiceContainer() {
|
void ActiveDiceContainer() {
|
||||||
CLAY(CLAY_ID("ActiveDice"), {
|
CLAY(CLAY_ID("ActiveDice"), {
|
||||||
.layout = {
|
.layout = {
|
||||||
.layoutDirection = CLAY_TOP_TO_BOTTOM,
|
.sizing = { CLAY_SIZING_GROW(), CLAY_SIZING_GROW() },
|
||||||
.sizing = { CLAY_SIZING_GROW(0), CLAY_SIZING_GROW(0) },
|
|
||||||
.padding = containerPadding,
|
|
||||||
.childGap = paragraphGap,
|
|
||||||
},
|
},
|
||||||
.INNER_CONTAINER(0),
|
.clip = {
|
||||||
}) { }
|
true, true,
|
||||||
|
{ Clay_GetScrollOffset().x, 0 },
|
||||||
|
},
|
||||||
|
.CONTAINER(0),
|
||||||
|
}) {
|
||||||
|
CLAY(CLAY_ID("ActiveDiceInner"), {
|
||||||
|
.layout = {
|
||||||
|
.sizing = { CLAY_SIZING_GROW(), CLAY_SIZING_GROW() },
|
||||||
|
.layoutDirection = CLAY_LEFT_TO_RIGHT,
|
||||||
|
.childAlignment = { CLAY_ALIGN_X_CENTER, CLAY_ALIGN_Y_CENTER },
|
||||||
|
.childGap = 16,
|
||||||
|
.padding = { 100, 100, 0, 0 },
|
||||||
|
},
|
||||||
|
}) {
|
||||||
|
size_t dice_count = 0;
|
||||||
|
enum die_type const *dice = get_active_dice_set(&dice_count);
|
||||||
|
for (size_t i = 0; i < dice_count; ++i) {
|
||||||
|
RemoveDieButton(dice[i], i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiceContainer() {
|
void DiceContainer() {
|
||||||
CLAY(CLAY_ID("DiceContainer"), {
|
CLAY(CLAY_ID("DiceContainer"), {
|
||||||
.layout = {
|
.layout = {
|
||||||
.layoutDirection = CLAY_LEFT_TO_RIGHT,
|
.layoutDirection = CLAY_LEFT_TO_RIGHT,
|
||||||
.sizing = { CLAY_SIZING_GROW(0), CLAY_SIZING_PERCENT(0.4) },
|
.sizing = { CLAY_SIZING_GROW(), CLAY_SIZING_PERCENT(0.4) },
|
||||||
.childGap = containerGap
|
.childGap = containerGap
|
||||||
},
|
},
|
||||||
}) {
|
}) {
|
||||||
|
|
Loading…
Reference in a new issue