70 lines
1.6 KiB
Odin
70 lines
1.6 KiB
Odin
package game
|
|
|
|
import clay "../clay-odin"
|
|
import "core:math"
|
|
import "core:strings"
|
|
import rl "vendor:raylib"
|
|
|
|
UI_FONT_ID :: 0
|
|
|
|
ui_font: rl.Font
|
|
|
|
ui_register_font :: proc() {
|
|
ui_font = rl.GetFontDefault()
|
|
}
|
|
|
|
clay_color_to_rl :: proc(c: clay.Color) -> rl.Color {
|
|
return {u8(c.r), u8(c.g), u8(c.b), u8(c.a)}
|
|
}
|
|
|
|
measure_text :: proc "c" (
|
|
text: clay.StringSlice,
|
|
config: ^clay.TextElementConfig,
|
|
_: rawptr,
|
|
) -> clay.Dimensions {
|
|
return {width = f32(text.length) * f32(config.fontSize) * 0.55, height = f32(config.fontSize)}
|
|
}
|
|
|
|
clay_raylib_render :: proc(commands: ^clay.ClayArray(clay.RenderCommand)) {
|
|
for i in 0 ..< commands.length {
|
|
cmd := clay.RenderCommandArray_Get(commands, i)
|
|
bounds := cmd.boundingBox
|
|
|
|
#partial switch cmd.commandType {
|
|
case .None:
|
|
case .Text:
|
|
cfg := cmd.renderData.text
|
|
text := string(cfg.stringContents.chars[:cfg.stringContents.length])
|
|
cstr := strings.clone_to_cstring(text, context.temp_allocator)
|
|
|
|
rl.DrawTextEx(
|
|
ui_font,
|
|
cstr,
|
|
{bounds.x, bounds.y},
|
|
f32(cfg.fontSize),
|
|
f32(cfg.letterSpacing),
|
|
clay_color_to_rl(cfg.textColor),
|
|
)
|
|
case .Rectangle:
|
|
cfg := cmd.renderData.rectangle
|
|
rl.DrawRectangle(
|
|
i32(math.round(bounds.x)),
|
|
i32(math.round(bounds.y)),
|
|
i32(math.round(bounds.width)),
|
|
i32(math.round(bounds.height)),
|
|
clay_color_to_rl(cfg.backgroundColor),
|
|
)
|
|
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()
|
|
}
|
|
}
|
|
}
|
|
|