Compare commits

...

3 Commits

Author SHA1 Message Date
caleb-snow-cbm
f1a37176e3
Merge 94a3d57236 into 61490e4557 2025-03-20 22:27:48 +02:00
Leo Zurbriggen
61490e4557
[Bindings/Odin] expose _OpenElement and _CloseElement (#301)
Some checks are pending
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Waiting to run
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Waiting to run
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Waiting to run
2025-03-21 09:25:50 +13:00
Caleb Snow
94a3d57236 [Core] Add right click support
Adds the Clay_SetPointerStateEx function to optionally capture
right click info.
2025-03-04 08:48:18 -05:00
2 changed files with 27 additions and 5 deletions

View File

@ -367,6 +367,8 @@ Context :: struct {} // opaque structure, only use as a pointer
@(link_prefix = "Clay_", default_calling_convention = "c")
foreign Clay {
_OpenElement :: proc() ---
_CloseElement :: proc() ---
MinMemorySize :: proc() -> u32 ---
CreateArenaWithCapacityAndMemory :: proc(capacity: c.size_t, offset: [^]u8) -> Arena ---
SetPointerState :: proc(position: Vector2, pointerDown: bool) ---
@ -399,9 +401,7 @@ foreign Clay {
@(link_prefix = "Clay_", default_calling_convention = "c", private)
foreign Clay {
_OpenElement :: proc() ---
_ConfigureOpenElement :: proc(config: ElementDeclaration) ---
_CloseElement :: proc() ---
_HashString :: proc(key: String, offset: u32, seed: u32) -> ElementId ---
_OpenTextElement :: proc(text: String, textConfig: ^TextElementConfig) ---
_StoreTextElementConfig :: proc(config: TextElementConfig) -> ^TextElementConfig ---

28
clay.h
View File

@ -709,7 +709,8 @@ typedef struct {
// CLAY_POINTER_DATA_PRESSED - The left mouse button click or touch happened at some point in the past, and is still currently held down this frame.
// CLAY_POINTER_DATA_RELEASED_THIS_FRAME - The left mouse button click or touch was released this frame.
// CLAY_POINTER_DATA_RELEASED - The left mouse button click or touch is not currently down / was released at some point in the past.
Clay_PointerDataInteractionState state;
Clay_PointerDataInteractionState state : 4;
Clay_PointerDataInteractionState right_state : 4;
} Clay_PointerData;
typedef struct {
@ -802,6 +803,8 @@ CLAY_DLL_EXPORT Clay_Arena Clay_CreateArenaWithCapacityAndMemory(size_t capacity
// Sets the state of the "pointer" (i.e. the mouse or touch) in Clay's internal data. Used for detecting and responding to mouse events in the debug view,
// as well as for Clay_Hovered() and scroll element handling.
CLAY_DLL_EXPORT void Clay_SetPointerState(Clay_Vector2 position, bool pointerDown);
// Same as `Clay_SetPointerState` but includes right click info
CLAY_DLL_EXPORT void Clay_SetPointerStateEx(Clay_Vector2 position, bool pointerDown, bool rightPointerDown);
// Initialize Clay's internal arena and setup required data before layout can begin. Only needs to be called once.
// - arena can be created using Clay_CreateArenaWithCapacityAndMemory()
// - layoutDimensions are the initial bounding dimensions of the layout (i.e. the screen width and height for a full screen layout)
@ -3673,8 +3676,8 @@ void Clay_SetLayoutDimensions(Clay_Dimensions dimensions) {
Clay_GetCurrentContext()->layoutDimensions = dimensions;
}
CLAY_WASM_EXPORT("Clay_SetPointerState")
void Clay_SetPointerState(Clay_Vector2 position, bool isPointerDown) {
CLAY_WASM_EXPORT("Clay_SetPointerStateEx")
void Clay_SetPointerStateEx(Clay_Vector2 position, bool isPointerDown, bool isRightPointerDown) {
Clay_Context* context = Clay_GetCurrentContext();
if (context->booleanWarnings.maxElementsExceeded) {
return;
@ -3746,6 +3749,25 @@ void Clay_SetPointerState(Clay_Vector2 position, bool isPointerDown) {
context->pointerInfo.state = CLAY_POINTER_DATA_RELEASED_THIS_FRAME;
}
}
if (isRightPointerDown) {
if (context->pointerInfo.right_state == CLAY_POINTER_DATA_PRESSED_THIS_FRAME) {
context->pointerInfo.right_state = CLAY_POINTER_DATA_PRESSED;
} else if (context->pointerInfo.right_state != CLAY_POINTER_DATA_PRESSED) {
context->pointerInfo.right_state = CLAY_POINTER_DATA_PRESSED_THIS_FRAME;
}
} else {
if (context->pointerInfo.right_state == CLAY_POINTER_DATA_RELEASED_THIS_FRAME) {
context->pointerInfo.right_state = CLAY_POINTER_DATA_RELEASED;
} else if (context->pointerInfo.right_state != CLAY_POINTER_DATA_RELEASED) {
context->pointerInfo.right_state = CLAY_POINTER_DATA_RELEASED_THIS_FRAME;
}
}
}
CLAY_WASM_EXPORT("Clay_SetPointerState")
void Clay_SetPointerState(Clay_Vector2 position, bool isPointerDown)
{
Clay_SetPointerStateEx(position, isPointerDown, false);
}
CLAY_WASM_EXPORT("Clay_Initialize")