From f580e2efca19776192b2c86b30fea76b10ba22bc Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 20 Nov 2023 22:23:09 -0800 Subject: [PATCH] add lots of buttons to the toolbar --- 0012-on.draw | 16 +++++----- 0021-draw_menu | 63 ++++++++++---------------------------- 0049-new_pane | 15 ++------- 0051-run_button | 2 +- 0059-previous_pane_button | 12 ++++++++ 0060-next_pane_button | 12 ++++++++ 0061-new_pane_button | 16 ++++++++++ 0063-Show_code | 1 + 0064-show_code_button | 14 +++++++++ 0065-hide_code_button | 14 +++++++++ 0066-copy_button | 15 +++++++++ 0067-paste_button | 15 +++++++++ 0068-copy_editor | 14 +++++++++ 0069-output_editor_state | 9 ++++++ 0070-code_editor_state | 10 ++++++ 0071-duplicate_pane_button | 20 ++++++++++++ 0072-settings_button | 13 ++++++++ 0074-clear_pane_button | 12 ++++++++ 0075-clear_pane | 6 ++++ 0076-delete_pane_button | 21 +++++++++++++ edit.lua | 20 +++++++----- 21 files changed, 244 insertions(+), 76 deletions(-) create mode 100644 0059-previous_pane_button create mode 100644 0060-next_pane_button create mode 100644 0061-new_pane_button create mode 100644 0063-Show_code create mode 100644 0064-show_code_button create mode 100644 0065-hide_code_button create mode 100644 0066-copy_button create mode 100644 0067-paste_button create mode 100644 0068-copy_editor create mode 100644 0069-output_editor_state create mode 100644 0070-code_editor_state create mode 100644 0071-duplicate_pane_button create mode 100644 0072-settings_button create mode 100644 0074-clear_pane_button create mode 100644 0075-clear_pane create mode 100644 0076-delete_pane_button diff --git a/0012-on.draw b/0012-on.draw index 2fef5d5..1172467 100644 --- a/0012-on.draw +++ b/0012-on.draw @@ -1,14 +1,14 @@ on.draw = function() Global_state.button_handlers = {} draw_canvas() - --if Canvas then return end - draw_editor_border() --- love.graphics.rectangle('line', 100-5-Line_number_padding,100-5, 300+Line_number_padding+10, 200+10, 5,5) - edit.draw(Current_pane.editor_state, --[[fg]] nil, --[[hide_cursor]] nil, --[[show_line_numbers]] true) - draw_scrollbar(Current_pane.editor_state) - draw_output_border() - edit.draw(Current_pane.output_editor_state, Normal_color, --[[hide cursor]] true) - draw_scrollbar(Current_pane.output_editor_state) + if Show_code then + draw_editor_border() + edit.draw(Current_pane.editor_state, --[[fg]] nil, --[[hide_cursor]] nil, --[[show_line_numbers]] true) + draw_scrollbar(Current_pane.editor_state) + draw_output_border() + edit.draw(Current_pane.output_editor_state, Normal_color, --[[hide cursor]] true) + draw_scrollbar(Current_pane.output_editor_state) + end draw_menu() draw_next_frames_of_animations() end \ No newline at end of file diff --git a/0021-draw_menu b/0021-draw_menu index d9c4082..e8c8771 100644 --- a/0021-draw_menu +++ b/0021-draw_menu @@ -3,58 +3,29 @@ draw_menu = function() love.graphics.rectangle('fill', 0,0, App.screen.width, Menu_bottom) App.color(Normal_color) local x = Menu_left+5 - love.graphics.print(Current_pane_index, x, Menu_top+5) - x = x + App.width(tostring(Current_pane_index)) + 5 + love.graphics.print(Current_pane_index, x+5, Menu_top+5+2) + x = x+5 + App.width(tostring(Current_pane_index)) + 10 -- main buttons x = run_button(x) + if Show_code then + x = hide_code_button(x) + else + x = show_code_button(x) + end + x = copy_button(x) + x = paste_button(x) + x = new_pane_button(x) + x = duplicate_pane_button(x) + x = clear_pane_button(x) + x = delete_pane_button(x) -- settings button on right local w = App.width('settings') - button(Global_state, 'settings', {x=Safe_width-w-10-5, y=Menu_top+5, w=w+10, h=Line_height, bg={r=0.6, g=0.8, b=0.6}, - icon = function(p) - App.color(Normal_color) - love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2) - love.graphics.print('settings', p.x+5,p.y+2) - end, - onpress1 = function() - print('settings') - end, - }) + settings_button(Safe_width-w-10-5, w) -- nav buttons along sides if Current_pane_index > 1 then - button(Global_state, 'left', {x=0, y=Menu_bottom, w=Menu_left+30, h=App.screen.height, bg={r=0.5, g=0.5, b=0.5, a=0.2}, - icon = function(p) - App.color{r=0.4,g=0.4,b=0.4} - love.graphics.polygon('fill', Menu_left+5, App.screen.height/2, Menu_left+25, App.screen.height/2-10, Menu_left+25, App.screen.height/2+10) - end, - onpress1 = function() - Current_pane_index = Current_pane_index-1 - Current_pane = Panes[Current_pane_index] - end, - }) + previous_pane_button() end - local r = Menu_left + Safe_width - if Current_pane_index == #Panes then - button(Global_state, 'right', {x=r-30, y=Menu_bottom, w=100, h=App.screen.height, bg={r=0.5, g=0.5, b=0.5, a=0.2}, - icon = function(p) - App.color{r=0.4,g=0.4,b=0.4} - love.graphics.print('+', r-25, App.screen.height/2-10) - end, - onpress1 = function() - table.insert(Panes, new_pane()) - Current_pane_index = Current_pane_index+1 - Current_pane = Panes[Current_pane_index] - end, - }) - else - button(Global_state, 'right', {x=r-30, y=Menu_bottom, w=100, h=App.screen.height, bg={r=0.5, g=0.5, b=0.5, a=0.2}, - icon = function(p) - App.color{r=0.4,g=0.4,b=0.4} - love.graphics.polygon('fill', r-25, App.screen.height/2-10, r-25, App.screen.height/2+10, r-5, App.screen.height/2) - end, - onpress1 = function() - Current_pane_index = Current_pane_index+1 - Current_pane = Panes[Current_pane_index] - end, - }) + if Current_pane_index < #Panes then + next_pane_button(Menu_left + Safe_width) end end \ No newline at end of file diff --git a/0049-new_pane b/0049-new_pane index 65240ee..fa5d7d0 100644 --- a/0049-new_pane +++ b/0049-new_pane @@ -1,17 +1,6 @@ new_pane = function() local result = {} - result.editor_state = edit.initialize_state( - Menu_bottom + 20, -- top - Safe_height/2-Line_height, -- bottom - Menu_left + 50 + Line_number_padding, -- left - math.min(100+30*App.width('m'), Safe_width*2/3), -- right - love.graphics.getFont():getHeight(), Line_height) - Text.redraw_all(result.editor_state) - result.output_editor_state = edit.initialize_state( - result.editor_state.bottom+5+10+5, -- top - nil, -- buttom - result.editor_state.left, result.editor_state.right, - love.graphics.getFont():getHeight(), Line_height) - Text.redraw_all(result.output_editor_state) + result.editor_state = code_editor_state() + result.output_editor_state = output_editor_state(result.editor_state) return result end \ No newline at end of file diff --git a/0051-run_button b/0051-run_button index 69e65d6..0862c2b 100644 --- a/0051-run_button +++ b/0051-run_button @@ -35,5 +35,5 @@ run_button = function(x) love.graphics.setCanvas() end, }) - return x+w + return x+w+10 end \ No newline at end of file diff --git a/0059-previous_pane_button b/0059-previous_pane_button new file mode 100644 index 0000000..b9030b4 --- /dev/null +++ b/0059-previous_pane_button @@ -0,0 +1,12 @@ +previous_pane_button = function() + button(Global_state, 'previous_pane', {x=0, y=Menu_bottom, w=Menu_left+30, h=App.screen.height, bg={r=0.5, g=0.5, b=0.5, a=0.2}, + icon = function(p) + App.color{r=0.4,g=0.4,b=0.4} + love.graphics.polygon('fill', Menu_left+5, App.screen.height/2, Menu_left+25, App.screen.height/2-10, Menu_left+25, App.screen.height/2+10) + end, + onpress1 = function() + Current_pane_index = Current_pane_index-1 + Current_pane = Panes[Current_pane_index] + end, + }) +end \ No newline at end of file diff --git a/0060-next_pane_button b/0060-next_pane_button new file mode 100644 index 0000000..bb0125b --- /dev/null +++ b/0060-next_pane_button @@ -0,0 +1,12 @@ +next_pane_button = function(r) + button(Global_state, 'right', {x=r-30, y=Menu_bottom, w=100, h=App.screen.height, bg={r=0.5, g=0.5, b=0.5, a=0.2}, + icon = function(p) + App.color{r=0.4,g=0.4,b=0.4} + love.graphics.polygon('fill', r-25, App.screen.height/2-10, r-25, App.screen.height/2+10, r-5, App.screen.height/2) + end, + onpress1 = function() + Current_pane_index = Current_pane_index+1 + Current_pane = Panes[Current_pane_index] + end, + }) +end \ No newline at end of file diff --git a/0061-new_pane_button b/0061-new_pane_button new file mode 100644 index 0000000..6c7015c --- /dev/null +++ b/0061-new_pane_button @@ -0,0 +1,16 @@ +new_pane_button = function(x) + local w = App.width('new')+10 + button(Global_state, 'new', {x=x, y=Menu_top+5, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6}, + icon = function(p) + App.color(Normal_color) + love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2) + love.graphics.print('new', p.x+5,p.y+2) + end, + onpress1 = function() + Current_pane_index = Current_pane_index+1 + table.insert(Panes, Current_pane_index, new_pane()) + Current_pane = Panes[Current_pane_index] + end, + }) + return x+w+10 +end \ No newline at end of file diff --git a/0063-Show_code b/0063-Show_code new file mode 100644 index 0000000..1eb62c5 --- /dev/null +++ b/0063-Show_code @@ -0,0 +1 @@ +Show_code = true \ No newline at end of file diff --git a/0064-show_code_button b/0064-show_code_button new file mode 100644 index 0000000..6b27230 --- /dev/null +++ b/0064-show_code_button @@ -0,0 +1,14 @@ +show_code_button = function(x) + local w = App.width('show')+10 + button(Global_state, 'show', {x=x, y=Menu_top+5, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6}, + icon = function(p) + App.color(Normal_color) + love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2) + love.graphics.print('show', p.x+5,p.y+2) + end, + onpress1 = function() + Show_code = true + end, + }) + return x+w+10 +end \ No newline at end of file diff --git a/0065-hide_code_button b/0065-hide_code_button new file mode 100644 index 0000000..0db6e7e --- /dev/null +++ b/0065-hide_code_button @@ -0,0 +1,14 @@ +hide_code_button = function(x) + local w = App.width('hide')+10 + button(Global_state, 'hide', {x=x, y=Menu_top+5, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6}, + icon = function(p) + App.color(Normal_color) + love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2) + love.graphics.print('hide', p.x+5,p.y+2) + end, + onpress1 = function() + Show_code = false + end, + }) + return x+w+10 +end \ No newline at end of file diff --git a/0066-copy_button b/0066-copy_button new file mode 100644 index 0000000..7b570a6 --- /dev/null +++ b/0066-copy_button @@ -0,0 +1,15 @@ +copy_button = function(x) + local w = App.width('copy')+10 + button(Global_state, 'copy', {x=x, y=Menu_top+5, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6}, + icon = function(p) + App.color(Normal_color) + love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2) + love.graphics.print('copy', p.x+5,p.y+2) + end, + onpress1 = function() + local s = Text.selection(Current_pane.editor_state) + if s then App.set_clipboard(s) end + end, + }) + return x+w+10 +end \ No newline at end of file diff --git a/0067-paste_button b/0067-paste_button new file mode 100644 index 0000000..0f14943 --- /dev/null +++ b/0067-paste_button @@ -0,0 +1,15 @@ +paste_button = function(x) + local w = App.width('paste')+10 + button(Global_state, 'paste', {x=x, y=Menu_top+5, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6}, + icon = function(p) + App.color(Normal_color) + love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2) + love.graphics.print('paste', p.x+5,p.y+2) + end, + onpress1 = function() + local s = App.get_clipboard() + Text.insert_text(Current_pane.editor_state, s) + end, + }) + return x+w+10 +end \ No newline at end of file diff --git a/0068-copy_editor b/0068-copy_editor new file mode 100644 index 0000000..05c6eb1 --- /dev/null +++ b/0068-copy_editor @@ -0,0 +1,14 @@ +copy_editor = function(state) + local new_state = edit.initialize_state( + Menu_bottom + 20, -- top + Safe_height/2-Line_height, -- bottom + Menu_left + 50 + Line_number_padding, -- left + math.min(100+30*App.width('m'), Safe_width*2/3), -- right + love.graphics.getFont():getHeight(), Line_height) + new_state.lines = map(state.lines, + function(line) + return {data=line.data} + end) + Text.redraw_all(new_state) + return new_state +end \ No newline at end of file diff --git a/0069-output_editor_state b/0069-output_editor_state new file mode 100644 index 0000000..b33b51d --- /dev/null +++ b/0069-output_editor_state @@ -0,0 +1,9 @@ +output_editor_state = function(editor_state) + local result = edit.initialize_state( + editor_state.bottom+5+10+5, -- top + nil, -- buttom + editor_state.left, editor_state.right, + love.graphics.getFont():getHeight(), Line_height) + Text.redraw_all(result) + return result +end \ No newline at end of file diff --git a/0070-code_editor_state b/0070-code_editor_state new file mode 100644 index 0000000..dfb64b0 --- /dev/null +++ b/0070-code_editor_state @@ -0,0 +1,10 @@ +code_editor_state = function() + local result = edit.initialize_state( + Menu_bottom + 20, -- top + Safe_height/2-Line_height, -- bottom + Menu_left + 50 + Line_number_padding, -- left + math.min(100+30*App.width('m'), Safe_width*2/3), -- right + love.graphics.getFont():getHeight(), Line_height) + Text.redraw_all(result) + return result +end \ No newline at end of file diff --git a/0071-duplicate_pane_button b/0071-duplicate_pane_button new file mode 100644 index 0000000..c19e613 --- /dev/null +++ b/0071-duplicate_pane_button @@ -0,0 +1,20 @@ +duplicate_pane_button = function(x) + local w = App.width('dup')+10 + button(Global_state, 'duplicate', {x=x, y=Menu_top+5, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6}, + icon = function(p) + App.color(Normal_color) + love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2) + love.graphics.print('dup', p.x+5,p.y+2) + end, + onpress1 = function() + local new_pane = { + editor_state = copy_editor(Current_pane.editor_state) + } + new_pane.output_editor_state = output_editor_state(new_pane.editor_state) + Current_pane_index = Current_pane_index+1 + table.insert(Panes, Current_pane_index, new_pane) + Current_pane = Panes[Current_pane_index] + end, + }) + return x+w+10 +end \ No newline at end of file diff --git a/0072-settings_button b/0072-settings_button new file mode 100644 index 0000000..4f4bcd9 --- /dev/null +++ b/0072-settings_button @@ -0,0 +1,13 @@ +settings_button = function(x, w) + button(Global_state, 'settings', {x=x, y=Menu_top+5, w=w+10, h=Line_height, bg={r=0.6, g=0.8, b=0.6}, + icon = function(p) + App.color(Normal_color) + love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2) + love.graphics.print('settings', p.x+5,p.y+2) + end, + onpress1 = function() + print('settings') + end, + }) + return x+w+10 +end \ No newline at end of file diff --git a/0074-clear_pane_button b/0074-clear_pane_button new file mode 100644 index 0000000..b3a2e97 --- /dev/null +++ b/0074-clear_pane_button @@ -0,0 +1,12 @@ +clear_pane_button = function(x) + local w = App.width('clear')+10 + button(Global_state, 'clear', {x=x, y=Menu_top+5, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6}, + icon = function(p) + App.color(Normal_color) + love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2) + love.graphics.print('clear', p.x+5,p.y+2) + end, + onpress1 = clear_pane, + }) + return x+w+10 +end \ No newline at end of file diff --git a/0075-clear_pane b/0075-clear_pane new file mode 100644 index 0000000..a59346e --- /dev/null +++ b/0075-clear_pane @@ -0,0 +1,6 @@ +clear_pane = function() + Current_pane.editor_state.lines = {{data=''}} + Current_pane.editor_state.screen_top1 = {line=1, pos=1} + Current_pane.editor_state.cursor1 = {line=1, pos=1} + Text.redraw_all(Current_pane.editor_state) +end \ No newline at end of file diff --git a/0076-delete_pane_button b/0076-delete_pane_button new file mode 100644 index 0000000..e257714 --- /dev/null +++ b/0076-delete_pane_button @@ -0,0 +1,21 @@ +delete_pane_button = function(x) + local w = App.width('delete')+10 + button(Global_state, 'delete', {x=x, y=Menu_top+5, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6}, + icon = function(p) + App.color(Normal_color) + love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2) + love.graphics.print('delete', p.x+5,p.y+2) + end, + onpress1 = function() + table.remove(Panes, Current_pane_index) + if #Panes == 0 then + table.insert(Panes, new_pane()) + end + if Current_pane_index > #Panes then + Current_pane_index = Current_pane_index-1 + end + Current_pane = Panes[Current_pane_index] + end, + }) + return x+w+10 +end \ No newline at end of file diff --git a/edit.lua b/edit.lua index a6aa46a..67f1548 100644 --- a/edit.lua +++ b/edit.lua @@ -369,14 +369,7 @@ function edit.keychord_press(State, chord, key, readonly) local before_line = State.cursor1.line local before = snapshot(State, before_line) local clipboard_data = App.get_clipboard() - for _,code in utf8.codes(clipboard_data) do - local c = utf8.char(code) - if c == '\n' then - Text.insert_return(State) - else - Text.insert_at_cursor(State, c) - end - end + Text.insert_text(State, clipboard_data) if Text.cursor_out_of_screen(State) then Text.snap_cursor_to_bottom_of_screen(State, State.left, State.right) end @@ -389,6 +382,17 @@ function edit.keychord_press(State, chord, key, readonly) end end +function Text.insert_text(State, d) + for _,code in utf8.codes(d) do + local c = utf8.char(code) + if c == '\n' then + Text.insert_return(State) + else + Text.insert_at_cursor(State, c) + end + end +end + function edit.key_release(State, key, scancode) end