Preparing to add matrices to the list
This commit is contained in:
parent
88dee75f7d
commit
4987f1b0d2
4 changed files with 127 additions and 82 deletions
|
|
@ -14,6 +14,10 @@ elems_available :: proc(pool: ^Pool($T), capacity: int) -> bool {
|
|||
return pool.usage + count <= pool.capacity
|
||||
}
|
||||
|
||||
capacity :: proc(pool: Pool($T)) -> int {
|
||||
return len(pool.pool)
|
||||
}
|
||||
|
||||
get :: proc(pool: ^Pool($T), count: int) -> []T {
|
||||
range_to := pool.usage + count
|
||||
assert(range_to <= len(pool.pool), "pool.get count reaches outside preallocated size")
|
||||
|
|
@ -40,3 +44,7 @@ free_range :: proc(pool: ^Pool($T), from, count: int) {
|
|||
assert(to < pool.usage, "Cannot free beyond usage")
|
||||
mem.copy(&pool.pool[from], &pool.pool[to], (pool.usage - to) * size_of(T))
|
||||
}
|
||||
|
||||
raw_data :: proc(pool: ^Pool) -> rawptr {
|
||||
return raw_data(pool.pool)
|
||||
}
|
||||
|
|
@ -11,14 +11,13 @@ rect_get_tr :: #force_inline proc(rect: rect2) -> v2 {return {rect.x + rect.widt
|
|||
rect_get_br :: #force_inline proc(rect: rect2) -> v2 {return {rect.x + rect.width, rect.y + rect.height}}
|
||||
rect_get_bl :: #force_inline proc(rect: rect2) -> v2 {return {rect.x, rect.y + rect.height}}
|
||||
rect_get_size :: #force_inline proc(rect: rect2) -> v2 {return {rect.width, rect.height}}
|
||||
rect_grow :: proc(rect: rect2, amount: v2) -> rect2 {
|
||||
return {rect.x - amount.x / 2.0, rect.y - amount.y / 2.0, rect.width + amount.x, rect.height + amount.y}
|
||||
}
|
||||
rect_grow :: proc(rect: rect2, amount: v2) -> rect2 {return {rect.x - amount.x / 2.0, rect.y - amount.y / 2.0, rect.width + amount.x, rect.height + amount.y}}
|
||||
|
||||
ctx: ^Context
|
||||
|
||||
Context :: struct {
|
||||
origin: v2,
|
||||
element_focus_id: int,
|
||||
containers: [dynamic]int,
|
||||
container_last_element: [dynamic]int,
|
||||
elements: [dynamic]Element,
|
||||
|
|
@ -29,6 +28,7 @@ CONTAINER_STACK_SIZE :: 16
|
|||
|
||||
Element :: struct {
|
||||
area: rect2,
|
||||
id: int,
|
||||
using config: ElementConfiguration,
|
||||
data: ElementData,
|
||||
type: ElementType,
|
||||
|
|
@ -42,12 +42,19 @@ ElementConfiguration :: struct {
|
|||
}
|
||||
|
||||
ElementData :: struct {
|
||||
using float_input_data: ElementData_FloatInput,
|
||||
min, max: f32,
|
||||
value: ^f32,
|
||||
value_string: cstring,
|
||||
}
|
||||
|
||||
ElementData_Slider :: struct {
|
||||
min, max: f32,
|
||||
value: ^f32,
|
||||
}
|
||||
|
||||
ElementData_FloatInput :: struct {
|
||||
min, max: f32,
|
||||
value: ^f32,
|
||||
value: ^f32,
|
||||
value_string: cstring,
|
||||
}
|
||||
|
||||
ElementType :: enum {
|
||||
|
|
@ -57,6 +64,8 @@ ElementType :: enum {
|
|||
InputFloat,
|
||||
}
|
||||
|
||||
@rodata element_type_input := bit_set[ElementType] {.InputFloat}
|
||||
|
||||
Size_Pixels :: distinct f32
|
||||
Size_Percentage :: distinct f32
|
||||
Size_PercentageRemainder :: distinct f32
|
||||
|
|
@ -104,6 +113,36 @@ 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 = -1
|
||||
}
|
||||
|
||||
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 == -1 {
|
||||
return
|
||||
}
|
||||
if ctx.element_focus_id + 1 >= len(ctx.elements) {
|
||||
ctx.element_focus_id = -1
|
||||
return
|
||||
}
|
||||
ctx.element_focus_id += 1
|
||||
for ctx.element_focus_id < len(ctx.elements) {
|
||||
if ctx.elements[ctx.element_focus_id].type in allowed_focus {
|
||||
return
|
||||
}
|
||||
ctx.element_focus_id += 1
|
||||
}
|
||||
ctx.element_focus_id = -1
|
||||
}
|
||||
|
||||
container_begin :: proc(dimensions: Dimensions, config: ElementConfiguration) -> ^Element {
|
||||
area := _resolve_element_area(dimensions, config.margin)
|
||||
element := _append_element({area = area, config = config, type = .Container, dimensions = dimensions})
|
||||
|
|
@ -158,14 +197,14 @@ button :: proc(dimensions: Dimensions, config: ElementConfiguration) -> ^Element
|
|||
dimensions = dimensions})
|
||||
}
|
||||
|
||||
slider :: proc(dimensions: Dimensions, config: ElementConfiguration, data: ElementData_FloatInput) -> ^Element {
|
||||
slider :: proc(dimensions: Dimensions, config: ElementConfiguration, data: ElementData_Slider) -> ^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,
|
||||
data = {float_input_data = data},
|
||||
data = {max = data.max, min = data.min, value = data.value},
|
||||
dimensions = dimensions})
|
||||
}
|
||||
|
||||
|
|
@ -176,7 +215,7 @@ input_float :: proc(dimensions: Dimensions, config: ElementConfiguration, data:
|
|||
area = area,
|
||||
config = config,
|
||||
type = .InputFloat,
|
||||
data = {float_input_data = data},
|
||||
data = {value = data.value, value_string = data.value_string},
|
||||
dimensions = dimensions})
|
||||
}
|
||||
|
||||
|
|
@ -190,8 +229,11 @@ get_element_inner_area :: proc(element: Element) -> rect2 {
|
|||
|
||||
_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]
|
||||
last_element_index := len(ctx.elements) - 1
|
||||
last_element := &ctx.elements[last_element_index]
|
||||
last_element.id = last_element_index
|
||||
ctx.container_last_element[len(ctx.containers) - 1] = last_element_index
|
||||
return last_element
|
||||
}
|
||||
|
||||
_resolve_element_area :: proc(dimensions: Dimensions, margin: v2) -> rect2 {
|
||||
|
|
@ -222,7 +264,7 @@ _resolve_element_outer_size :: proc(dimensions: Dimensions) -> v2 {
|
|||
_resolve_elemment_outer_size_axis :: proc(size: Size, axis: Axis) -> f32 {
|
||||
switch value in size {
|
||||
case Size_Pixels:
|
||||
return cast(f32)value
|
||||
return f32(value)
|
||||
case Size_Percentage:
|
||||
inner := get_element_inner_area(_container_current()^)
|
||||
container_size := inner.width if axis == .X else inner.height
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue