imgui - part 2
This commit is contained in:
parent
22feae4b45
commit
b14c4720a0
2 changed files with 55 additions and 41 deletions
|
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import rl "libraries/raylib"
|
||||
import "base:runtime"
|
||||
import "core:fmt"
|
||||
|
||||
WINDOW_WIDTH :: 1280
|
||||
WINDOW_HEIGHT :: 720
|
||||
|
|
@ -15,6 +16,8 @@ init :: proc() {
|
|||
rl.SetTargetFPS(WINDOW_FRAMERATE)
|
||||
}
|
||||
|
||||
value: i32
|
||||
|
||||
update :: proc() {
|
||||
rl.BeginDrawing()
|
||||
defer rl.EndDrawing()
|
||||
|
|
@ -31,7 +34,9 @@ update :: proc() {
|
|||
ui_button(&ui_state, ui_button_size, {label = "Hi"})
|
||||
ui_same_line(&ui_state)
|
||||
ui_button(&ui_state, ui_button_size, {label = "Hi"})
|
||||
ui_input(&ui_state, ui_button_size, {label = "", value = &value, min = 0, max = 10})
|
||||
ui_container_end(&ui_state)
|
||||
ui_button(&ui_state, ui_button_size, {label = "notheunoehunh"})
|
||||
ui_elements := ui_end(ui_state)
|
||||
|
||||
for element in ui_elements {
|
||||
|
|
@ -40,6 +45,9 @@ update :: proc() {
|
|||
data := element.data.(UiElementData_Button)
|
||||
rl.GuiButton(element.area, data.label)
|
||||
case .Input:
|
||||
data := element.data.(UiElementData_Input)
|
||||
value := rl.GuiValueBox(element.area, "", data.value, data.min, data.max, true)
|
||||
fmt.println(value)
|
||||
case .Container:
|
||||
data := element.data.(UiElementData_Container)
|
||||
if len(data.label) == 0 {
|
||||
|
|
@ -47,7 +55,6 @@ update :: proc() {
|
|||
} else {
|
||||
rl.GuiGroupBox(element.area, data.label)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
87
ui.odin
87
ui.odin
|
|
@ -16,18 +16,6 @@ UiElementData :: union {
|
|||
UiElementData_Container,
|
||||
}
|
||||
|
||||
UiElementData_Button :: struct {
|
||||
label: cstring,
|
||||
}
|
||||
|
||||
UiElementData_Container :: struct {
|
||||
label: cstring,
|
||||
}
|
||||
|
||||
UiElementData_Input :: struct {
|
||||
label: cstring,
|
||||
}
|
||||
|
||||
UiElement :: struct {
|
||||
area: rect2,
|
||||
type: UiElementType,
|
||||
|
|
@ -47,20 +35,67 @@ UiStyle :: struct {
|
|||
margin, padding: f32,
|
||||
}
|
||||
|
||||
ui_start :: proc(state: ^UiState) {
|
||||
clear(&state.elements)
|
||||
state.position_left = state.origin
|
||||
state.position = state.position_left
|
||||
}
|
||||
|
||||
ui_end :: proc(state: UiState) -> []UiElement {
|
||||
return state.elements[:]
|
||||
}
|
||||
|
||||
UiElementData_Button :: struct {
|
||||
label: cstring,
|
||||
}
|
||||
|
||||
ui_button :: proc(state: ^UiState, size: v2, data: UiElementData_Button) {
|
||||
area := _ui_advance_element(state, size)
|
||||
append(&state.elements, UiElement{area = area, type = .Button, data = data})
|
||||
}
|
||||
|
||||
UiElementData_Container :: struct {
|
||||
label: cstring,
|
||||
}
|
||||
|
||||
ui_container_begin :: proc(state: ^UiState, data: UiElementData_Container) {
|
||||
assert(state.container == nil)
|
||||
append(&state.elements, UiElement{area = _ui_advance_container(state), type = .Container, data = data})
|
||||
state.position_left += state.style.margin + state.style.padding
|
||||
state.container = &state.elements[len(state.elements) - 1]
|
||||
}
|
||||
|
||||
ui_container_end :: proc(state: ^UiState) {
|
||||
assert(state.container != nil)
|
||||
state.position_left.x = state.origin.x
|
||||
state.position_left.y = state.container.area.y + state.container.area.height
|
||||
state.position = state.position_left
|
||||
state.container = nil
|
||||
state.group_element_count = 0
|
||||
}
|
||||
|
||||
UiElementData_Input :: struct {
|
||||
label: cstring,
|
||||
value: ^i32,
|
||||
min, max: i32,
|
||||
}
|
||||
|
||||
ui_input :: proc(state: ^UiState, size: v2, data: UiElementData_Input) {
|
||||
area := _ui_advance_element(state, size)
|
||||
append(&state.elements, UiElement{area = area, type = .Input, data = data})
|
||||
}
|
||||
|
||||
ui_same_line :: proc(state: ^UiState) {
|
||||
state.same_line = true
|
||||
}
|
||||
|
||||
ui_init :: proc(state: ^UiState, style: UiStyle, origin: v2, allocator: mem.Allocator) {
|
||||
state^ = {
|
||||
origin = origin,
|
||||
position = origin,
|
||||
style = style,
|
||||
elements = make(type_of(state.elements), 0, 512, allocator)
|
||||
}
|
||||
}
|
||||
|
||||
_ui_advance_element :: proc(state: ^UiState, size: v2) -> rect2 {
|
||||
|
|
@ -91,31 +126,3 @@ _ui_advance_container :: proc(state: ^UiState) -> rect2 {
|
|||
state.position += state.style.margin
|
||||
return {**state.position, 0.0, 0.0}
|
||||
}
|
||||
|
||||
ui_input :: proc(state: ^UiState, size: v2, data: UiElementData_Input) {
|
||||
area := _ui_advance_element(state, size)
|
||||
append(&state.elements, UiElement{area = area, type = .Input, data = data})
|
||||
}
|
||||
|
||||
ui_same_line :: proc(state: ^UiState) {
|
||||
state.same_line = true
|
||||
}
|
||||
|
||||
ui_start :: proc(state: ^UiState) {
|
||||
clear(&state.elements)
|
||||
state.position_left = state.origin
|
||||
state.position = state.position_left
|
||||
}
|
||||
|
||||
ui_end :: proc(state: UiState) -> []UiElement {
|
||||
return state.elements[:]
|
||||
}
|
||||
|
||||
ui_init :: proc(state: ^UiState, style: UiStyle, origin: v2, allocator: mem.Allocator) {
|
||||
state^ = {
|
||||
origin = origin,
|
||||
position = origin,
|
||||
style = style,
|
||||
elements = make(type_of(state.elements), 0, 512, allocator)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue