Gui code neatened up for easy components.

Updated the gui init etc to use a layout struct to quickly setup new
rectangles for the gui. Each component can use its rect as its bounding
box for ui elements, each can set its own padding etc per panel
This commit is contained in:
2026-06-03 07:04:04 +02:00
parent cf572179ea
commit e6feabe2f1
5 changed files with 97 additions and 57 deletions
+54 -10
View File
@@ -7,6 +7,18 @@ import rl "vendor:raylib"
WINDOW_WIDTH :: 1920
WINDOW_HEIGHT :: 1080
// TODO: If this grows lets move it into its own file
SIDEBAR_PERCENT :: 0.20
DISPLAY_PERCENT :: 0.30
CONTROLBAR_PERCENT :: 0.05
Layout :: struct {
left_panel : rl.Rectangle,
right_panel : rl.Rectangle,
display : rl.Rectangle,
control_bar : rl.Rectangle,
}
// Initialize main the gui 'window'
init_gui :: proc(s: ^m.System) {
rl.SetConfigFlags({.WINDOW_RESIZABLE})
@@ -20,15 +32,9 @@ init_gui :: proc(s: ^m.System) {
// Pass these down to gui functions so they can setup their sizes?
screen_width := f32(rl.GetScreenWidth())
screen_height := f32(rl.GetScreenHeight())
sidebar_width := screen_width * 0.20
display_rect := rl.Rectangle{
x = sidebar_width,
y = 0,
width = screen_width - (sidebar_width * 2),
height = screen_height * 0.30,
}
layout := calc_layout(screen_width, screen_height)
rl.BeginDrawing()
rl.ClearBackground(rl.BLACK)
@@ -42,12 +48,50 @@ init_gui :: proc(s: ^m.System) {
}
// --------------------------------------
// run each gui "component"
gui_screen(display_rect, s)
gui_left_panel(layout.left_panel, s)
gui_right_panel(layout.right_panel, s)
gui_screen(layout.display, s)
gui_control_bar(layout.control_bar, s)
rl.EndDrawing()
}
rl.CloseAudioDevice()
rl.CloseWindow()
}
}
// TODO: If this grows lets move it into its own file
calc_layout :: proc(screen_width: f32, screen_height: f32) -> Layout {
sidebar_width := screen_width * SIDEBAR_PERCENT
display_height := screen_height * DISPLAY_PERCENT
return Layout {
left_panel = rl.Rectangle {
x = 0,
y = 0,
width = sidebar_width,
height = screen_height
},
right_panel = rl.Rectangle {
x = screen_width - sidebar_width,
y = 0,
width = sidebar_width,
height = screen_height
},
display = rl.Rectangle {
x = sidebar_width,
y = 0,
width = screen_width - (sidebar_width * 2),
height = display_height
},
control_bar = rl.Rectangle {
x = sidebar_width,
y = 0,
width = screen_width - (sidebar_width * 2),
height = (screen_height * 0.05) + display_height
}
}
}