Compare commits

...

11 Commits

Author SHA1 Message Date
Joram Vandemoortele
97dee308a7
Merge af3d63ad0f into 982ade4cf9 2025-03-18 17:31:58 +02:00
Nic Barker
982ade4cf9 [Compilers] Add a dummy function to suppress unused variable warning in GCC
Some checks failed
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Has been cancelled
2025-03-18 11:21:23 +13:00
Nic Barker
d5af2c3dc0
[Renderers/SDL2] Added explicit include of math.h in SDL2 renderer 2025-03-18 11:13:46 +13:00
Nic Barker
2677bec854 [Housekeeping] Revert previous commit to allow proper PR attribution 2025-03-18 11:12:21 +13:00
Nic Barker
05ac2810d8 [Renderers/SDL2] Added explicit include of math.h in SDL2 renderer 2025-03-18 11:10:53 +13:00
Nic Barker
1f8cab8d72 [Core] Fix a bug where floating elements could be clipped incorrectly 2025-03-18 11:05:06 +13:00
Emerald-Ruby
6186596b41
math.h include missing cause lots of warning logs 2025-03-15 21:51:36 +00:00
Orcolom
af3d63ad0f added dll_export macro 2025-02-26 21:13:36 +01:00
Orcolom
0eb162e3a3 Merge branch 'main' into feature/get-pointer
# Conflicts:
#	clay.h
2025-02-26 21:12:35 +01:00
Orcolom
d1fd147b09 added getpointerstate to readme 2025-02-19 22:01:25 +01:00
Orcolom
13b588d8c1 added a pointer get method 2025-02-19 21:54:08 +01:00
3 changed files with 28 additions and 0 deletions

View File

@ -169,6 +169,7 @@ For help starting out or to discuss clay, considering joining [the discord serve
- [Clay_SetCurrentContext](#clay_setcurrentcontext)
- [Clay_SetLayoutDimensions](#clay_setlayoutdimensions)
- [Clay_SetPointerState](#clay_setpointerstate)
- [Clay_GetPointerState](#clay_getpointerstate)
- [Clay_UpdateScrollContainers](#clay_updatescrollcontainers)
- [Clay_BeginLayout](#clay_beginlayout)
- [Clay_EndLayout](#clay_endlayout)
@ -646,6 +647,14 @@ Sets the internal pointer position and state (i.e. current mouse / touch positio
---
### Clay_GetPointerState
`Clay_PointerData Clay_GetPointerState()`
Get the internal pointer position and state (i.e. current mouse / touch position). returns clay internal click start and stop state.
---
### Clay_UpdateScrollContainers
`void Clay_UpdateScrollContainers(bool enableDragScrolling, Clay_Vector2 scrollDelta, float deltaTime)`

18
clay.h
View File

@ -102,6 +102,10 @@
static uint8_t CLAY__ELEMENT_DEFINITION_LATCH;
// GCC marks the above CLAY__ELEMENT_DEFINITION_LATCH as an unused variable for files that include clay.h but don't declare any layout
// This is to suppress that warning
static inline void Clay__SuppressUnusedLatchDefinitionVariableWarning(void) { (void) CLAY__ELEMENT_DEFINITION_LATCH; }
// Publicly visible layout element macros -----------------------------------------------------
/* This macro looks scary on the surface, but is actually quite simple.
@ -798,6 +802,9 @@ 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);
// Gets the state of the "pointer". This will return the position provided by `Clay_SetPointerState`
// and the frame pressed state.
CLAY_DLL_EXPORT Clay_PointerData Clay_GetPointerState();
// 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)
@ -1654,6 +1661,8 @@ void Clay__CloseElement(void) {
elementHasScrollVertical = config->config.scrollElementConfig->vertical;
context->openClipElementStack.length--;
break;
} else if (config->type == CLAY__ELEMENT_CONFIG_TYPE_FLOATING) {
context->openClipElementStack.length--;
}
}
@ -1933,6 +1942,9 @@ void Clay__ConfigureOpenElementPtr(const Clay_ElementDeclaration *declaration) {
if (!openLayoutElementId.id) {
openLayoutElementId = Clay__HashString(CLAY_STRING("Clay__FloatingContainer"), context->layoutElementTreeRoots.length, 0);
}
int32_t currentElementIndex = Clay__int32_tArray_GetValue(&context->openLayoutElementStack, context->openLayoutElementStack.length - 1);
Clay__int32_tArray_Set(&context->layoutElementClipElementIds, currentElementIndex, clipElementId);
Clay__int32_tArray_Add(&context->openClipElementStack, clipElementId);
Clay__LayoutElementTreeRootArray_Add(&context->layoutElementTreeRoots, CLAY__INIT(Clay__LayoutElementTreeRoot) {
.layoutElementIndex = Clay__int32_tArray_GetValue(&context->openLayoutElementStack, context->openLayoutElementStack.length - 1),
.parentId = floatingConfig.parentId,
@ -3739,6 +3751,12 @@ void Clay_SetPointerState(Clay_Vector2 position, bool isPointerDown) {
}
}
CLAY_WASM_EXPORT("Clay_GetPointerState")
Clay_PointerData Clay_GetPointerState() {
Clay_Context* context = Clay_GetCurrentContext();
return context->pointerInfo;
}
CLAY_WASM_EXPORT("Clay_Initialize")
Clay_Context* Clay_Initialize(Clay_Arena arena, Clay_Dimensions layoutDimensions, Clay_ErrorHandler errorHandler) {
Clay_Context *context = Clay__Context_Allocate_Arena(&arena);

View File

@ -3,6 +3,7 @@
#include <SDL_ttf.h>
#include <SDL_image.h>
#include <stdio.h>
#include <math.h>
#ifndef M_PI
#define M_PI 3.14159