some keyboard shortcuts on non-mobile devices
Hopefully this is easy to remember from left to right: - run is F1 - stop is F2 - hide/show is F3 - save is F4 - load is F5 There are also tooltips to introduce these shortcuts to newcomers. Most of the shortcuts are only enabled when code is visible. In keeping with existing conventions for mouse events, we leave most event handlers for the script when code is hidden. The only exception is 'F3' to show code. So if you want to use a shortcut 'k' when code is hidden, you have to instead use 'F3 k F3'. This is all tentative and open to change. But I'll probably grow more reluctant to change the shortcuts in a few weeks or months.
This commit is contained in:
parent
7232de5b2e
commit
3293f3e139
|
@ -24,4 +24,5 @@ on.draw = function()
|
|||
end
|
||||
draw_menu()
|
||||
draw_next_frames_of_animations()
|
||||
draw_button_tooltips(Global_state)
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
run_button = function(x, y)
|
||||
styled_button('run', x,y, press_run_button)
|
||||
styled_button('run', x,y, press_run_button, not Is_mobile and Show_code and 'F1')
|
||||
local w = Font:getWidth('run')+10
|
||||
return x+w+10, y
|
||||
end
|
|
@ -5,5 +5,8 @@ previous_pane_button = function()
|
|||
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 = press_previous_pane_button,
|
||||
tooltip = function(x,y)
|
||||
show_tooltip(x,y+20, not Is_mobile and Show_code and 'ctrl+left')
|
||||
end,
|
||||
})
|
||||
end
|
|
@ -5,5 +5,9 @@ next_pane_button = function(r)
|
|||
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 = press_next_pane_button,
|
||||
tooltip = function(x,y)
|
||||
local w = App.width('ctrl+right')
|
||||
show_tooltip(x-w-10,y+20, not Is_mobile and Show_code and 'ctrl+right')
|
||||
end,
|
||||
})
|
||||
end
|
|
@ -1,3 +1,3 @@
|
|||
show_code_button = function(x, y, r)
|
||||
return overflowable_button('show', x, y, r, press_show_button)
|
||||
return overflowable_button('show', x, y, r, press_show_button, nil, not Is_mobile and 'F3')
|
||||
end
|
|
@ -1,3 +1,3 @@
|
|||
hide_code_button = function(x, y, r)
|
||||
return overflowable_button('hide', x, y, r, press_hide_button)
|
||||
return overflowable_button('hide', x, y, r, press_hide_button, nil, not Is_mobile and 'F3')
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
stop_button = function(x, y)
|
||||
styled_button('stop', x,y, press_stop_button)
|
||||
styled_button('stop', x,y, press_stop_button, not Is_mobile and Show_code and 'F2')
|
||||
local w = Font:getWidth('stop')+10
|
||||
return x+w+10, y
|
||||
end
|
|
@ -1,3 +1,3 @@
|
|||
save_button = function(x, y, r)
|
||||
return overflowable_button('save', x, y, r, press_save_button)
|
||||
return overflowable_button('save', x, y, r, press_save_button, --[[final button?]] false, not Is_mobile and Show_code and 'F4')
|
||||
end
|
|
@ -1,19 +1,4 @@
|
|||
load_button = function(x, y, r)
|
||||
return overflowable_button('load', x, y, r,
|
||||
function()
|
||||
Show_menu = nil
|
||||
Show_file_dialog = true
|
||||
File_dialog_callback = function(filename)
|
||||
if filename == '' then
|
||||
-- clear filename
|
||||
Current_pane.filename = nil
|
||||
return
|
||||
end
|
||||
Current_pane.filename = filename
|
||||
one_time_load()
|
||||
-- Load new filename in future sessions.
|
||||
-- On mobile devices, we can't depend on on.save_settings() triggering on quit.
|
||||
love.filesystem.write('config', json.encode(settings()))
|
||||
end
|
||||
end)
|
||||
press_load_button, --[[final button?]] false, not Is_mobile and Show_code and 'F5')
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
-- draw a button in the menu if possible
|
||||
-- if not, stash it behind an overflow ('>>') button
|
||||
overflowable_button = function(name, x, y, r, onpress1, final_button)
|
||||
overflowable_button = function(name, x, y, r, onpress1, final_button, tooltip_text)
|
||||
local w = Font:getWidth(name)+10
|
||||
local x2, y2 = maybe_draw_overflow_button(x, y, w, r, final_button)
|
||||
if Overflow_button then
|
||||
|
@ -11,10 +11,10 @@ overflowable_button = function(name, x, y, r, onpress1, final_button)
|
|||
y = y2
|
||||
end
|
||||
end
|
||||
styled_button(name, x,y, onpress1)
|
||||
styled_button(name, x,y, onpress1, tooltip_text)
|
||||
if Overflow_button then
|
||||
return x, y+Line_height
|
||||
else
|
||||
return x+w+10, y
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
styled_button = function(name, x, y, onpress1)
|
||||
styled_button = function(name, x, y, onpress1, tooltip_text)
|
||||
local w = Font:getWidth(name)+10
|
||||
button(Global_state, name, {x=x, y=y, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
|
||||
icon = function(p)
|
||||
|
@ -17,5 +17,8 @@ styled_button = function(name, x, y, onpress1)
|
|||
expire=Current_time+0.1,
|
||||
}
|
||||
end,
|
||||
tooltip = function(x,y)
|
||||
show_tooltip(x,y+20, tooltip_text)
|
||||
end,
|
||||
})
|
||||
end
|
||||
end
|
|
@ -1,5 +1,6 @@
|
|||
press_next_pane_button = function()
|
||||
Show_menu = nil
|
||||
if Current_pane_index >= #Panes then return end
|
||||
Current_pane.car = car
|
||||
Current_pane_index = Current_pane_index+1
|
||||
Current_pane = Panes[Current_pane_index]
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
press_previous_pane_button = function()
|
||||
Show_menu = nil
|
||||
if Current_pane_index <=1 then return end
|
||||
Current_pane.car = car
|
||||
Current_pane_index = Current_pane_index-1
|
||||
Current_pane = Panes[Current_pane_index]
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Tooltip_background = {r=0.8, g=0.8, b=0.8}
|
|
@ -0,0 +1 @@
|
|||
Tooltip_foreground = {r=0, g=0, b=0}
|
|
@ -0,0 +1 @@
|
|||
Is_mobile = (OS == 'Android' or OS == 'iOS')
|
|
@ -0,0 +1,8 @@
|
|||
show_tooltip = function(x,y, tooltip_text)
|
||||
if not tooltip_text then return end
|
||||
App.color(Tooltip_background)
|
||||
local w = App.width(tooltip_text)
|
||||
love.graphics.rectangle('fill', x,y, w+10, Line_height+10, 2,2)
|
||||
App.color(Tooltip_foreground)
|
||||
love.graphics.print(tooltip_text, x+5, y+5)
|
||||
end
|
12
button.lua
12
button.lua
|
@ -33,3 +33,15 @@ function mouse_press_consumed_by_any_button(State, x, y, mouse_button)
|
|||
end
|
||||
return button_pressed and consume_press
|
||||
end
|
||||
|
||||
function draw_button_tooltips(State)
|
||||
if App.mouse_down(1) then return end
|
||||
local x,y = love.mouse.getPosition()
|
||||
for _,ev in ipairs(State.button_handlers) do
|
||||
if ev.tooltip then
|
||||
if x>ev.x and x<ev.x+ev.w and y>ev.y and y<ev.y+ev.h then
|
||||
ev.tooltip(x,y)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue