diff --git a/field_pool.odin b/field_pool.odin deleted file mode 100644 index 78051ef..0000000 --- a/field_pool.odin +++ /dev/null @@ -1,44 +0,0 @@ -package main - -import "libraries/fixed_pool" - -Field :: struct($T: typeid) { - value: f32, - input: FieldInput, -} - -FIELD_BYTE_COUNT :: 32 -FieldInput :: [FIELD_BYTE_COUNT]byte -FieldPool :: struct($T: typeid) { - values: fixed_pool.Pool(T), - inputs: fixed_pool.Pool(FieldInput), -} - -field_input_as_cstring :: proc(field_input: ^FieldInput) -> cstring { - return cstring(&field_input[0]) -} - -field_pool_get :: proc(pool: ^FieldPool($T), count: int) -> (values: []T, inputs: []FieldInput) { - return fixed_pool.get(&pool.values, count), fixed_pool.get(&pool.inputs, count) -} - -field_pool_clear :: proc(pool: ^FieldPool($T)) { - fixed_pool.clear(&pool.values) - fixed_pool.clear(&pool.inputs) -} - -field_pool_init :: proc(pool: ^FieldPool($T), capacity: int, allocator := context.allocator) { - fixed_pool.init(&pool.values, capacity, allocator) - fixed_pool.init(&pool.inputs, capacity, allocator) -} - -field_pool_free_range :: proc(pool: ^FieldPool($T), from: int, count: int) { - fixed_pool.free_range(&pool.values, from, count) - fixed_pool.free_range(&pool.inputs, from, count) -} - -field_pool_get_allocated_elems :: proc(pool: ^FieldPool($T)) -> #soa[]Field(T) { - values := fixed_pool.get_allocated_elems(pool.values) - fields := fixed_pool.get_allocated_elems(pool.inputs) - return soa_zip(value = values, input = fields) -} diff --git a/libraries/fixed_pool/fixed_pool.odin b/libraries/fixed_pool/fixed_pool.odin deleted file mode 100644 index 3945781..0000000 --- a/libraries/fixed_pool/fixed_pool.odin +++ /dev/null @@ -1,50 +0,0 @@ -package adb_pool - -Pool :: struct($T: typeid) { - pool: []T, - usage: int, -} - -init :: proc(pool: ^Pool($T), capacity: int, allocator := context.allocator) { - pool.pool = make([]T, capacity, allocator) - pool.usage = 0 -} - -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") - elements := pool.pool[pool.usage:] - pool.usage += count - return elements -} - -usage :: proc(pool: Pool($T)) -> int { - return pool.usage -} - -get_allocated_elements :: proc(pool: Pool($T)) -> []T { - return pool.pool[:pool.usage] -} - -clear :: proc(pool: ^Pool($T)) { - pool.usage = 0 -} - -free_range :: proc(pool: ^Pool($T), from, count: int) { - assert(count > 0, "Cannot free zero or negative count") - to := from + count - 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) -} diff --git a/libraries/raylib/raygui.odin b/libraries/raylib/raygui.odin index b45e5ec..fba81e1 100644 --- a/libraries/raylib/raygui.odin +++ b/libraries/raylib/raygui.odin @@ -280,6 +280,7 @@ foreign lib { GuiDropdownBox :: proc(bounds: Rectangle, text: cstring, active: ^c.int, editMode: bool) -> bool --- // Dropdown Box control, returns selected item GuiSpinner :: proc(bounds: Rectangle, text: cstring, value: ^c.int, minValue, maxValue: c.int, editMode: bool) -> c.int --- // Spinner control, returns selected value GuiValueBox :: proc(bounds: Rectangle, text: cstring, value: ^c.int, minValue, maxValue: c.int, editMode: bool) -> c.int --- // Value Box control, updates input text with numbers + GuiValueBoxFloat :: proc(bounds: Rectangle, text: cstring, text_value: cstring, value: ^c.float, editMode: bool) -> c.int --- // Value box control for float values GuiTextBox :: proc(bounds: Rectangle, text: cstring, textSize: c.int, editMode: bool) -> bool --- // Text Box control, updates input text GuiSlider :: proc(bounds: Rectangle, textLeft: cstring, textRight: cstring, value: ^f32, minValue: f32, maxValue: f32) -> c.int --- // Slider control, returns selected value diff --git a/program.odin b/program.odin index 057753b..de6ad66 100644 --- a/program.odin +++ b/program.odin @@ -2,7 +2,6 @@ package main import rl "libraries/raylib" import ui "libraries/snths_ui" -import "libraries/fixed_pool" import "core:fmt" FontStyle :: struct { @@ -30,9 +29,17 @@ program_set_message_state :: proc(program: ^Program, message: ProgramMessageType program: Program +InputFloatField :: [32]byte +MATRIX_POOL_SIZE :: 4096 + +input_float_field_as_cstring :: proc(field: ^InputFloatField) -> cstring { + return cstring(&field[0]) +} + Program :: struct { ui_context: ui.Context, - matrix_field_pool: FieldPool(f32), + matrix_float_pool: []f32, + matrix_value_string_pool: []InputFloatField, matrix_count: int, grid: Grid, font_style: FontStyle, @@ -46,8 +53,20 @@ Grid :: struct { zoom: f32, } +matrix_pool_max :: proc() -> int { + return len(program.matrix_float_pool) / 9 +} + +matrix_pool_get_mat3 :: proc() -> ^mat3 { + assert(program.matrix_count + 1 < matrix_pool_max(), "Max matrix count exceeded") + mat := cast(^mat3)&program.matrix_float_pool[program.matrix_count * 9] + program.matrix_count += 1 + return mat +} + program_init :: proc(allocator := context.allocator) { - field_pool_init(&program.matrix_field_pool, 4096, allocator) + program.matrix_float_pool = make(type_of(program.matrix_float_pool), MATRIX_POOL_SIZE) + program.matrix_value_string_pool = make(type_of(program.matrix_value_string_pool), MATRIX_POOL_SIZE) program.font_style = { font = rl.GetFontDefault(), size = 16.0, @@ -62,8 +81,14 @@ program_init :: proc(allocator := context.allocator) { } program_update :: proc() { + if rl.IsKeyPressed(.ENTER) { + matrix_pool_get_mat3() + } ui_elements := program_build_ui() - program_render_ui(ui_elements) + if rl.IsKeyPressed(.TAB) { + ui.focus_next_element(&program.ui_context) + } + program_render_ui(&program.ui_context, ui_elements) } program_build_ui :: proc() -> []ui.Element { @@ -90,30 +115,34 @@ program_build_ui :: proc() -> []ui.Element { ui.container_begin({ui.Size_Percentage(0.2), ui.Size_PercentageRemainder(1.0)}, container_config) for i in 0..