Prepping to add ui
This commit is contained in:
parent
a2a70a0f33
commit
af82f9c2d4
6 changed files with 120 additions and 589 deletions
38
utils.odin
38
utils.odin
|
|
@ -17,6 +17,44 @@ write_entire_file :: proc(name: string, data: []byte, truncate := true) -> (succ
|
|||
return _write_entire_file(name, data, truncate)
|
||||
}
|
||||
|
||||
/// ### RAYLIB SHORTHANDS ### ///
|
||||
measure_text :: proc(text: cstring, style: FontStyle) -> v2 {
|
||||
return rl.MeasureTextEx(style.font, text, style.size, style.spacing)
|
||||
}
|
||||
|
||||
draw_text :: proc(text: cstring, position: v2, style: FontStyle, color: rl.Color) {
|
||||
rl.DrawTextEx(style.font, text, position, style.size, style.spacing, color)
|
||||
}
|
||||
|
||||
TextHalign :: enum {
|
||||
Left,
|
||||
Middle,
|
||||
Right,
|
||||
}
|
||||
|
||||
TextValign :: enum {
|
||||
Top,
|
||||
Center,
|
||||
Bottom,
|
||||
}
|
||||
|
||||
draw_text_aligned :: proc(text: cstring, position: v2, style: FontStyle, halign: TextHalign, valign: TextValign, color: rl.Color) {
|
||||
size := measure_text(text, style)
|
||||
position := position
|
||||
switch halign {
|
||||
case .Left:
|
||||
case .Middle: position.x -= size.x / 2.0
|
||||
case .Right: position.x -= size.x
|
||||
}
|
||||
switch valign {
|
||||
case .Top:
|
||||
case .Center: position.y -= size.y / 2.0
|
||||
case .Bottom: position.y -= size.y
|
||||
}
|
||||
draw_text(text, position, style, color)
|
||||
}
|
||||
|
||||
/// ### TYPES ### ///
|
||||
v1 :: [1]f32
|
||||
v2 :: [2]f32
|
||||
v3 :: [3]f32
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue