diff --git a/src/core/gfx.odin b/src/core/gfx.odin index 9957324..9d121f8 100644 --- a/src/core/gfx.odin +++ b/src/core/gfx.odin @@ -107,6 +107,13 @@ free_font_atlas :: proc(font_atlas: FontAtlas) { } } +draw_line :: proc(state: ^State, x1,y1,x2,y2: int, color: theme.PaletteColor) { + color := theme.get_palette_color(color) + + sdl2.SetRenderDrawColor(state.sdl_renderer, color.r, color.g, color.b, color.a) + sdl2.RenderDrawLine(state.sdl_renderer, i32(x1), i32(y1), i32(x2), i32(y2)) +} + draw_rect_outline :: proc(state: ^State, x,y,w,h: int, color: theme.PaletteColor) { color := theme.get_palette_color(color); diff --git a/src/panels/panels.odin b/src/panels/panels.odin index d383bbf..7496940 100644 --- a/src/panels/panels.odin +++ b/src/panels/panels.odin @@ -63,7 +63,7 @@ register_default_leader_actions :: proc(input_map: ^core.InputActions) { }, "close this help"); core.register_key_action(input_map, .R, proc(state: ^core.State) { - open(state, make_grep_panel(state)) + open_grep_panel(state) }, "Grep Workspace") } @@ -163,19 +163,39 @@ render_file_buffer :: proc(state: ^core.State, s: ^ui.State, buffer: ^core.FileB 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, nil, + { + dir = .TopToBottom, + kind = {ui.Grow{}, ui.Grow{}}, + }, + style = { + border = {.Left, .Right, .Top, .Bottom}, + border_color = .Background4, + background_color = .Background1, + } + ) { - ui.open_element(s, ui.UI_Element_Kind_Custom{fn = draw_func, user_data = transmute(rawptr)buffer}, { - 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{}} + }, + style = { + border = {.Left, .Right, .Top, .Bottom}, + border_color = .Background4, + background_color = .Background1, + } + ) ui.close_element(s) ui.open_element(s, nil, { kind = {ui.Grow{}, ui.Exact(state.source_font_height)} - }) + }, + style = { + border = {.Left, .Right, .Top, .Bottom}, + border_color = .Background4, + } + ) { ui.open_element(s, fmt.tprintf("%s", state.mode), {}) ui.close_element(s) @@ -274,6 +294,13 @@ make_file_buffer_panel :: proc(buffer_index: int) -> core.Panel { } } +open_grep_panel :: proc(state: ^core.State) { + open(state, make_grep_panel(state)) + + state.mode = .Insert + sdl2.StartTextInput() +} + make_grep_panel :: proc(state: ^core.State) -> core.Panel { query_arena: mem.Arena mem.arena_init(&query_arena, make([]u8, 1024*1024*2, state.ctx.allocator)) @@ -419,10 +446,16 @@ make_grep_panel :: proc(state: ^core.State) -> core.Panel { { if panel_state.query_results != nil { // query results - query_result_container := ui.open_element(s, nil, { - dir = .TopToBottom, - kind = {ui.Grow{}, ui.Grow{}} - }) + query_result_container := ui.open_element(s, nil, + { + dir = .TopToBottom, + kind = {ui.Grow{}, ui.Grow{}} + }, + style = { + border = {.Left, .Right, .Top, .Bottom}, + border_color = .Background4 + } + ) { container_height := query_result_container.layout.size.y max_results := container_height / 16 @@ -442,14 +475,15 @@ make_grep_panel :: proc(state: ^core.State) -> core.Panel { ui.open_element(s, fmt.tprintf("%v:%v: ", result.line, result.col), {}) ui.close_element(s) - // TODO: when styling is implemented, make this look better + + style := ui.UI_Style{} + if panel_state.selected_result == i { - ui.open_element(s, fmt.tprintf("%s <--", result.file_path), {}) - ui.close_element(s) - } else { - ui.open_element(s, result.file_path, {}) - ui.close_element(s) + style.background_color = .Background2 } + + ui.open_element(s, result.file_path, {}, style) + ui.close_element(s) } } } diff --git a/src/ui/ui.odin b/src/ui/ui.odin index 66ce8d8..933a462 100644 --- a/src/ui/ui.odin +++ b/src/ui/ui.odin @@ -26,6 +26,7 @@ UI_Element :: struct { kind: UI_Element_Kind, layout: UI_Layout, + style: UI_Style, } UI_Element_Kind :: union { @@ -59,6 +60,15 @@ Exact :: distinct i32 Grow :: struct {} Fit :: struct {} +UI_Style :: struct { + border: UI_Border_Set, + + border_color: theme.PaletteColor, + background_color: theme.PaletteColor, +} +UI_Border_Set :: bit_set[UI_Border] +UI_Border :: enum{Left, Right, Top, Bottom} + UI_Direction :: enum { LeftToRight, RightToLeft, @@ -66,10 +76,11 @@ UI_Direction :: enum { BottomToTop, } -open_element :: proc(state: ^State, kind: UI_Element_Kind, layout: UI_Layout) -> UI_Element { +open_element :: proc(state: ^State, kind: UI_Element_Kind, layout: UI_Layout, style: UI_Style = {}) -> UI_Element { e := UI_Element { kind = kind, layout = layout, + style = style, } e.layout.pos = state.curr_elements[state.num_curr].layout.pos e.layout.size = state.curr_elements[state.num_curr].layout.size @@ -108,7 +119,7 @@ close_element :: proc(state: ^State, loc := #caller_location) -> UI_Layout { switch v in e.kind { case UI_Element_Kind_Text: { // FIXME: properly use font size - e.layout.size.x = len(v) * 10 + e.layout.size.x = len(v) * 12 } case UI_Element_Kind_Image: { // TODO @@ -354,24 +365,33 @@ draw :: proc(state: ^State, core_state: ^core.State) { for i in 0..