package main import clay "../../clay-odin" import "core:math" import "core:strings" import "vendor:raylib" RaylibFont :: struct { fontId: u16, font: raylib.Font, } clayColorToRaylibColor :: proc(color: clay.Color) -> raylib.Color { return raylib.Color{cast(u8)color.r, cast(u8)color.g, cast(u8)color.b, cast(u8)color.a} } raylibFonts := [10]RaylibFont{} measureText :: proc "c" (text: ^clay.String, config: ^clay.TextElementConfig) -> clay.Dimensions { // Measure string size for Font textSize: clay.Dimensions = {0, 0} maxTextWidth: f32 = 0 lineTextWidth: f32 = 0 textHeight := cast(f32)config.fontSize fontToUse := raylibFonts[config.fontId].font for i in 0.. 0) { radius: f32 = (config.cornerRadius.topLeft * 2) / min(boundingBox.width, boundingBox.height) raylib.DrawRectangleRounded( raylib.Rectangle{boundingBox.x, boundingBox.y, boundingBox.width, boundingBox.height}, radius, 8, clayColorToRaylibColor(config.color), ) } else { raylib.DrawRectangle( cast(i32)boundingBox.x, cast(i32)boundingBox.y, cast(i32)boundingBox.width, cast(i32)boundingBox.height, clayColorToRaylibColor(config.color), ) } case clay.RenderCommandType.Border: config := renderCommand.config.borderElementConfig // Left border if (config.left.width > 0) { raylib.DrawRectangle( cast(i32)math.round(boundingBox.x), cast(i32)math.round(boundingBox.y + config.cornerRadius.topLeft), cast(i32)config.left.width, cast(i32)math.round(boundingBox.height - config.cornerRadius.topLeft - config.cornerRadius.bottomLeft), clayColorToRaylibColor(config.left.color), ) } // Right border if (config.right.width > 0) { raylib.DrawRectangle( cast(i32)math.round(boundingBox.x + boundingBox.width - cast(f32)config.right.width), cast(i32)math.round(boundingBox.y + config.cornerRadius.topRight), cast(i32)config.right.width, cast(i32)math.round(boundingBox.height - config.cornerRadius.topRight - config.cornerRadius.bottomRight), clayColorToRaylibColor(config.right.color), ) } // Top border if (config.top.width > 0) { raylib.DrawRectangle( cast(i32)math.round(boundingBox.x + config.cornerRadius.topLeft), cast(i32)math.round(boundingBox.y), cast(i32)math.round(boundingBox.width - config.cornerRadius.topLeft - config.cornerRadius.topRight), cast(i32)config.top.width, clayColorToRaylibColor(config.top.color), ) } // Bottom border if (config.bottom.width > 0) { raylib.DrawRectangle( cast(i32)math.round(boundingBox.x + config.cornerRadius.bottomLeft), cast(i32)math.round(boundingBox.y + boundingBox.height - cast(f32)config.bottom.width), cast(i32)math.round(boundingBox.width - config.cornerRadius.bottomLeft - config.cornerRadius.bottomRight), cast(i32)config.bottom.width, clayColorToRaylibColor(config.bottom.color), ) } if (config.cornerRadius.topLeft > 0) { raylib.DrawRing( raylib.Vector2{math.round(boundingBox.x + config.cornerRadius.topLeft), math.round(boundingBox.y + config.cornerRadius.topLeft)}, math.round(config.cornerRadius.topLeft - cast(f32)config.top.width), config.cornerRadius.topLeft, 180, 270, 10, clayColorToRaylibColor(config.top.color), ) } if (config.cornerRadius.topRight > 0) { raylib.DrawRing( raylib.Vector2{math.round(boundingBox.x + boundingBox.width - config.cornerRadius.topRight), math.round(boundingBox.y + config.cornerRadius.topRight)}, math.round(config.cornerRadius.topRight - cast(f32)config.top.width), config.cornerRadius.topRight, 270, 360, 10, clayColorToRaylibColor(config.top.color), ) } if (config.cornerRadius.bottomLeft > 0) { raylib.DrawRing( raylib.Vector2 { math.round(boundingBox.x + config.cornerRadius.bottomLeft), math.round(boundingBox.y + boundingBox.height - config.cornerRadius.bottomLeft), }, math.round(config.cornerRadius.bottomLeft - cast(f32)config.top.width), config.cornerRadius.bottomLeft, 90, 180, 10, clayColorToRaylibColor(config.bottom.color), ) } if (config.cornerRadius.bottomRight > 0) { raylib.DrawRing( raylib.Vector2 { math.round(boundingBox.x + boundingBox.width - config.cornerRadius.bottomRight), math.round(boundingBox.y + boundingBox.height - config.cornerRadius.bottomRight), }, math.round(config.cornerRadius.bottomRight - cast(f32)config.bottom.width), config.cornerRadius.bottomRight, 0.1, 90, 10, clayColorToRaylibColor(config.bottom.color), ) } case clay.RenderCommandType.Custom: // Implement custom element rendering here } } }