85 lines
2 KiB
Odin
85 lines
2 KiB
Odin
package main
|
|
|
|
import rl "libraries/raylib"
|
|
import "base:runtime"
|
|
import "core:fmt"
|
|
|
|
WINDOW_WIDTH :: 1280
|
|
WINDOW_HEIGHT :: 720
|
|
WINDOW_FRAMERATE :: 30
|
|
WINDOW_CAPTION :: "Transformation Visualizer"
|
|
|
|
value: i32
|
|
ui_style := UiStyle{margin = 4.0, padding = 4.0}
|
|
ui_state: UiState
|
|
|
|
init :: proc() {
|
|
rl.SetTraceLogLevel(.WARNING)
|
|
rl.SetConfigFlags({.WINDOW_RESIZABLE, .VSYNC_HINT})
|
|
rl.InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_CAPTION)
|
|
rl.SetTargetFPS(WINDOW_FRAMERATE)
|
|
ui_init(&ui_state, ui_style, {0, 0}, context.temp_allocator)
|
|
}
|
|
|
|
update :: proc() {
|
|
if rl.IsMouseButtonPressed(.LEFT) {
|
|
ui_element_focus_reset(&ui_state)
|
|
}
|
|
|
|
rl.BeginDrawing()
|
|
defer rl.EndDrawing()
|
|
rl.ClearBackground(rl.BLACK)
|
|
|
|
ui_start(&ui_state)
|
|
ui_container_begin({label = ""})
|
|
ui_button_size := v2{192.0, 32.0}
|
|
ui_button(ui_button_size, {label = "Hi"})
|
|
ui_same_line()
|
|
ui_button(ui_button_size, {label = "Hi"})
|
|
ui_same_line()
|
|
ui_button(ui_button_size, {label = "Hi"})
|
|
ui_input(ui_button_size, {label = "", value = &value, min = 0, max = 10})
|
|
ui_container_end()
|
|
ui_button(ui_button_size, {label = "notheunoehunh"})
|
|
ui_elements := ui_end()
|
|
|
|
for element in ui_elements {
|
|
switch element.type {
|
|
case .Button:
|
|
data := element.data.(UiElementData_Button)
|
|
rl.GuiButton(element.area, data.label)
|
|
case .Input:
|
|
data := element.data.(UiElementData_Input)
|
|
edit_mode := ui_element_is_editing(ui_state, element.id)
|
|
if (rl.GuiValueBox(element.area, "", data.value, data.min, data.max, edit_mode) == 1) {
|
|
ui_element_focus(&ui_state, element.id)
|
|
}
|
|
case .Container:
|
|
data := element.data.(UiElementData_Container)
|
|
if len(data.label) == 0 {
|
|
rl.DrawRectangleRoundedLinesEx(element.area, 0.1, 2, 1.0, rl.WHITE)
|
|
} else {
|
|
rl.GuiGroupBox(element.area, data.label)
|
|
}
|
|
}
|
|
}
|
|
|
|
free_all(context.temp_allocator)
|
|
}
|
|
|
|
parent_window_size_changed :: proc(w, h: int) {
|
|
rl.SetWindowSize(i32(w), i32(h))
|
|
}
|
|
|
|
shutdown :: proc() {
|
|
rl.CloseWindow()
|
|
}
|
|
|
|
should_run :: proc() -> bool {
|
|
when ODIN_OS != .JS {
|
|
if rl.WindowShouldClose() {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|