diff --git a/plugins/buffer_search/plugin.odin b/plugins/buffer_search/plugin.odin index ddc1170..3905330 100644 --- a/plugins/buffer_search/plugin.odin +++ b/plugins/buffer_search/plugin.odin @@ -3,8 +3,11 @@ package buffer_search; import "core:runtime" import "core:fmt" +import "core:path/filepath" +import "vendor:raylib" import p "../../src/plugin" +import "../../src/theme" Plugin :: p.Plugin; Iterator :: p.Iterator; @@ -12,6 +15,10 @@ BufferIter :: p.BufferIter; BufferIndex :: p.BufferIndex; Key :: p.Key; +BufferListWindow :: struct { + selected_index: int, +} + @export OnInitialize :: proc "c" (plugin: Plugin) { context = runtime.default_context(); @@ -30,30 +37,141 @@ OnExit :: proc "c" (plugin: Plugin) { open_buffer_window :: proc "c" (plugin: Plugin) { context = runtime.default_context(); - fmt.println("Look you tried opening a window from a plugin!"); + window := new(BufferListWindow); + window^ = BufferListWindow {}; - window := plugin.create_window(proc "c" (plugin: Plugin, input_map: rawptr) { + plugin.create_window(window, proc "c" (plugin: Plugin, input_map: rawptr) { plugin.register_input(input_map, .K, proc "c" (plugin: Plugin) { context = runtime.default_context(); - fmt.println("haha, moving up does nothing"); + win := cast(^BufferListWindow)plugin.get_window(); + if win != nil { + if win.selected_index > 0 { + win.selected_index -= 1; + } else { + win.selected_index = plugin.buffer.get_num_buffers()-1; + } + } }, "move selection up"); plugin.register_input(input_map, .J, proc "c" (plugin: Plugin) { context = runtime.default_context(); - fmt.println("haha, moving down does nothing"); + win := cast(^BufferListWindow)plugin.get_window(); + if win != nil { + if win.selected_index < plugin.buffer.get_num_buffers()-1 { + win.selected_index += 1; + } else { + win.selected_index = 0; + } + } }, "move selection down"); - }, draw_buffer_window); + plugin.register_input(input_map, .ENTER, proc "c" (plugin: Plugin) { + context = runtime.default_context(); + + win := cast(^BufferListWindow)plugin.get_window(); + if win != nil { + plugin.buffer.set_current_buffer(win.selected_index); + } + + plugin.request_window_close(); + }, "switch to buffer") + }, draw_buffer_window, free_buffer_window); } -draw_buffer_window :: proc "c" (plugin: Plugin, window: rawptr) { +free_buffer_window :: proc "c" (plugin: Plugin, win: rawptr) { context = runtime.default_context(); + win := cast(^BufferListWindow)plugin.get_window(); + if win == nil { + return; + } + + free(win); +} + +buffer_list_iter :: proc(plugin: Plugin, buffer_index: ^int) -> (int, int, bool) { + if buffer_index^ == -1 { + return 0, 0, false; + } + + index := plugin.iter.get_buffer_list_iter(buffer_index); + return index, 0, true; +} + +draw_buffer_window :: proc "c" (plugin: Plugin, win: rawptr) { + context = runtime.default_context(); + win := cast(^BufferListWindow)win; + if win == nil { + return; + } + + screen_width := plugin.get_screen_width(); + screen_height := plugin.get_screen_height(); + source_font_width := plugin.get_font_width(); + source_font_height := plugin.get_font_height(); + + win_rec := raylib.Rectangle { + x = f32(screen_width/8), + y = f32(screen_height/8), + width = f32(screen_width - screen_width/4), + height = f32(screen_height - screen_height/4), + }; + plugin.draw_rect( + i32(win_rec.x), + i32(win_rec.y), + i32(win_rec.width), + i32(win_rec.height), + .Background4 + ); + + win_margin := raylib.Vector2 { f32(source_font_width), f32(source_font_height) }; + + buffer_prev_width := (win_rec.width - win_margin.x*2) / 2; + buffer_prev_height := win_rec.height - win_margin.y*2; + + glyph_buffer_width := int(buffer_prev_width) / source_font_width - 1; + glyph_buffer_height := int(buffer_prev_height) / source_font_height; + + directory := string(plugin.get_current_directory()); plugin.draw_rect( - 0, - 0, - 64, - 64, - 0x000000ff, + i32(win_rec.x + win_rec.width / 2), + i32(win_rec.y + win_margin.y), + i32(buffer_prev_width), + i32(buffer_prev_height), + .Background2, ); + + _buffer_index := 0; + for index in buffer_list_iter(plugin, &_buffer_index) { + buffer := plugin.buffer.get_buffer_info_from_index(index); + relative_file_path, _ := filepath.rel(directory, string(buffer.file_path), context.temp_allocator) + text := fmt.ctprintf("%s:%d", relative_file_path, buffer.cursor.line+1); + text_width := len(text) * source_font_width; + + if index == win.selected_index { + plugin.draw_buffer( + index, + int(win_rec.x + win_margin.x + win_rec.width / 2), + int(win_rec.y + win_margin.y), + glyph_buffer_width, + glyph_buffer_height, + false); + + plugin.draw_rect( + i32(win_rec.x + win_margin.x), + i32(win_rec.y + win_margin.y) + i32(index * source_font_height), + i32(text_width), + i32(source_font_height), + .Background2, + ); + } + + plugin.draw_text( + text, + win_rec.x + win_margin.x, win_rec.y + win_margin.y + f32(index * source_font_height), + .Foreground2 + ); + + runtime.free_all(context.temp_allocator); + } } diff --git a/plugins/highlighter/src/plugin.odin b/plugins/highlighter/src/plugin.odin index c7288ff..f423996 100644 --- a/plugins/highlighter/src/plugin.odin +++ b/plugins/highlighter/src/plugin.odin @@ -280,10 +280,10 @@ is_rust_keyword :: proc(plugin: Plugin, start: BufferIter, end: BufferIter) -> ( color_buffer_odin :: proc "c" (plugin: Plugin, buffer: rawptr) { context = runtime.default_context(); - start_it := plugin.iter.get_buffer_iterator(buffer); - it := plugin.iter.get_buffer_iterator(buffer); + buffer := plugin.buffer.get_buffer_info(buffer); - buffer := plugin.buffer.get_buffer_info(); + start_it := plugin.iter.get_buffer_iterator(buffer.buffer); + it := plugin.iter.get_buffer_iterator(buffer.buffer); for character in iterate_buffer(plugin.iter, &it) { if it.cursor.line > buffer.glyph_buffer_height && (it.cursor.line - buffer.top_line) > buffer.glyph_buffer_height { @@ -350,10 +350,10 @@ color_buffer_odin :: proc "c" (plugin: Plugin, buffer: rawptr) { color_buffer_rust :: proc "c" (plugin: Plugin, buffer: rawptr) { context = runtime.default_context(); - start_it := plugin.iter.get_buffer_iterator(buffer); - it := plugin.iter.get_buffer_iterator(buffer); + buffer := plugin.buffer.get_buffer_info(buffer); - buffer := plugin.buffer.get_buffer_info(); + start_it := plugin.iter.get_buffer_iterator(buffer.buffer); + it := plugin.iter.get_buffer_iterator(buffer.buffer); for character in iterate_buffer(plugin.iter, &it) { if it.cursor.line > buffer.glyph_buffer_height && (it.cursor.line - buffer.top_line) > buffer.glyph_buffer_height { diff --git a/src/core/core.odin b/src/core/core.odin index 38f6b98..fced658 100644 --- a/src/core/core.odin +++ b/src/core/core.odin @@ -11,17 +11,19 @@ Mode :: enum { Insert, } -WindowDrawProc :: proc "c" (plugin: plugin.Plugin, win: rawptr); -WindowFreeProc :: proc(win: ^Window, state: ^State); +WindowDrawProc :: proc "c" (plugin: plugin.Plugin, user_data: rawptr); +WindowFreeProc :: proc "c" (plugin: plugin.Plugin, user_data: rawptr); WindowGetBufferProc :: proc(win: ^Window) -> ^FileBuffer; Window :: struct { input_map: InputMap, draw: WindowDrawProc, - free: WindowFreeProc, + free_user_data: WindowFreeProc, get_buffer: WindowGetBufferProc, // TODO: create hook for when mode changes happen + + user_data: rawptr, } request_window_close :: proc(state: ^State) { state.should_close_window = true; @@ -29,8 +31,8 @@ request_window_close :: proc(state: ^State) { close_window_and_free :: proc(state: ^State) { if state.window != nil { - if state.window.free != nil { - state.window->free(state); + if state.window.free_user_data != nil { + state.window.free_user_data(state.plugin_vtable, state.window.user_data); } delete_input_map(&state.window.input_map); diff --git a/src/core/file_buffer.odin b/src/core/file_buffer.odin index 40bd6db..a424893 100644 --- a/src/core/file_buffer.odin +++ b/src/core/file_buffer.odin @@ -11,6 +11,7 @@ import "core:strings" import "vendor:raylib" import "../theme" +import "../plugin" ScrollDir :: enum { Up, @@ -617,6 +618,40 @@ new_file_buffer :: proc(allocator: mem.Allocator, file_path: string, base_dir: s } } +next_buffer :: proc(state: ^State, prev_buffer: ^int) -> int { + index := prev_buffer^; + + if prev_buffer^ >= len(state.buffers)-1 { + prev_buffer^ = -1; + } else { + prev_buffer^ += 1; + } + + return index; +} + +into_buffer_info:: proc(state: ^State, buffer: ^FileBuffer) -> plugin.BufferInfo { + return plugin.BufferInfo { + buffer = buffer, + cursor = plugin.Cursor { + col = buffer.cursor.col, + line = buffer.cursor.line, + index = plugin.BufferIndex { + slice_index = buffer.cursor.index.slice_index, + content_index = buffer.cursor.index.content_index, + } + }, + file_path = strings.clone_to_cstring(buffer.file_path, context.temp_allocator), + glyph_buffer_width = buffer.glyph_buffer_width, + glyph_buffer_height = buffer.glyph_buffer_height, + top_line = buffer.top_line, + }; +} +into_buffer_info_from_index :: proc(state: ^State, buffer_index: int) -> plugin.BufferInfo { + buffer := &state.buffers[buffer_index]; + return into_buffer_info(state, buffer); +} + free_file_buffer :: proc(buffer: ^FileBuffer) { delete(buffer.original_content); delete(buffer.added_content); @@ -625,145 +660,6 @@ free_file_buffer :: proc(buffer: ^FileBuffer) { delete(buffer.input_buffer); } -is_keyword :: proc(start: FileBufferIter, end: FileBufferIter) -> (matches: bool) { - keywords := []string { - "using", - "transmute", - "cast", - "distinct", - "opaque", - "where", - "struct", - "enum", - "union", - "bit_field", - "bit_set", - "if", - "when", - "else", - "do", - "for", - "switch", - "case", - "continue", - "break", - "size_of", - "offset_of", - "type_info_of", - "typeid_of", - "type_of", - "align_of", - "or_return", - "or_else", - "inline", - "no_inline", - "string", - "cstring", - "bool", - "b8", - "b16", - "b32", - "b64", - "rune", - "any", - "rawptr", - "f16", - "f32", - "f64", - "f16le", - "f16be", - "f32le", - "f32be", - "f64le", - "f64be", - "u8", - "u16", - "u32", - "u64", - "u128", - "u16le", - "u32le", - "u64le", - "u128le", - "u16be", - "u32be", - "u64be", - "u128be", - "uint", - "uintptr", - "i8", - "i16", - "i32", - "i64", - "i128", - "i16le", - "i32le", - "i64le", - "i128le", - "i16be", - "i32be", - "i64be", - "i128be", - "int", - "complex", - "complex32", - "complex64", - "complex128", - "quaternion", - "quaternion64", - "quaternion128", - "quaternion256", - "matrix", - "typeid", - "true", - "false", - "nil", - "dynamic", - "map", - "proc", - "in", - "notin", - "not_in", - "import", - "export", - "foreign", - "const", - "package", - "return", - "defer", - }; - - for keyword in keywords { - it := start; - keyword_index := 0; - - for character in iterate_file_buffer(&it) { - if character != keyword[keyword_index] { - break; - } - - keyword_index += 1; - if keyword_index >= len(keyword)-1 && it == end { - if get_character_at_iter(it) == keyword[keyword_index] { - matches = true; - } - - break; - } else if keyword_index >= len(keyword)-1 { - break; - } else if it == end { - break; - } - } - - if matches { - break; - } - } - - return; -} - color_character :: proc(buffer: ^FileBuffer, start: Cursor, end: Cursor, palette_index: theme.PaletteColor) { start, end := start, end; diff --git a/src/main.odin b/src/main.odin index dc3fdd3..7d031ba 100644 --- a/src/main.odin +++ b/src/main.odin @@ -290,12 +290,15 @@ main :: proc() { core.register_key_action(to_be_edited_map, key, input_action, description); } }, - create_window = proc "c" (register_group: plugin.InputGroupProc, draw_proc: plugin.WindowDrawProc) -> rawptr { + create_window = proc "c" (user_data: rawptr, register_group: plugin.InputGroupProc, draw_proc: plugin.WindowDrawProc, free_window_proc: plugin.WindowFreeProc) -> rawptr { context = state.ctx; window := new(core.Window); window^ = core.Window { input_map = core.new_input_map(), draw = draw_proc, + free_user_data = free_window_proc, + + user_data = user_data, }; register_group(state.plugin_vtable, transmute(rawptr)&window.input_map); @@ -305,7 +308,68 @@ main :: proc() { return window; }, - draw_rect = raylib.DrawRectangle, + get_window = proc "c" () -> rawptr { + if state.window != nil { + return state.window.user_data; + } + + return nil; + }, + request_window_close = proc "c" () { + context = state.ctx; + + core.request_window_close(&state); + }, + get_screen_width = proc "c" () -> int { + return state.screen_width; + }, + get_screen_height = proc "c" () -> int { + return state.screen_height; + }, + get_font_width = proc "c" () -> int { + return state.source_font_width; + }, + get_font_height = proc "c" () -> int { + return state.source_font_height; + }, + get_current_directory = proc "c" () -> cstring { + context = state.ctx; + + return strings.clone_to_cstring(state.directory, context.temp_allocator); + }, + draw_rect = proc "c" (x: i32, y: i32, width: i32, height: i32, color: theme.PaletteColor) { + context = state.ctx; + + raylib.DrawRectangle(x, y, width, height, theme.get_palette_raylib_color(color)); + }, + draw_text = proc "c" (text: cstring, x: f32, y: f32, color: theme.PaletteColor) { + context = state.ctx; + + raylib.DrawTextEx( + state.font, + text, + raylib.Vector2 { + x, + y, + }, + f32(state.source_font_height), + 0, + theme.get_palette_raylib_color(color) + ); + }, + draw_buffer = proc "c" (buffer_index: int, x: int, y: int, glyph_buffer_width: int, glyph_buffer_height: int, show_line_numbers: bool) { + context = state.ctx; + state.buffers[buffer_index].glyph_buffer_width = glyph_buffer_width; + state.buffers[buffer_index].glyph_buffer_height = glyph_buffer_height; + + core.draw_file_buffer( + &state, + &state.buffers[buffer_index], + x, + y, + state.font, + show_line_numbers); + }, iter = plugin.Iterator { get_current_buffer_iterator = proc "c" () -> plugin.BufferIter { context = state.ctx; @@ -364,6 +428,11 @@ main :: proc() { return core.get_character_at_iter(internal_it); }, + get_buffer_list_iter = proc "c" (prev_buffer: ^int) -> int { + context = state.ctx; + + return core.next_buffer(&state, prev_buffer); + }, iterate_buffer = proc "c" (it: ^plugin.BufferIter) -> plugin.IterateResult { context = state.ctx; @@ -513,16 +582,22 @@ main :: proc() { until_end_of_word = transmute(rawptr)core.until_end_of_word, }, buffer = plugin.Buffer { - get_buffer_info = proc "c" () -> plugin.BufferInfo { + get_num_buffers = proc "c" () -> int { context = state.ctx; - buffer := &state.buffers[state.current_buffer]; + return len(state.buffers); + }, + get_buffer_info = proc "c" (buffer: rawptr) -> plugin.BufferInfo { + context = state.ctx; + buffer := cast(^core.FileBuffer)buffer; - return plugin.BufferInfo { - glyph_buffer_width = buffer.glyph_buffer_width, - glyph_buffer_height = buffer.glyph_buffer_height, - top_line = buffer.top_line, - }; + return core.into_buffer_info(&state, buffer); + }, + get_buffer_info_from_index = proc "c" (buffer_index: int) -> plugin.BufferInfo { + context = state.ctx; + buffer := &state.buffers[buffer_index]; + + return core.into_buffer_info(&state, buffer); }, color_char_at = proc "c" (buffer: rawptr, start_cursor: plugin.Cursor, end_cursor: plugin.Cursor, palette_index: i32) { buffer := cast(^core.FileBuffer)buffer; @@ -546,6 +621,9 @@ main :: proc() { }; core.color_character(buffer, start_cursor, end_cursor, cast(theme.PaletteColor)palette_index); + }, + set_current_buffer = proc "c" (buffer_index: int) { + state.current_buffer = buffer_index; } } }; @@ -692,7 +770,7 @@ main :: proc() { theme.get_palette_raylib_color(.Background1)); if state.window != nil && state.window.draw != nil { - state.window.draw(state.plugin_vtable, state.window); + state.window.draw(state.plugin_vtable, state.window.user_data); } if state.current_input_map != &state.input_map { @@ -764,6 +842,8 @@ main :: proc() { } ui.test_menu_bar(&state, &menu_bar_state, 0,0, mouse_pos, raylib.IsMouseButtonReleased(.LEFT), state.source_font_height); + + runtime.free_all(context.temp_allocator); } for plugin in state.plugins { diff --git a/src/plugin/plugin.odin b/src/plugin/plugin.odin index 5ee9be5..413a981 100644 --- a/src/plugin/plugin.odin +++ b/src/plugin/plugin.odin @@ -5,6 +5,8 @@ import "core:dynlib" import "core:fmt" import "vendor:raylib" +import "../theme" + OnInitializeProc :: proc "c" (plugin: Plugin); OnExitProc :: proc "c" (/* probably needs some state eventually */); OnDrawProc :: proc "c" (plugin: Plugin); @@ -37,20 +39,29 @@ IterateResult :: struct { } BufferInfo :: struct { + buffer: rawptr, + file_path: cstring, + + cursor: Cursor, + glyph_buffer_width: int, glyph_buffer_height: int, top_line: int, } Buffer :: struct { - get_buffer_info: proc "c" () -> BufferInfo, + get_num_buffers: proc "c" () -> int, + get_buffer_info: proc "c" (buffer: rawptr) -> BufferInfo, + get_buffer_info_from_index: proc "c" (buffer_index: int) -> BufferInfo, color_char_at: proc "c" (buffer: rawptr, start_cursor: Cursor, end_cursor: Cursor, palette_index: i32), + set_current_buffer: proc "c" (buffer_index: int), } Iterator :: struct { get_current_buffer_iterator: proc "c" () -> BufferIter, get_buffer_iterator: proc "c" (buffer: rawptr) -> BufferIter, get_char_at_iter: proc "c" (it: ^BufferIter) -> u8, + get_buffer_list_iter: proc "c" (prev_buffer: ^int) -> int, iterate_buffer: proc "c" (it: ^BufferIter) -> IterateResult, iterate_buffer_reverse: proc "c" (it: ^BufferIter) -> IterateResult, @@ -64,6 +75,37 @@ Iterator :: struct { until_end_of_word: rawptr, } +OnColorBufferProc :: proc "c" (plugin: Plugin, buffer: rawptr); +InputGroupProc :: proc "c" (plugin: Plugin, input_map: rawptr); +InputActionProc :: proc "c" (plugin: Plugin); +WindowInputProc :: proc "c" (plugin: Plugin, window: rawptr); +WindowDrawProc :: proc "c" (plugin: Plugin, window: rawptr); +WindowFreeProc :: proc "c" (plugin: Plugin, window: rawptr); +Plugin :: struct { + state: rawptr, + iter: Iterator, + buffer: Buffer, + + register_highlighter: proc "c" (extension: cstring, on_color_buffer: OnColorBufferProc), + + register_input_group: proc "c" (input_map: rawptr, key: Key, register_group: InputGroupProc), + register_input: proc "c" (input_map: rawptr, key: Key, input_action: InputActionProc, description: cstring), + + create_window: proc "c" (user_data: rawptr, register_group: InputGroupProc, draw_proc: WindowDrawProc, free_window_proc: WindowFreeProc) -> rawptr, + get_window: proc "c" () -> rawptr, + + request_window_close: proc "c" (), + get_screen_width: proc "c" () -> int, + get_screen_height: proc "c" () -> int, + get_font_width: proc "c" () -> int, + get_font_height: proc "c" () -> int, + get_current_directory: proc "c" () -> cstring, + + draw_rect: proc "c" (x: i32, y: i32, width: i32, height: i32, color: theme.PaletteColor), + draw_text: proc "c" (text: cstring, x: f32, y: f32, color: theme.PaletteColor), + draw_buffer: proc "c" (buffer_index: int, x: int, y: int, glyph_buffer_width: int, glyph_buffer_height: int, show_line_numbers: bool), +} + Key :: enum { KEY_NULL = 0, // Key: NULL, used for no key pressed // Alphanumeric keys @@ -182,26 +224,6 @@ Key :: enum { } -OnColorBufferProc :: proc "c" (plugin: Plugin, buffer: rawptr); -InputGroupProc :: proc "c" (plugin: Plugin, input_map: rawptr); -InputActionProc :: proc "c" (plugin: Plugin); -WindowInputProc :: proc "c" (plugin: Plugin, window: rawptr); -WindowDrawProc :: proc "c" (plugin: Plugin, window: rawptr); -Plugin :: struct { - state: rawptr, - iter: Iterator, - buffer: Buffer, - - register_highlighter: proc "c" (extension: cstring, on_color_buffer: OnColorBufferProc), - - register_input_group: proc "c" (input_map: rawptr, key: Key, register_group: InputGroupProc), - register_input: proc "c" (input_map: rawptr, key: Key, input_action: InputActionProc, description: cstring), - - create_window: proc "c" (register_group: InputGroupProc, draw_proc: WindowDrawProc) -> rawptr, - - draw_rect: type_of(raylib.DrawRectangle), -} - load_proc_address :: proc(lib_path: string, library: dynlib.Library, symbol: string, $ProcType: typeid) -> ProcType where intrinsics.type_is_proc(ProcType) { diff --git a/src/ui/buffer_list_window.odin b/src/ui/buffer_list_window.odin deleted file mode 100644 index a3c7aaa..0000000 --- a/src/ui/buffer_list_window.odin +++ /dev/null @@ -1,122 +0,0 @@ -package ui; - -import "core:math" -import "core:path/filepath" -import "vendor:raylib" - -import "../core" -import "../theme" - -BufferListWindow :: struct { - using window: core.Window, - - selected_buffer: int, -} - -create_buffer_list_window :: proc() -> ^BufferListWindow { - input_map := core.new_input_map(); - - core.register_key_action(&input_map, .K, proc(state: ^core.State) { - win := cast(^BufferListWindow)(state.window); - - if win.selected_buffer > 0 { - win.selected_buffer -= 1; - } else { - win.selected_buffer = len(state.buffers)-1; - } - - }, "move selection up"); - core.register_key_action(&input_map, .J, proc(state: ^core.State) { - win := cast(^BufferListWindow)(state.window); - - if win.selected_buffer >= len(state.buffers)-1 { - win.selected_buffer = 0; - } else { - win.selected_buffer += 1; - } - }, "move selection down"); - core.register_key_action(&input_map, .ENTER, proc(state: ^core.State) { - win := cast(^BufferListWindow)(state.window); - - state.current_buffer = win.selected_buffer; - - core.request_window_close(state); - }, "switch to file"); - - core.register_key_action(&input_map, .Q, proc(state: ^core.State) { - core.request_window_close(state); - }, "close window"); - - list_window := new(BufferListWindow); - list_window^ = BufferListWindow { - window = core.Window { - input_map = input_map, - //draw = draw_buffer_list_window, - }, - }; - - return list_window; -} - -draw_buffer_list_window :: proc(win: ^core.Window, state: ^core.State) { - win := cast(^BufferListWindow)(win); - - win_rec := raylib.Rectangle { - x = f32(state.screen_width/8), - y = f32(state.screen_height/8), - width = f32(state.screen_width - state.screen_width/4), - height = f32(state.screen_height - state.screen_height/4), - }; - raylib.DrawRectangleRec( - win_rec, - theme.get_palette_raylib_color(.Background4)); - - win_margin := raylib.Vector2 { f32(state.source_font_width), f32(state.source_font_height) }; - - buffer_prev_width := (win_rec.width - win_margin.x*2) / 2; - buffer_prev_height := win_rec.height - win_margin.y*2; - - glyph_buffer_width := int(buffer_prev_width) / state.source_font_width - 1; - glyph_buffer_height := int(buffer_prev_height) / state.source_font_height; - - raylib.DrawRectangle( - i32(win_rec.x + win_rec.width / 2), - i32(win_rec.y + win_margin.y), - i32(buffer_prev_width), - i32(buffer_prev_height), - theme.get_palette_raylib_color(.Background2)); - - for _, index in state.buffers { - buffer := &state.buffers[index]; - relative_file_path, _ := filepath.rel(state.directory, buffer.file_path) - text := raylib.TextFormat("%s:%d", relative_file_path, buffer.cursor.line+1); - text_width := raylib.MeasureTextEx(state.font, text, f32(state.source_font_height), 0); - - if index == win.selected_buffer { - buffer.glyph_buffer_height = glyph_buffer_height; - buffer.glyph_buffer_width = glyph_buffer_width; - core.draw_file_buffer( - state, - buffer, - int(win_rec.x + win_margin.x + win_rec.width / 2), - int(win_rec.y + win_margin.y), - state.font, - show_line_numbers = false); - - raylib.DrawRectangle( - i32(win_rec.x + win_margin.x), - i32(win_rec.y + win_margin.y) + i32(index * state.source_font_height), - i32(text_width.x), - i32(state.source_font_height), - theme.get_palette_raylib_color(.Background2)); - } - - raylib.DrawTextEx( - state.font, - text, - raylib.Vector2 { win_rec.x + win_margin.x, win_rec.y + win_margin.y + f32(index * state.source_font_height) }, - f32(state.source_font_height), - 0, - theme.get_palette_raylib_color(.Foreground2)); - } -} diff --git a/src/ui/grep_window.odin b/src/ui/grep_window.odin index 1063ed8..7126b50 100644 --- a/src/ui/grep_window.odin +++ b/src/ui/grep_window.odin @@ -162,7 +162,7 @@ create_grep_window :: proc() -> ^GrepWindow { input_map = input_map, //draw = draw_grep_window, get_buffer = grep_window_get_buffer, - free = free_grep_window, + // free_user_data = free_grep_window, }, input_buffer = core.new_virtual_file_buffer(context.allocator),