Created
April 10, 2026 05:06
-
-
Save Lajt/0f1311fd0f6426f3e7f44724fe9d66ba to your computer and use it in GitHub Desktop.
example raylib with clay integration using odin in a single file, not fully featured, just to test concept
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import "../vendor/clay" | |
| import "core:math" | |
| import "core:strings" | |
| import rl "vendor:raylib" | |
| WINDOW_WIDTH :: 1360 | |
| WINDOW_HEIGHT :: 768 | |
| COLOR_ORANGE :: clay.Color{225, 138, 50, 255} | |
| text_config := clay.TextElementConfig { | |
| fontId = 0, | |
| fontSize = 32, | |
| textColor = {255, 255, 255, 255}, | |
| } | |
| convert_color :: proc(color: clay.Color) -> rl.Color { | |
| return {u8(color.r), u8(color.g), u8(color.b), u8(color.a)} | |
| } | |
| build_layout :: proc() { | |
| if clay.UI(clay.ID("test"))( | |
| clay.ElementDeclaration { | |
| layout = { | |
| padding = clay.PaddingAll(16), | |
| sizing = {height = clay.SizingFixed(200), width = clay.SizingFixed(200)}, | |
| }, | |
| backgroundColor = COLOR_ORANGE, | |
| }, | |
| ) { | |
| clay.Text("Hellop!", &text_config) | |
| } | |
| } | |
| render_layout :: proc(render_commands: ^clay.ClayArray(clay.RenderCommand)) { | |
| for i in 0 ..< render_commands.length { | |
| command := clay.RenderCommandArray_Get(render_commands, i) | |
| bounds := command.boundingBox | |
| rectangle := command.renderData.rectangle | |
| switch command.commandType { | |
| case .None: | |
| case .ScissorStart: | |
| rl.BeginScissorMode( | |
| i32(math.round(bounds.x)), | |
| i32(math.round(bounds.y)), | |
| i32(math.round(bounds.width)), | |
| i32(math.round(bounds.height)), | |
| ) | |
| case .ScissorEnd: | |
| rl.EndScissorMode() | |
| case .Rectangle: | |
| rl.DrawRectangle( | |
| i32(math.round(bounds.x)), | |
| i32(math.round(bounds.y)), | |
| i32(math.round(bounds.width)), | |
| i32(math.round(bounds.height)), | |
| convert_color(rectangle.backgroundColor), | |
| ) | |
| case .Border: | |
| case .Text: | |
| text_data := command.renderData.text | |
| text := string(text_data.stringContents.chars[:text_data.stringContents.length]) | |
| txt := strings.clone_to_cstring(text) | |
| rl.DrawText(txt, i32(bounds.x), i32(bounds.y), i32(text_data.fontSize), rl.WHITE) | |
| case .Image: | |
| case .Custom: | |
| } | |
| } | |
| } | |
| main :: proc() { | |
| // raylib init | |
| rl.InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "test") | |
| defer rl.CloseWindow() | |
| rl.SetConfigFlags({.WINDOW_RESIZABLE}) | |
| rl.SetTargetFPS(60) | |
| // clay init | |
| min_memory_size := clay.MinMemorySize() | |
| memory := make([^]u8, min_memory_size) | |
| arena: clay.Arena = clay.CreateArenaWithCapacityAndMemory(uint(min_memory_size), memory) | |
| clay.Initialize(arena, {WINDOW_WIDTH, WINDOW_HEIGHT}, {}) | |
| // clay.SetDebugModeEnabled(true) | |
| for !rl.WindowShouldClose() { | |
| clay.BeginLayout() | |
| build_layout() | |
| render_commands := clay.EndLayout() | |
| rl.BeginDrawing() | |
| render_layout(&render_commands) | |
| rl.EndDrawing() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment