Grid values

This commit is contained in:
Synthasmagoria 2026-08-23 11:59:32 +02:00
commit 1c2a324f55
3 changed files with 66 additions and 44 deletions

View file

@ -30,16 +30,6 @@ draw_text :: proc(text: cstring, position: v2, style: FontStyle, color: rl.Color
rl.DrawTextEx(style.font, text, position, style.size, style.spacing, color)
}
draw_grid :: proc(area: rect2, line_interval: v2, color: rl.Color) {
br := rect_get_br(area)
for x := area.x; x < br.x; x += line_interval.x {
rl.DrawLineV({x, area.y}, {x, br.y}, color)
}
for y := area.y; y < br.y; y += line_interval.y {
rl.DrawLineV({area.x, y}, {br.x, y}, color)
}
}
TextHalign :: enum {
Left,
Middle,
@ -68,6 +58,19 @@ draw_text_aligned :: proc(text: cstring, position: v2, style: FontStyle, halign:
draw_text(text, position, style, color)
}
draw_float_aligned :: proc(value: f32, position: v2, style: FontStyle, halign: TextHalign, valign: TextValign, color: rl.Color) {
fractional := fract(value)
text: cstring
if fractional == 0.0 {
text = fmt.ctprintf("%.0f", value)
} else if fractional * 10.0 > 1.0 {
text = fmt.ctprintf("%.1f", value)
} else {
text = fmt.ctprintf("%.2f", value)
}
draw_text_aligned(text, position, style, halign, valign, color)
}
/// ### MATH ### ///
fract :: proc(val: f32) -> f32 {
return val - math.trunc(val)