mirror of
https://github.com/nicbarker/clay.git
synced 2025-05-14 14:28:06 +00:00
Compare commits
5 Commits
c73dffbb6f
...
ee99e5f0f2
Author | SHA1 | Date | |
---|---|---|---|
|
ee99e5f0f2 | ||
|
256fc32549 | ||
|
28a8f59733 | ||
|
47c8e9178e | ||
|
a62ee15758 |
37
README.md
37
README.md
@ -722,6 +722,15 @@ 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_ElementId Clay_GetElementId(Clay_String idString)`
|
||||
@ -1240,7 +1249,7 @@ Used to perform **aspect ratio scaling** on the image element. As of this versio
|
||||
|
||||
```C
|
||||
// Load an image somewhere in your code
|
||||
Image profilePicture = LoadImage("profilePicture.png");
|
||||
YourImage profilePicture = LoadYourImage("profilePicture.png");
|
||||
// Note that when rendering, .imageData will be void* type.
|
||||
CLAY({ .image = { .imageData = &profilePicture, .sourceDimensions = { 60, 60 } } }) {}
|
||||
```
|
||||
@ -1249,7 +1258,7 @@ CLAY({ .image = { .imageData = &profilePicture, .sourceDimensions = { 60, 60 } }
|
||||
|
||||
```C
|
||||
// Load an image somewhere in your code
|
||||
Image profilePicture = LoadImage("profilePicture.png");
|
||||
YourImage profilePicture = LoadYourImage("profilePicture.png");
|
||||
// Declare a reusable image config
|
||||
Clay_ImageElementConfig imageConfig = (Clay_ImageElementConfig) { .imageData = &profilePicture, .sourceDimensions = {60, 60} };
|
||||
// Declare an image element using a reusable config
|
||||
@ -1257,7 +1266,7 @@ CLAY({ .image = imageConfig }) {}
|
||||
// Declare an image element using an inline config
|
||||
CLAY({ .image = { .imageData = &profilePicture, .sourceDimensions = {60, 60} } }) {}
|
||||
// Rendering example
|
||||
Image *imageToRender = renderCommand->elementConfig.imageElementConfig->imageData;
|
||||
YourImage *imageToRender = renderCommand->elementConfig.imageElementConfig->imageData;
|
||||
```
|
||||
|
||||
**Rendering**
|
||||
@ -1967,16 +1976,34 @@ typedef union {
|
||||
### Clay_ScrollContainerData
|
||||
|
||||
```C
|
||||
typedef struct
|
||||
{
|
||||
// Data representing the current internal state of a scrolling element.
|
||||
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;
|
||||
// The bounding box of the scroll element.
|
||||
Clay_Dimensions scrollContainerDimensions;
|
||||
// The outer dimensions of the inner scroll container content, including the padding of the parent scroll container.
|
||||
Clay_Dimensions contentDimensions;
|
||||
// The config that was originally passed to the scroll element.
|
||||
Clay_ScrollElementConfig config;
|
||||
// Indicates whether an actual scroll container matched the provided ID or if the default struct was returned.
|
||||
bool found;
|
||||
} 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**
|
||||
|
||||
**`.scrollPosition`** - `Clay_Vector2 *`
|
||||
|
@ -509,12 +509,12 @@ main :: proc() {
|
||||
loadFont(FONT_ID_BODY_24, 24, "resources/Quicksand-Semibold.ttf")
|
||||
loadFont(FONT_ID_BODY_16, 16, "resources/Quicksand-Semibold.ttf")
|
||||
|
||||
syntaxImage = raylib.LoadTextureFromImage(raylib.LoadImage("resources/declarative.png"))
|
||||
checkImage1 = raylib.LoadTextureFromImage(raylib.LoadImage("resources/check_1.png"))
|
||||
checkImage2 = raylib.LoadTextureFromImage(raylib.LoadImage("resources/check_2.png"))
|
||||
checkImage3 = raylib.LoadTextureFromImage(raylib.LoadImage("resources/check_3.png"))
|
||||
checkImage4 = raylib.LoadTextureFromImage(raylib.LoadImage("resources/check_4.png"))
|
||||
checkImage5 = raylib.LoadTextureFromImage(raylib.LoadImage("resources/check_5.png"))
|
||||
syntaxImage = raylib.LoadTexture("resources/declarative.png")
|
||||
checkImage1 = raylib.LoadTexture("resources/check_1.png")
|
||||
checkImage2 = raylib.LoadTexture("resources/check_2.png")
|
||||
checkImage3 = raylib.LoadTexture("resources/check_3.png")
|
||||
checkImage4 = raylib.LoadTexture("resources/check_4.png")
|
||||
checkImage5 = raylib.LoadTexture("resources/check_5.png")
|
||||
|
||||
debugModeEnabled: bool = false
|
||||
|
||||
|
@ -48,9 +48,15 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
SDL_Window *window = NULL;
|
||||
SDL_Renderer *renderer = NULL;
|
||||
if (SDL_CreateWindowAndRenderer(800, 600, SDL_WINDOW_RESIZABLE, &window, &renderer) < 0) {
|
||||
fprintf(stderr, "Error: could not create window and renderer: %s", SDL_GetError());
|
||||
}
|
||||
|
||||
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"); //for antialiasing
|
||||
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();
|
||||
Clay_Arena clayMemory = Clay_CreateArenaWithCapacityAndMemory(totalMemorySize, malloc(totalMemorySize));
|
||||
|
@ -227,7 +227,7 @@ int main(void) {
|
||||
Clay_Arena clayMemory = Clay_CreateArenaWithCapacityAndMemory(totalMemorySize, malloc(totalMemorySize));
|
||||
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);
|
||||
profilePicture = LoadTextureFromImage(LoadImage("resources/profile-picture.png"));
|
||||
profilePicture = LoadTexture("resources/profile-picture.png");
|
||||
|
||||
Font fonts[2];
|
||||
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.
|
||||
void SDL_RenderCornerBorder(SDL_Renderer *renderer, Clay_BoundingBox* boundingBox, Clay_BorderRenderData* config, int cornerIndex, Clay_Color _color){
|
||||
static 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).
|
||||
//First three vertices are first outer triangle's vertices
|
||||
|
@ -153,6 +153,7 @@ static void SDL_Clay_RenderClayCommands(Clay_SDL3RendererData *rendererData, Cla
|
||||
switch (rcmd->commandType) {
|
||||
case CLAY_RENDER_COMMAND_TYPE_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);
|
||||
if (config->cornerRadius.topLeft > 0) {
|
||||
SDL_Clay_RenderFillRoundedRect(rendererData, rect, config->cornerRadius.topLeft, config->backgroundColor);
|
||||
|
Loading…
Reference in New Issue
Block a user