Grid values
This commit is contained in:
parent
bd47c52111
commit
1c2a324f55
3 changed files with 66 additions and 44 deletions
23
utils.odin
23
utils.odin
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue