mirror of
https://github.com/nicbarker/clay.git
synced 2025-05-14 06:18:04 +00:00
Compare commits
6 Commits
47799a01f2
...
a84d014be8
Author | SHA1 | Date | |
---|---|---|---|
|
a84d014be8 | ||
|
fd76ce62f3 | ||
|
d0d1e01a3f | ||
|
23ee491e37 | ||
|
ccb57787ce | ||
|
25e13b8bdb |
10
clay.h
10
clay.h
@ -3521,13 +3521,19 @@ CLAY_WASM_EXPORT("Clay_EndLayout")
|
||||
Clay_RenderCommandArray Clay_EndLayout(void) {
|
||||
Clay_Context* context = Clay_GetCurrentContext();
|
||||
Clay__CloseElement();
|
||||
if (context->debugModeEnabled) {
|
||||
bool elementsExceededBeforeDebugView = context->booleanWarnings.maxElementsExceeded;
|
||||
if (context->debugModeEnabled && !elementsExceededBeforeDebugView) {
|
||||
context->warningsEnabled = false;
|
||||
Clay__RenderDebugView();
|
||||
context->warningsEnabled = true;
|
||||
}
|
||||
if (context->booleanWarnings.maxElementsExceeded) {
|
||||
Clay_String message = CLAY_STRING("Clay Error: Layout elements exceeded Clay__maxElementCount");
|
||||
Clay_String message;
|
||||
if (!elementsExceededBeforeDebugView) {
|
||||
message = CLAY_STRING("Clay Error: Layout elements exceeded Clay__maxElementCount after adding the debug-view to the layout.");
|
||||
} else {
|
||||
message = CLAY_STRING("Clay Error: Layout elements exceeded Clay__maxElementCount");
|
||||
}
|
||||
Clay__AddRenderCommand(CLAY__INIT(Clay_RenderCommand ) {
|
||||
.boundingBox = { context->layoutDimensions.width / 2 - 59 * 4, context->layoutDimensions.height / 2, 0, 0 },
|
||||
.renderData = { .text = { .stringContents = CLAY__INIT(Clay_StringSlice) { .length = message.length, .chars = message.chars, .baseChars = message.chars }, .textColor = {255, 0, 0, 255}, .fontSize = 16 } },
|
||||
|
@ -34,11 +34,24 @@ message(STATUS "Using SDL_ttf via FetchContent")
|
||||
FetchContent_MakeAvailable(SDL_ttf)
|
||||
set_property(DIRECTORY "${sdl_ttf_SOURCE_DIR}" PROPERTY EXCLUDE_FROM_ALL TRUE)
|
||||
|
||||
# Download SDL_image
|
||||
FetchContent_Declare(
|
||||
SDL_image
|
||||
GIT_REPOSITORY "https://github.com/libsdl-org/SDL_image.git"
|
||||
GIT_TAG main # Slightly risky to use main branch, but it's the only one available
|
||||
GIT_SHALLOW TRUE
|
||||
GIT_PROGRESS TRUE
|
||||
)
|
||||
message(STATUS "Using SDL_image via FetchContent")
|
||||
FetchContent_MakeAvailable(SDL_image)
|
||||
set_property(DIRECTORY "${SDL_image_SOURCE_DIR}" PROPERTY EXCLUDE_FROM_ALL TRUE)
|
||||
|
||||
# Example executable
|
||||
add_executable(${PROJECT_NAME} main.c)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||
SDL3::SDL3
|
||||
SDL3_ttf::SDL3_ttf
|
||||
SDL3_image::SDL3_image
|
||||
)
|
||||
|
||||
add_custom_command(
|
||||
|
@ -23,6 +23,8 @@ typedef struct app_state {
|
||||
ClayVideoDemo_Data demoData;
|
||||
} AppState;
|
||||
|
||||
SDL_Surface *sample_image;
|
||||
|
||||
static inline Clay_Dimensions SDL_MeasureText(Clay_StringSlice text, Clay_TextElementConfig *config, void *userData)
|
||||
{
|
||||
TTF_Font *font = gFonts[config->fontId];
|
||||
@ -68,6 +70,8 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
|
||||
gFonts[FONT_ID] = font;
|
||||
|
||||
sample_image = IMG_Load("resources/sample.png");
|
||||
|
||||
/* Initialize Clay */
|
||||
uint64_t totalMemorySize = Clay_MinMemorySize();
|
||||
Clay_Arena clayMemory = (Clay_Arena) {
|
||||
|
BIN
examples/SDL3-simple-demo/resources/sample.png
Normal file
BIN
examples/SDL3-simple-demo/resources/sample.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 850 B |
@ -1,4 +0,0 @@
|
||||
Please note, the SDL3 renderer is not 100% feature complete. It is currently missing:
|
||||
|
||||
- Images
|
||||
- Scroll / Scissor handling
|
@ -2,6 +2,7 @@
|
||||
#include <SDL3/SDL_main.h>
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3_ttf/SDL_ttf.h>
|
||||
#include <SDL3_image/SDL_image.h>
|
||||
|
||||
/* This needs to be global because the "MeasureText" callback doesn't have a
|
||||
* user data parameter */
|
||||
@ -137,6 +138,8 @@ static void SDL_RenderArc(SDL_Renderer *renderer, const SDL_FPoint center, const
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Rect currentClippingRectangle;
|
||||
|
||||
static void SDL_RenderClayCommands(SDL_Renderer *renderer, Clay_RenderCommandArray *rcommands)
|
||||
{
|
||||
for (size_t i = 0; i < rcommands->length; i++) {
|
||||
@ -232,6 +235,29 @@ static void SDL_RenderClayCommands(SDL_Renderer *renderer, Clay_RenderCommandArr
|
||||
}
|
||||
|
||||
} break;
|
||||
case CLAY_RENDER_COMMAND_TYPE_SCISSOR_START: {
|
||||
Clay_BoundingBox boundingBox = rcmd->boundingBox;
|
||||
currentClippingRectangle = (SDL_Rect) {
|
||||
.x = boundingBox.x,
|
||||
.y = boundingBox.y,
|
||||
.w = boundingBox.width,
|
||||
.h = boundingBox.height,
|
||||
};
|
||||
SDL_SetRenderClipRect(renderer, ¤tClippingRectangle);
|
||||
break;
|
||||
}
|
||||
case CLAY_RENDER_COMMAND_TYPE_SCISSOR_END: {
|
||||
SDL_SetRenderClipRect(renderer, NULL);
|
||||
break;
|
||||
}
|
||||
case CLAY_RENDER_COMMAND_TYPE_IMAGE: {
|
||||
Clay_ImageRenderData *config = &rcmd->renderData.image;
|
||||
const SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, config->imageData);
|
||||
const SDL_FRect dest = { rect.x, rect.y, rect.w, rect.h };
|
||||
|
||||
SDL_RenderTexture(renderer, texture, NULL, &dest);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
SDL_Log("Unknown render command type: %d", rcmd->commandType);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user