Files
octal_cookie/src/gui/gui.odin
T
jasonhilder e6feabe2f1 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
2026-06-03 07:04:04 +02:00

98 lines
2.3 KiB
Odin

package gui
import m "../machine"
import rl "vendor:raylib"
// Initial window size
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})
rl.InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "raylib")
rl.InitAudioDevice()
rl.SetTargetFPS(60)
// Draw each of the components in its own window within the main window
for !rl.WindowShouldClose() {
// Recalculate layout each frame based on current window size
// 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
layout := calc_layout(screen_width, screen_height)
rl.BeginDrawing()
rl.ClearBackground(rl.BLACK)
// TODO: move this out / make better
// --------------------------------------
// CPU cycles
for _ in 0..<12 {
m.handle_input(s)
m.cycle(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
}
}
}