diff --git a/src/main.odin b/src/main.odin index 21a0257..6a015cc 100644 --- a/src/main.odin +++ b/src/main.odin @@ -94,61 +94,44 @@ draw :: proc(state: ^State) { panel->render(state) } } + + { + if state.mode != .Insert && state.current_input_map.show_help { + @(thread_local) + layout: ui.UI_Layout + + ui.open_element(new_ui, nil, + { + dir = .TopToBottom, + kind = {ui.Fit{}, ui.Fit{}}, + pos = {state.screen_width - layout.size.x - state.source_font_width, state.screen_height - layout.size.y - state.source_font_height}, + floating = true, + }, + style = { + border = {.Left, .Right, .Top, .Bottom}, + border_color = .Background4, + background_color = .Background3 + } + ) + { + for key, action in state.current_input_map.key_actions { + ui.open_element(new_ui, fmt.tprintf("%s - %s", key, action.description), {}) + ui.close_element(new_ui) + } + for key, action in state.current_input_map.ctrl_key_actions { + ui.open_element(new_ui, fmt.tprintf("-%s - %s", key, action.description), {}) + ui.close_element(new_ui) + } + } + layout = ui.close_element(new_ui) + } + } } ui.close_element(new_ui) ui.compute_layout(new_ui) ui.draw(new_ui, state) - if state.mode != .Insert && state.current_input_map.show_help { - longest_description := 0; - for key, action in state.current_input_map.key_actions { - if len(action.description) > longest_description { - longest_description = len(action.description); - } - } - for key, action in state.current_input_map.ctrl_key_actions { - if len(action.description) > longest_description { - longest_description = len(action.description); - } - } - longest_description += 8; - - helper_height := state.source_font_height * (len(state.current_input_map.key_actions) + len(state.current_input_map.ctrl_key_actions)); - offset_from_bottom := state.source_font_height * 2; - - core.draw_rect( - state, - state.screen_width - longest_description * state.source_font_width, - state.screen_height - helper_height - offset_from_bottom, - longest_description*state.source_font_width, - helper_height, - .Background2 - ); - - index := 0; - for key, action in state.current_input_map.key_actions { - core.draw_text( - state, - fmt.tprintf("%s - %s", key, action.description), - state.screen_width - longest_description * state.source_font_width, - state.screen_height - helper_height + index * state.source_font_height - offset_from_bottom - ); - - index += 1; - } - for key, action in state.current_input_map.ctrl_key_actions { - core.draw_text( - state, - fmt.tprintf("-%s - %s", key, action.description), - state.screen_width - longest_description * state.source_font_width, - state.screen_height - helper_height + index * state.source_font_height - offset_from_bottom - ); - - index += 1; - } - } - sdl2.RenderPresent(state.sdl_renderer); } diff --git a/src/panels/file_buffer.odin b/src/panels/file_buffer.odin index 5ceadcd..3d03e17 100644 --- a/src/panels/file_buffer.odin +++ b/src/panels/file_buffer.odin @@ -269,8 +269,9 @@ file_buffer_input_actions :: proc(input_map: ^core.InputActions) { } }, "Save file") - core.register_key_action(input_map, .G, core.new_input_actions(), "Go commands"); - file_buffer_go_actions(&(&input_map.key_actions[.G]).action.(core.InputActions)); + go_actions := core.new_input_actions(show_help = true) + file_buffer_go_actions(&go_actions); + core.register_key_action(input_map, .G, go_actions, "Go commands"); core.register_key_action(input_map, .V, proc(state: ^core.State, user_data: rawptr) { buffer := &(&(transmute(^core.Panel)user_data).type.(core.FileBufferPanel)).buffer @@ -492,7 +493,7 @@ file_buffer_text_input_actions :: proc(input_map: ^core.InputActions) { // Copy-Paste { { - yank_actions := core.new_input_actions() + yank_actions := core.new_input_actions(show_help = true) defer core.register_key_action(input_map, .Y, yank_actions) core.register_key_action(&yank_actions, .Y, proc(state: ^core.State, user_data: rawptr) { diff --git a/src/ui/ui.odin b/src/ui/ui.odin index 014cd46..ae261ac 100644 --- a/src/ui/ui.odin +++ b/src/ui/ui.odin @@ -193,7 +193,11 @@ close_element :: proc(state: ^State, loc := #caller_location) -> UI_Layout { } } } - case Grow: { /* Done in the Grow pass */ } + case Grow: { + if _, ok := e.parent.?; !ok { + e.layout.size = state.max_size + } + } } state.current_open_element = e.parent @@ -422,22 +426,6 @@ draw :: proc(state: ^State, core_state: ^core.State) { switch v in e.kind { case nil: { - // core.draw_rect( - // core_state, - // e.layout.pos.x, - // e.layout.pos.y, - // e.layout.size.x, - // e.layout.size.y, - // e.style.background_color, - // ); - // core.draw_rect_outline( - // core_state, - // e.layout.pos.x, - // e.layout.pos.y, - // e.layout.size.x, - // e.layout.size.y, - // .Background4 - // ); } case UI_Element_Kind_Text: { core.draw_text(core_state, string(v), e.layout.pos.x, e.layout.pos.y); @@ -449,11 +437,6 @@ draw :: proc(state: ^State, core_state: ^core.State) { v.fn(core_state, e^, v.user_data) } } - } - - // Separate loop done to draw border over elements - for i in 0..