add lots of buttons to the toolbar
This commit is contained in:
parent
e5e6193184
commit
f580e2efca
|
@ -1,14 +1,14 @@
|
|||
on.draw = function()
|
||||
Global_state.button_handlers = {}
|
||||
draw_canvas()
|
||||
--if Canvas then return end
|
||||
if Show_code then
|
||||
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)
|
||||
end
|
||||
draw_menu()
|
||||
draw_next_frames_of_animations()
|
||||
end
|
|
@ -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
|
|
@ -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
|
|
@ -35,5 +35,5 @@ run_button = function(x)
|
|||
love.graphics.setCanvas()
|
||||
end,
|
||||
})
|
||||
return x+w
|
||||
return x+w+10
|
||||
end
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -0,0 +1 @@
|
|||
Show_code = true
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
20
edit.lua
20
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
|
||||
|
||||
|
|
Loading…
Reference in New Issue