From 342f31478ecc3abf1bbd91a5572347d5cb8e530b Mon Sep 17 00:00:00 2001 From: Patrick Cleaveliln Date: Sat, 5 Jul 2025 23:19:22 +0000 Subject: [PATCH] change a bit how panels work --- src/core/core.odin | 24 +++++++++++-------- src/main.odin | 26 ++++++++++++++++++--- src/panels/panels.odin | 53 ++++++++++++++++++++++++++++++++++++++++++ src/util/list.odin | 30 ++++++++++++++++++++++++ 4 files changed, 120 insertions(+), 13 deletions(-) create mode 100644 src/panels/panels.odin create mode 100644 src/util/list.odin diff --git a/src/core/core.odin b/src/core/core.odin index 34f3e6c..e622c55 100644 --- a/src/core/core.odin +++ b/src/core/core.odin @@ -8,6 +8,8 @@ import "core:log" import "vendor:sdl2" import lua "vendor:lua/5.4" +import "../util" + Mode :: enum { Normal, Insert, @@ -48,8 +50,7 @@ State :: struct { command_arena: runtime.Allocator, command_args: [dynamic]EditorCommandArgument, - active_panels: [128]Maybe(Panel), - panel_catalog: [dynamic]PanelId, + panels: util.StaticList(Panel), } EditorCommand :: struct { @@ -68,16 +69,19 @@ EditorCommandArgument :: union #no_nil { i32 } -PanelId :: union { - LibPanelId, -} -Panel :: union { - LibPanel, +PanelRenderProc :: proc(state: ^State, panel_state: ^PanelState) -> (ok: bool) +Panel :: struct { + panel_state: PanelState, + render_proc: PanelRenderProc, } -// TODO -LibPanelId :: struct {} -LibPanel :: struct {} +PanelState :: union { + FileBufferPanel +} + +FileBufferPanel :: struct { + buffer_index: int, +} current_buffer :: proc(state: ^State) -> ^FileBuffer { if state.current_buffer == -2 { diff --git a/src/main.odin b/src/main.odin index 4f941c2..6fe1a62 100644 --- a/src/main.odin +++ b/src/main.odin @@ -13,7 +13,9 @@ import "core:slice" import "vendor:sdl2" import "vendor:sdl2/ttf" +import "util" import "core" +import "panels" import "theme" import "ui" @@ -263,9 +265,24 @@ draw :: proc(state: ^State) { new_ui.max_size.y = state.screen_height // TODO: use the new panels stuff - if file_buffer := core.current_buffer(state); file_buffer != nil { - ui_file_buffer(new_ui, file_buffer) + // if file_buffer := core.current_buffer(state); file_buffer != nil { + // ui_file_buffer(new_ui, file_buffer) + // } + + ui.open_element(new_ui, nil, { + dir = .LeftToRight, + kind = {ui.Grow{}, ui.Grow{}}, + }) + { + for i in 0.. core.Panel { + return core.Panel { + panel_state = core.FileBufferPanel { buffer_index = buffer_index }, + render_proc = proc(state: ^core.State, panel_state: ^core.PanelState) -> (ok: bool) { + panel_state := panel_state.(core.FileBufferPanel) or_return; + + draw_func := proc(state: ^core.State, e: ui.UI_Element, user_data: rawptr) { + buffer := transmute(^core.FileBuffer)user_data; + if buffer != nil { + buffer.glyph_buffer_width = e.layout.size.x / state.source_font_width; + buffer.glyph_buffer_height = e.layout.size.y / state.source_font_height + 1; + + core.draw_file_buffer(state, buffer, e.layout.pos.x, e.layout.pos.y); + } + }; + + s := transmute(^ui.State)state.ui + buffer := &state.buffers[panel_state.buffer_index] + relative_file_path, _ := filepath.rel(state.directory, buffer.file_path, context.temp_allocator) + + ui.open_element(s, nil, { + dir = .TopToBottom, + kind = {ui.Grow{}, ui.Grow{}}, + }) + { + ui.open_element(s, ui.UI_Element_Kind_Custom{fn = draw_func, user_data = transmute(rawptr)buffer}, { + kind = {ui.Grow{}, ui.Grow{}} + }) + ui.close_element(s) + + ui.open_element(s, nil, { + kind = {ui.Grow{}, ui.Exact(state.source_font_height)} + }) + { + ui.open_element(s, fmt.tprintf("%s", state.mode), {}) + ui.close_element(s) + } + ui.close_element(s) + } + ui.close_element(s) + + return true + } + } +} diff --git a/src/util/list.odin b/src/util/list.odin new file mode 100644 index 0000000..86516f4 --- /dev/null +++ b/src/util/list.odin @@ -0,0 +1,30 @@ +package util + +import "base:runtime" + +StaticList :: struct($T: typeid) { + data: []T, + len: int, +} + +append_static_list :: proc(list: ^StaticList($T), value: T) -> bool { + if list.len >= len(list.data) { + return false + } + + list.data[list.len] = value + list.len += 1 + + return true +} +append :: proc{append_static_list} + +make_static_list :: proc($T: typeid, len: int) -> StaticList(T) { + list := StaticList(T) { + data = runtime.make_slice([]T, len) + } + + return list +} + +make :: proc{make_static_list} \ No newline at end of file