mirror of
https://github.com/nicbarker/clay.git
synced 2025-04-20 13:18:03 +00:00
54 lines
2.0 KiB
C
54 lines
2.0 KiB
C
|
// Must be defined in one file, _before_ #include "clay.h"
|
||
|
#define CLAY_IMPLEMENTATION
|
||
|
|
||
|
#include <unistd.h>
|
||
|
#include "../../clay.h"
|
||
|
#include "../../renderers/terminal/clay_renderer_terminal.c"
|
||
|
|
||
|
const Clay_Color COLOR_LIGHT = (Clay_Color) {224, 215, 210, 255};
|
||
|
const Clay_Color COLOR_RED = (Clay_Color) {168, 66, 28, 255};
|
||
|
const Clay_Color COLOR_ORANGE = (Clay_Color) {225, 138, 50, 255};
|
||
|
|
||
|
// An example function to begin the "root" of your layout tree
|
||
|
Clay_RenderCommandArray CreateLayout() {
|
||
|
Clay_BeginLayout();
|
||
|
|
||
|
CLAY(CLAY_ID("OuterContainer"),
|
||
|
CLAY_LAYOUT({.layoutDirection = CLAY_LEFT_TO_RIGHT, .sizing = {CLAY_SIZING_GROW(), CLAY_SIZING_GROW()}, }),
|
||
|
CLAY_RECTANGLE({ .color = {0,0,0,255} })) {
|
||
|
CLAY(CLAY_ID("SideBar"),
|
||
|
CLAY_LAYOUT({.layoutDirection = CLAY_TOP_TO_BOTTOM, .sizing = {.width = CLAY_SIZING_PERCENT(
|
||
|
0.5), .height = CLAY_SIZING_PERCENT(1)}}),
|
||
|
CLAY_RECTANGLE({.color = (Clay_Color) {255, 255, 255, 255}})
|
||
|
) {
|
||
|
}
|
||
|
CLAY(CLAY_ID("OtherSideBar"),
|
||
|
CLAY_LAYOUT({.layoutDirection = CLAY_TOP_TO_BOTTOM, .sizing = {.width = CLAY_SIZING_PERCENT(
|
||
|
0.5), .height = CLAY_SIZING_PERCENT(1)}}),
|
||
|
CLAY_RECTANGLE({ .color = {0,0, 0, 255 }})
|
||
|
) {
|
||
|
// TODO font size is wrong, only one is allowed, but I don't know which it is
|
||
|
CLAY_TEXT(CLAY_STRING("0123456789 0123456 78901 234567 89012 34567 8901234567890 123456789"),
|
||
|
CLAY_TEXT_CONFIG({ .fontId = 0, .fontSize = 24, .textColor = {255,255,255,255} }));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return Clay_EndLayout();
|
||
|
}
|
||
|
|
||
|
int main() {
|
||
|
uint64_t totalMemorySize = Clay_MinMemorySize();
|
||
|
Clay_Arena arena = Clay_CreateArenaWithCapacityAndMemory(totalMemorySize, malloc(totalMemorySize));
|
||
|
Clay_Initialize(arena, (Clay_Dimensions) { .width = 80, .height = 24 }); // TODO this is wrong, but I have no idea what the actual size of the terminal is in pixels
|
||
|
// Tell clay how to measure text
|
||
|
Clay_SetMeasureTextFunction(Console_MeasureText);
|
||
|
|
||
|
while(true) {
|
||
|
Clay_RenderCommandArray layout = CreateLayout();
|
||
|
|
||
|
Clay_Console_Render(layout);
|
||
|
|
||
|
fflush(stdout);
|
||
|
sleep(1);
|
||
|
}
|
||
|
}
|