24 lines
589 B
Odin
24 lines
589 B
Odin
package gui
|
|
|
|
import "core:fmt"
|
|
import rl "vendor:raylib"
|
|
|
|
fit_text_for_width :: proc(text: string, width_px, px_per_char: int) -> string {
|
|
if px_per_char <= 0 {
|
|
return text
|
|
}
|
|
max_chars := width_px / px_per_char
|
|
if max_chars < 4 {
|
|
max_chars = 4
|
|
}
|
|
if len(text) <= max_chars {
|
|
return text
|
|
}
|
|
return fmt.tprintf("%s…", text[:max_chars-1])
|
|
}
|
|
|
|
draw_text_fitted :: proc(text: string, x, y, font_size: i32, width_px, px_per_char: int, color: rl.Color) {
|
|
display := fit_text_for_width(text, width_px, px_per_char)
|
|
rl.DrawText(fmt.ctprintf("%s", display), x, y, font_size, color)
|
|
}
|