imgui - part 2
This commit is contained in:
parent
22feae4b45
commit
b14c4720a0
2 changed files with 55 additions and 41 deletions
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