Update ui
This commit is contained in:
parent
099fdf1b4b
commit
aee31e8f3a
3 changed files with 94 additions and 61 deletions
|
|
@ -18,7 +18,6 @@ ctx: ^Context
|
|||
|
||||
Context :: struct {
|
||||
origin: v2,
|
||||
element_focus_id: ElementId,
|
||||
container_count: u16,
|
||||
containers: [dynamic]int,
|
||||
container_last_element: [dynamic]int,
|
||||
|
|
@ -57,6 +56,17 @@ ElementType :: enum {
|
|||
Button,
|
||||
Slider,
|
||||
InputFloat,
|
||||
Dropdown,
|
||||
Custom0,
|
||||
Custom1,
|
||||
Custom2,
|
||||
Custom3,
|
||||
Custom4,
|
||||
Custom5,
|
||||
Custom6,
|
||||
Custom7,
|
||||
Custom8,
|
||||
Custom9,
|
||||
}
|
||||
|
||||
@rodata element_type_input := bit_set[ElementType] {.InputFloat}
|
||||
|
|
@ -109,36 +119,18 @@ same_line :: proc() {
|
|||
ctx.same_line = true
|
||||
}
|
||||
|
||||
focus_element :: proc(ctx: ^Context, element: Element) {
|
||||
ctx.element_focus_id = element.id
|
||||
}
|
||||
|
||||
unfocus_element :: proc(ctx: ^Context) {
|
||||
ctx.element_focus_id = element_id_invalid()
|
||||
}
|
||||
|
||||
is_element_focused :: proc(ctx: ^Context, element: Element) -> bool {
|
||||
return ctx.element_focus_id == element.id
|
||||
}
|
||||
|
||||
focus_next_element :: proc(ctx: ^Context, allowed_focus := element_type_input) {
|
||||
if ctx.element_focus_id == element_id_invalid() {
|
||||
return
|
||||
focus_next_element :: proc(id: ElementId, elements: []Element, allowed_focus: bit_set[ElementType]) -> ElementId {
|
||||
if id == element_id_invalid() {
|
||||
return element_id_invalid()
|
||||
}
|
||||
element_index := int(ctx.element_focus_id.element_index)
|
||||
if element_index + 1 >= len(ctx.elements) {
|
||||
ctx.element_focus_id = element_id_invalid()
|
||||
return
|
||||
}
|
||||
element_index += 1
|
||||
for element_index < len(ctx.elements) {
|
||||
if ctx.elements[element_index].type in allowed_focus {
|
||||
ctx.element_focus_id = ctx.elements[element_index].id
|
||||
return
|
||||
element_index := int(id.element_index)
|
||||
for element_index < len(elements) {
|
||||
if elements[element_index].type in allowed_focus {
|
||||
return elements[element_index].id
|
||||
}
|
||||
element_index += 1
|
||||
}
|
||||
ctx.element_focus_id = element_id_invalid()
|
||||
return element_id_invalid()
|
||||
}
|
||||
|
||||
container_begin :: proc(dimensions: Dimensions, config: ElementConfiguration, data: rawptr = nil) -> ^Element {
|
||||
|
|
@ -174,7 +166,8 @@ container_end :: proc() {
|
|||
ctx.same_line = false
|
||||
}
|
||||
|
||||
assert_no_dimensions_percentage_in_auto_container :: proc(dimensions: Dimensions) {
|
||||
element :: proc(element_type: ElementType, dimensions: Dimensions, config: ElementConfiguration, data: rawptr = nil) -> ^Element {
|
||||
assert(element_type != .Container)
|
||||
container := _container_current()
|
||||
if _, is_auto := container.dimensions.width.(Size_Auto); is_auto {
|
||||
_, is_pixels := dimensions.width.(Size_Pixels)
|
||||
|
|
@ -184,24 +177,9 @@ assert_no_dimensions_percentage_in_auto_container :: proc(dimensions: Dimensions
|
|||
_, is_pixels := dimensions.height.(Size_Pixels)
|
||||
assert(is_pixels, "Any height that is not Size_Pixels is disallowed in a container using Size_Auto for height")
|
||||
}
|
||||
}
|
||||
|
||||
button :: proc(dimensions: Dimensions, config: ElementConfiguration, data: rawptr = nil) -> ^Element {
|
||||
assert_no_dimensions_percentage_in_auto_container(dimensions)
|
||||
area := _resolve_element_area(dimensions, config.margin)
|
||||
return _append_element({area = area, config = config, type = .Button, dimensions = dimensions, data = data})
|
||||
}
|
||||
|
||||
slider :: proc(dimensions: Dimensions, config: ElementConfiguration, data: rawptr = nil) -> ^Element {
|
||||
assert_no_dimensions_percentage_in_auto_container(dimensions)
|
||||
area := _resolve_element_area(dimensions, config.margin)
|
||||
return _append_element({area = area, config = config, type = .Slider, dimensions = dimensions, data = data})
|
||||
}
|
||||
|
||||
input_float :: proc(dimensions: Dimensions, config: ElementConfiguration, data: rawptr = nil) -> ^Element {
|
||||
assert_no_dimensions_percentage_in_auto_container(dimensions)
|
||||
area := _resolve_element_area(dimensions, config.margin)
|
||||
return _append_element({area = area, config = config, type = .InputFloat, dimensions = dimensions, data = data})
|
||||
return _append_element({area = area, config = config, type = element_type, dimensions = dimensions, data = data})
|
||||
}
|
||||
|
||||
get_element_outer_area :: proc(element: Element) -> rect2 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue