Buttons debug
This commit is contained in:
parent
cd42cee14b
commit
6c8479f922
2 changed files with 95 additions and 38 deletions
38
ui.odin
38
ui.odin
|
|
@ -2,6 +2,7 @@ package synthas_ui
|
|||
|
||||
v2 :: [2]f32
|
||||
rect2 :: struct {x, y, width, height: f32}
|
||||
col :: [4]u8
|
||||
|
||||
rect_get_tl :: #force_inline proc(rect: rect2) -> v2 {return {rect.x, rect.y}}
|
||||
rect_get_tr :: #force_inline proc(rect: rect2) -> v2 {return {rect.x + rect.width, rect.y}}
|
||||
|
|
@ -27,18 +28,29 @@ CONTAINER_STACK_SIZE :: 16
|
|||
Element :: struct {
|
||||
area: rect2,
|
||||
using config: ElementConfiguration,
|
||||
data: ElementData,
|
||||
type: ElementType,
|
||||
}
|
||||
|
||||
ElementConfiguration :: struct {
|
||||
label: cstring,
|
||||
color: [4]u8,
|
||||
color: col,
|
||||
margin, padding: v2,
|
||||
}
|
||||
|
||||
ElementData :: struct {
|
||||
using float_input_data: ElementData_FloatInput,
|
||||
}
|
||||
|
||||
ElementData_FloatInput :: struct {
|
||||
min, max: f32,
|
||||
value: ^f32,
|
||||
}
|
||||
|
||||
ElementType :: enum {
|
||||
Container,
|
||||
Button,
|
||||
Slider,
|
||||
}
|
||||
|
||||
Size_Pixels :: distinct f32
|
||||
|
|
@ -85,7 +97,7 @@ end :: proc() -> []Element {
|
|||
assert(len(ctx.containers) > 0, "Closed base container before ending UI layout mode")
|
||||
elements := ctx.elements[:]
|
||||
ctx = nil
|
||||
return elements
|
||||
return elements[1:]
|
||||
}
|
||||
|
||||
same_line :: proc() {
|
||||
|
|
@ -94,7 +106,7 @@ same_line :: proc() {
|
|||
|
||||
container_begin :: proc(dimensions: Dimensions, config: ElementConfiguration) -> ^Element {
|
||||
area := _resolve_element_area(dimensions, config.margin)
|
||||
element := _append_element(Element{area = area, config = config, type = .Container})
|
||||
element := _append_element({area = area, config = config, type = .Container})
|
||||
container_index := len(ctx.elements) - 1
|
||||
append(&ctx.containers, container_index)
|
||||
append(&ctx.container_last_element, -1)
|
||||
|
|
@ -105,11 +117,18 @@ container_end :: proc() {
|
|||
container := ctx.elements[pop(&ctx.containers)]
|
||||
pop(&ctx.container_last_element)
|
||||
// TODO: Set flex
|
||||
ctx.same_line = false
|
||||
outer := get_element_outer_area(container)
|
||||
}
|
||||
|
||||
button :: proc(dimensions: Dimensions) -> ^Element {
|
||||
return nil
|
||||
button :: proc(dimensions: Dimensions, config: ElementConfiguration) -> ^Element {
|
||||
area := _resolve_element_area(dimensions, config.margin)
|
||||
return _append_element({area = area, config = config, type = .Button})
|
||||
}
|
||||
|
||||
slider :: proc(dimensions: Dimensions, config: ElementConfiguration, data: ElementData_FloatInput) -> ^Element {
|
||||
area := _resolve_element_area(dimensions, config.margin)
|
||||
return _append_element({area = area, config = config, type = .Slider, data = {float_input_data = data}})
|
||||
}
|
||||
|
||||
_append_element :: proc(element: Element) -> ^Element {
|
||||
|
|
@ -134,7 +153,14 @@ _resolve_element_area :: proc(dimensions: Dimensions, margin: v2) -> rect2 {
|
|||
|
||||
_resolve_element_outer_position :: proc() -> v2 {
|
||||
if alignment_element := _element_container_previous(); alignment_element != nil {
|
||||
return rect_get_bl(get_element_outer_area(alignment_element^))
|
||||
area: v2
|
||||
if ctx.same_line {
|
||||
area = rect_get_tr(get_element_outer_area(alignment_element^))
|
||||
} else {
|
||||
area = rect_get_bl(get_element_outer_area(alignment_element^))
|
||||
}
|
||||
ctx.same_line = false
|
||||
return area
|
||||
}
|
||||
return rect_get_tl(get_element_inner_area(_element_previous()^))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue