clean up button creation + center text
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package game
|
||||
|
||||
import rl "vendor:raylib"
|
||||
|
||||
draw_text_centered_in_rect :: proc(
|
||||
text: cstring,
|
||||
rect: rl.Rectangle,
|
||||
font_size: i32,
|
||||
color: rl.Color,
|
||||
) {
|
||||
text_w := rl.MeasureText(text, font_size)
|
||||
x := i32(rect.x) + (i32(rect.width) - text_w) / 2
|
||||
y := i32(rect.y) + (i32(rect.height) - font_size) / 2
|
||||
rl.DrawText(text, x, y, font_size, color)
|
||||
}
|
||||
|
||||
draw_button :: proc(
|
||||
rect: rl.Rectangle,
|
||||
label: cstring,
|
||||
bg: rl.Color,
|
||||
font_size: i32,
|
||||
text_color: rl.Color,
|
||||
) {
|
||||
rl.DrawRectangleRec(rect, bg)
|
||||
draw_text_centered_in_rect(label, rect, font_size, text_color)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user