same_line next line bugfix
This commit is contained in:
parent
9db12745b2
commit
ca0a8e6e59
2 changed files with 31 additions and 19 deletions
|
|
@ -28,7 +28,7 @@ main :: proc() {
|
||||||
for !rl.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
|
|
||||||
ui.start(&ctx, origin = {0, 0}, size = {WINDOW_WIDTH, WINDOW_HEIGHT})
|
ui.start(&ctx, origin = {0, 0}, size = {WINDOW_WIDTH, WINDOW_HEIGHT})
|
||||||
for i in 0..<9 {
|
for i in 0..<7 {
|
||||||
ui.container_begin(dimensions = {ui.SIZE_AUTO, ui.Size_Percentage(0.1)}, config = inner_container_config)
|
ui.container_begin(dimensions = {ui.SIZE_AUTO, ui.Size_Percentage(0.1)}, config = inner_container_config)
|
||||||
for j in 0..<10 {
|
for j in 0..<10 {
|
||||||
config := button_config
|
config := button_config
|
||||||
|
|
@ -38,6 +38,23 @@ main :: proc() {
|
||||||
}
|
}
|
||||||
ui.container_end()
|
ui.container_end()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ui.container_begin(dimensions = {ui.SIZE_AUTO, ui.Size_Percentage(0.2)}, config = inner_container_config)
|
||||||
|
for j in 0..<10 {
|
||||||
|
config := button_config
|
||||||
|
config.label = fmt.ctprintf("%d", 70 + j)
|
||||||
|
ui.button(dimensions = {ui.Size_Pixels(64.0), ui.Size_Percentage(0.5)}, config = config)
|
||||||
|
ui.same_line()
|
||||||
|
}
|
||||||
|
ctx.same_line = false
|
||||||
|
for j in 0..<10 {
|
||||||
|
config := button_config
|
||||||
|
config.label = fmt.ctprintf("%d", 80 + j)
|
||||||
|
ui.button(dimensions = {ui.Size_Pixels(64.0), ui.Size_Percentage(0.5)}, config = config)
|
||||||
|
ui.same_line()
|
||||||
|
}
|
||||||
|
ui.container_end()
|
||||||
|
|
||||||
ui.container_begin(dimensions = {ui.Size_Percentage(1.0), ui.Size_PercentageRemainder(1.0)}, config = inner_container_config)
|
ui.container_begin(dimensions = {ui.Size_Percentage(1.0), ui.Size_PercentageRemainder(1.0)}, config = inner_container_config)
|
||||||
for j in 0..<10 {
|
for j in 0..<10 {
|
||||||
config := button_config
|
config := button_config
|
||||||
|
|
|
||||||
31
ui.odin
31
ui.odin
|
|
@ -87,13 +87,7 @@ start :: proc(ui_context: ^Context, origin: v2, size: v2) {
|
||||||
clear(&ctx.elements)
|
clear(&ctx.elements)
|
||||||
clear(&ctx.containers)
|
clear(&ctx.containers)
|
||||||
clear(&ctx.container_last_element)
|
clear(&ctx.container_last_element)
|
||||||
append(&ctx.elements, Element{
|
append(&ctx.elements, Element{area = {**origin, **size}, type = .Container})
|
||||||
area = {**origin, **size},
|
|
||||||
label = "",
|
|
||||||
color = {0, 0, 0, 0},
|
|
||||||
margin = {},
|
|
||||||
padding = {},
|
|
||||||
type = .Container})
|
|
||||||
append(&ctx.containers, 0)
|
append(&ctx.containers, 0)
|
||||||
append(&ctx.container_last_element, -1)
|
append(&ctx.container_last_element, -1)
|
||||||
}
|
}
|
||||||
|
|
@ -162,12 +156,6 @@ input_float :: proc(dimensions: Dimensions, config: ElementConfiguration, data:
|
||||||
return _append_element({area = area, config = config, type = .InputFloat, data = {float_input_data = data}, dimensions = dimensions})
|
return _append_element({area = area, config = config, type = .InputFloat, data = {float_input_data = data}, dimensions = dimensions})
|
||||||
}
|
}
|
||||||
|
|
||||||
_append_element :: proc(element: Element) -> ^Element {
|
|
||||||
append(&ctx.elements, element)
|
|
||||||
ctx.container_last_element[len(ctx.containers) - 1] = len(ctx.elements) - 1
|
|
||||||
return &ctx.elements[len(ctx.elements) - 1]
|
|
||||||
}
|
|
||||||
|
|
||||||
get_element_outer_area :: proc(element: Element) -> rect2 {
|
get_element_outer_area :: proc(element: Element) -> rect2 {
|
||||||
return rect_grow(element.area, element.margin * 2.0)
|
return rect_grow(element.area, element.margin * 2.0)
|
||||||
}
|
}
|
||||||
|
|
@ -176,6 +164,12 @@ get_element_inner_area :: proc(element: Element) -> rect2 {
|
||||||
return rect_grow(element.area, -element.padding * 2.0)
|
return rect_grow(element.area, -element.padding * 2.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_append_element :: proc(element: Element) -> ^Element {
|
||||||
|
append(&ctx.elements, element)
|
||||||
|
ctx.container_last_element[len(ctx.containers) - 1] = len(ctx.elements) - 1
|
||||||
|
return &ctx.elements[len(ctx.elements) - 1]
|
||||||
|
}
|
||||||
|
|
||||||
_resolve_element_area :: proc(dimensions: Dimensions, margin: v2) -> rect2 {
|
_resolve_element_area :: proc(dimensions: Dimensions, margin: v2) -> rect2 {
|
||||||
outer_position := _resolve_element_outer_position()
|
outer_position := _resolve_element_outer_position()
|
||||||
outer_size := _resolve_element_outer_size(dimensions)
|
outer_size := _resolve_element_outer_size(dimensions)
|
||||||
|
|
@ -183,15 +177,16 @@ _resolve_element_area :: proc(dimensions: Dimensions, margin: v2) -> rect2 {
|
||||||
}
|
}
|
||||||
|
|
||||||
_resolve_element_outer_position :: proc() -> v2 {
|
_resolve_element_outer_position :: proc() -> v2 {
|
||||||
|
defer {ctx.same_line = false}
|
||||||
if alignment_element := _element_container_previous(); alignment_element != nil {
|
if alignment_element := _element_container_previous(); alignment_element != nil {
|
||||||
area: v2
|
|
||||||
if ctx.same_line {
|
if ctx.same_line {
|
||||||
area = rect_get_tr(get_element_outer_area(alignment_element^))
|
return rect_get_tr(get_element_outer_area(alignment_element^))
|
||||||
} else {
|
} else {
|
||||||
area = rect_get_bl(get_element_outer_area(alignment_element^))
|
return {
|
||||||
|
get_element_inner_area(_container_current()^).x,
|
||||||
|
rect_get_bl(get_element_outer_area(alignment_element^)).y
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ctx.same_line = false
|
|
||||||
return area
|
|
||||||
}
|
}
|
||||||
return rect_get_tl(get_element_inner_area(_element_previous()^))
|
return rect_get_tl(get_element_inner_area(_element_previous()^))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue