mirror of
https://github.com/nicbarker/clay.git
synced 2025-05-15 23:08:02 +00:00
Compare commits
1 Commits
9964da1838
...
b985950de1
Author | SHA1 | Date | |
---|---|---|---|
|
b985950de1 |
37
README.md
37
README.md
@ -724,15 +724,6 @@ Returns [Clay_ScrollContainerData](#clay_scrollcontainerdata) for the scroll con
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### Clay_GetElementData
|
|
||||||
|
|
||||||
`Clay_ElementData Clay_GetElementData(Clay_ElementId id)`
|
|
||||||
|
|
||||||
Returns [Clay_ElementData](#clay_elementdata) for the element matching the provided ID.
|
|
||||||
Used to retrieve information about elements such as their final calculated bounding box.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### Clay_GetElementId
|
### Clay_GetElementId
|
||||||
|
|
||||||
`Clay_ElementId Clay_GetElementId(Clay_String idString)`
|
`Clay_ElementId Clay_GetElementId(Clay_String idString)`
|
||||||
@ -1261,7 +1252,7 @@ Used to perform **aspect ratio scaling** on the image element. As of this versio
|
|||||||
|
|
||||||
```C
|
```C
|
||||||
// Load an image somewhere in your code
|
// Load an image somewhere in your code
|
||||||
YourImage profilePicture = LoadYourImage("profilePicture.png");
|
Image profilePicture = LoadImage("profilePicture.png");
|
||||||
// Note that when rendering, .imageData will be void* type.
|
// Note that when rendering, .imageData will be void* type.
|
||||||
CLAY({ .image = { .imageData = &profilePicture, .sourceDimensions = { 60, 60 } } }) {}
|
CLAY({ .image = { .imageData = &profilePicture, .sourceDimensions = { 60, 60 } } }) {}
|
||||||
```
|
```
|
||||||
@ -1270,7 +1261,7 @@ CLAY({ .image = { .imageData = &profilePicture, .sourceDimensions = { 60, 60 } }
|
|||||||
|
|
||||||
```C
|
```C
|
||||||
// Load an image somewhere in your code
|
// Load an image somewhere in your code
|
||||||
YourImage profilePicture = LoadYourImage("profilePicture.png");
|
Image profilePicture = LoadImage("profilePicture.png");
|
||||||
// Declare a reusable image config
|
// Declare a reusable image config
|
||||||
Clay_ImageElementConfig imageConfig = (Clay_ImageElementConfig) { .imageData = &profilePicture, .sourceDimensions = {60, 60} };
|
Clay_ImageElementConfig imageConfig = (Clay_ImageElementConfig) { .imageData = &profilePicture, .sourceDimensions = {60, 60} };
|
||||||
// Declare an image element using a reusable config
|
// Declare an image element using a reusable config
|
||||||
@ -1278,7 +1269,7 @@ CLAY({ .image = imageConfig }) {}
|
|||||||
// Declare an image element using an inline config
|
// Declare an image element using an inline config
|
||||||
CLAY({ .image = { .imageData = &profilePicture, .sourceDimensions = {60, 60} } }) {}
|
CLAY({ .image = { .imageData = &profilePicture, .sourceDimensions = {60, 60} } }) {}
|
||||||
// Rendering example
|
// Rendering example
|
||||||
YourImage *imageToRender = renderCommand->elementConfig.imageElementConfig->imageData;
|
Image *imageToRender = renderCommand->elementConfig.imageElementConfig->imageData;
|
||||||
```
|
```
|
||||||
|
|
||||||
**Rendering**
|
**Rendering**
|
||||||
@ -1988,34 +1979,16 @@ typedef union {
|
|||||||
### Clay_ScrollContainerData
|
### Clay_ScrollContainerData
|
||||||
|
|
||||||
```C
|
```C
|
||||||
// Data representing the current internal state of a scrolling element.
|
typedef struct
|
||||||
typedef struct {
|
{
|
||||||
// Note: This is a pointer to the real internal scroll position, mutating it may cause a change in final layout.
|
|
||||||
// Intended for use with external functionality that modifies scroll position, such as scroll bars or auto scrolling.
|
|
||||||
Clay_Vector2 *scrollPosition;
|
Clay_Vector2 *scrollPosition;
|
||||||
// The bounding box of the scroll element.
|
|
||||||
Clay_Dimensions scrollContainerDimensions;
|
Clay_Dimensions scrollContainerDimensions;
|
||||||
// The outer dimensions of the inner scroll container content, including the padding of the parent scroll container.
|
|
||||||
Clay_Dimensions contentDimensions;
|
Clay_Dimensions contentDimensions;
|
||||||
// The config that was originally passed to the scroll element.
|
|
||||||
Clay_ScrollElementConfig config;
|
Clay_ScrollElementConfig config;
|
||||||
// Indicates whether an actual scroll container matched the provided ID or if the default struct was returned.
|
|
||||||
bool found;
|
bool found;
|
||||||
} Clay_ScrollContainerData;
|
} Clay_ScrollContainerData;
|
||||||
```
|
```
|
||||||
|
|
||||||
### Clay_ElementData
|
|
||||||
|
|
||||||
```C
|
|
||||||
// Bounding box and other data for a specific UI element.
|
|
||||||
typedef struct {
|
|
||||||
// The rectangle that encloses this UI element, with the position relative to the root of the layout.
|
|
||||||
Clay_BoundingBox boundingBox;
|
|
||||||
// Indicates whether an actual Element matched the provided ID or if the default struct was returned.
|
|
||||||
bool found;
|
|
||||||
} Clay_ElementData;
|
|
||||||
```
|
|
||||||
|
|
||||||
**Fields**
|
**Fields**
|
||||||
|
|
||||||
**`.scrollPosition`** - `Clay_Vector2 *`
|
**`.scrollPosition`** - `Clay_Vector2 *`
|
||||||
|
@ -509,12 +509,12 @@ main :: proc() {
|
|||||||
loadFont(FONT_ID_BODY_24, 24, "resources/Quicksand-Semibold.ttf")
|
loadFont(FONT_ID_BODY_24, 24, "resources/Quicksand-Semibold.ttf")
|
||||||
loadFont(FONT_ID_BODY_16, 16, "resources/Quicksand-Semibold.ttf")
|
loadFont(FONT_ID_BODY_16, 16, "resources/Quicksand-Semibold.ttf")
|
||||||
|
|
||||||
syntaxImage = raylib.LoadTexture("resources/declarative.png")
|
syntaxImage = raylib.LoadTextureFromImage(raylib.LoadImage("resources/declarative.png"))
|
||||||
checkImage1 = raylib.LoadTexture("resources/check_1.png")
|
checkImage1 = raylib.LoadTextureFromImage(raylib.LoadImage("resources/check_1.png"))
|
||||||
checkImage2 = raylib.LoadTexture("resources/check_2.png")
|
checkImage2 = raylib.LoadTextureFromImage(raylib.LoadImage("resources/check_2.png"))
|
||||||
checkImage3 = raylib.LoadTexture("resources/check_3.png")
|
checkImage3 = raylib.LoadTextureFromImage(raylib.LoadImage("resources/check_3.png"))
|
||||||
checkImage4 = raylib.LoadTexture("resources/check_4.png")
|
checkImage4 = raylib.LoadTextureFromImage(raylib.LoadImage("resources/check_4.png"))
|
||||||
checkImage5 = raylib.LoadTexture("resources/check_5.png")
|
checkImage5 = raylib.LoadTextureFromImage(raylib.LoadImage("resources/check_5.png"))
|
||||||
|
|
||||||
debugModeEnabled: bool = false
|
debugModeEnabled: bool = false
|
||||||
|
|
||||||
|
@ -48,15 +48,9 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
SDL_Window *window = NULL;
|
SDL_Window *window = NULL;
|
||||||
SDL_Renderer *renderer = NULL;
|
SDL_Renderer *renderer = NULL;
|
||||||
|
if (SDL_CreateWindowAndRenderer(800, 600, SDL_WINDOW_RESIZABLE, &window, &renderer) < 0) {
|
||||||
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"); //for antialiasing
|
fprintf(stderr, "Error: could not create window and renderer: %s", SDL_GetError());
|
||||||
window = SDL_CreateWindow("SDL", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
|
}
|
||||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4); //for antialiasing
|
|
||||||
|
|
||||||
bool enableVsync = false;
|
|
||||||
if(enableVsync){ renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);} //"SDL_RENDERER_ACCELERATED" is for antialiasing
|
|
||||||
else{renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);}
|
|
||||||
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); //for alpha blending
|
|
||||||
|
|
||||||
uint64_t totalMemorySize = Clay_MinMemorySize();
|
uint64_t totalMemorySize = Clay_MinMemorySize();
|
||||||
Clay_Arena clayMemory = Clay_CreateArenaWithCapacityAndMemory(totalMemorySize, malloc(totalMemorySize));
|
Clay_Arena clayMemory = Clay_CreateArenaWithCapacityAndMemory(totalMemorySize, malloc(totalMemorySize));
|
||||||
|
@ -227,7 +227,7 @@ int main(void) {
|
|||||||
Clay_Arena clayMemory = Clay_CreateArenaWithCapacityAndMemory(totalMemorySize, malloc(totalMemorySize));
|
Clay_Arena clayMemory = Clay_CreateArenaWithCapacityAndMemory(totalMemorySize, malloc(totalMemorySize));
|
||||||
Clay_Initialize(clayMemory, (Clay_Dimensions) { (float)GetScreenWidth(), (float)GetScreenHeight() }, (Clay_ErrorHandler) { HandleClayErrors, 0 });
|
Clay_Initialize(clayMemory, (Clay_Dimensions) { (float)GetScreenWidth(), (float)GetScreenHeight() }, (Clay_ErrorHandler) { HandleClayErrors, 0 });
|
||||||
Clay_Raylib_Initialize(1024, 768, "Clay - Raylib Renderer Example", FLAG_VSYNC_HINT | FLAG_WINDOW_RESIZABLE | FLAG_WINDOW_HIGHDPI | FLAG_MSAA_4X_HINT);
|
Clay_Raylib_Initialize(1024, 768, "Clay - Raylib Renderer Example", FLAG_VSYNC_HINT | FLAG_WINDOW_RESIZABLE | FLAG_WINDOW_HIGHDPI | FLAG_MSAA_4X_HINT);
|
||||||
profilePicture = LoadTexture("resources/profile-picture.png");
|
profilePicture = LoadTextureFromImage(LoadImage("resources/profile-picture.png"));
|
||||||
|
|
||||||
Font fonts[2];
|
Font fonts[2];
|
||||||
fonts[FONT_ID_BODY_24] = LoadFontEx("resources/Roboto-Regular.ttf", 48, 0, 400);
|
fonts[FONT_ID_BODY_24] = LoadFontEx("resources/Roboto-Regular.ttf", 48, 0, 400);
|
||||||
|
@ -146,7 +146,7 @@ static void SDL_RenderFillRoundedRect(SDL_Renderer* renderer, const SDL_FRect re
|
|||||||
}
|
}
|
||||||
|
|
||||||
//all rendering is performed by a single SDL call, using twi sets of arcing triangles, inner and outer, that fit together; along with two tringles to fill the end gaps.
|
//all rendering is performed by a single SDL call, using twi sets of arcing triangles, inner and outer, that fit together; along with two tringles to fill the end gaps.
|
||||||
static void SDL_RenderCornerBorder(SDL_Renderer *renderer, Clay_BoundingBox* boundingBox, Clay_BorderRenderData* config, int cornerIndex, Clay_Color _color){
|
void SDL_RenderCornerBorder(SDL_Renderer *renderer, Clay_BoundingBox* boundingBox, Clay_BorderRenderData* config, int cornerIndex, Clay_Color _color){
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
//The arc is constructed of outer triangles and inner triangles (if needed).
|
//The arc is constructed of outer triangles and inner triangles (if needed).
|
||||||
//First three vertices are first outer triangle's vertices
|
//First three vertices are first outer triangle's vertices
|
||||||
|
@ -153,7 +153,6 @@ static void SDL_Clay_RenderClayCommands(Clay_SDL3RendererData *rendererData, Cla
|
|||||||
switch (rcmd->commandType) {
|
switch (rcmd->commandType) {
|
||||||
case CLAY_RENDER_COMMAND_TYPE_RECTANGLE: {
|
case CLAY_RENDER_COMMAND_TYPE_RECTANGLE: {
|
||||||
Clay_RectangleRenderData *config = &rcmd->renderData.rectangle;
|
Clay_RectangleRenderData *config = &rcmd->renderData.rectangle;
|
||||||
SDL_SetRenderDrawBlendMode(rendererData->renderer, SDL_BLENDMODE_BLEND);
|
|
||||||
SDL_SetRenderDrawColor(rendererData->renderer, config->backgroundColor.r, config->backgroundColor.g, config->backgroundColor.b, config->backgroundColor.a);
|
SDL_SetRenderDrawColor(rendererData->renderer, config->backgroundColor.r, config->backgroundColor.g, config->backgroundColor.b, config->backgroundColor.a);
|
||||||
if (config->cornerRadius.topLeft > 0) {
|
if (config->cornerRadius.topLeft > 0) {
|
||||||
SDL_Clay_RenderFillRoundedRect(rendererData, rect, config->cornerRadius.topLeft, config->backgroundColor);
|
SDL_Clay_RenderFillRoundedRect(rendererData, rect, config->cornerRadius.topLeft, config->backgroundColor);
|
||||||
|
Loading…
Reference in New Issue
Block a user