mirror of
https://github.com/nicbarker/clay.git
synced 2026-02-06 12:48:49 +00:00
[Renderers/Terminal] Add initial implementation of terminal renderer (#91)
This commit is contained in:
parent
7af50d0f48
commit
65e813d4df
4 changed files with 249 additions and 0 deletions
15
examples/terminal-example/CMakeLists.txt
Normal file
15
examples/terminal-example/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
cmake_minimum_required(VERSION 3.27)
|
||||
project(clay_examples_terminal C)
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
|
||||
add_executable(clay_examples_terminal main.c)
|
||||
|
||||
target_compile_options(clay_examples_terminal PUBLIC)
|
||||
target_include_directories(clay_examples_terminal PUBLIC .)
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL Linux)
|
||||
target_link_libraries(clay_examples_terminal INTERFACE m)
|
||||
endif()
|
||||
|
||||
target_link_libraries(clay_examples_terminal PUBLIC ${CURSES_LIBRARY})
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -Werror -DCLAY_DEBUG")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
|
||||
39
examples/terminal-example/main.c
Normal file
39
examples/terminal-example/main.c
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
// 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_ansi.c"
|
||||
#include "../shared-layouts/clay-video-demo.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};
|
||||
|
||||
void HandleClayErrors(Clay_ErrorData errorData) {
|
||||
printf("%s", errorData.errorText.chars);
|
||||
}
|
||||
|
||||
int main() {
|
||||
const int width = 145;
|
||||
const int height = 41;
|
||||
int columnWidth = 16;
|
||||
|
||||
uint64_t totalMemorySize = Clay_MinMemorySize();
|
||||
Clay_Arena arena = Clay_CreateArenaWithCapacityAndMemory(totalMemorySize, malloc(totalMemorySize));
|
||||
Clay_Initialize(arena,
|
||||
(Clay_Dimensions) {.width = (float) width * columnWidth, .height = (float) height * columnWidth},
|
||||
(Clay_ErrorHandler) {HandleClayErrors});
|
||||
// Tell clay how to measure text
|
||||
Clay_SetMeasureTextFunction(Console_MeasureText, &columnWidth);
|
||||
ClayVideoDemo_Data demoData = ClayVideoDemo_Initialize();
|
||||
|
||||
while (true) {
|
||||
Clay_RenderCommandArray renderCommands = ClayVideoDemo_CreateLayout(&demoData);
|
||||
|
||||
Clay_Terminal_Render(renderCommands, width, height, columnWidth);
|
||||
|
||||
fflush(stdout);
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue