close all menus when tapping any button

I think I'm least likely to break something if I do this as explicitly
as possible rather than trying to figure out the right helper to put it
in once and for all. So just add some boilerplate to reset all state at
the start of each onpress1 handler. This seems like a good choice since
we aren't planning to add a lot more menus that would quadratically
explode the boilerplate.
This commit is contained in:
Kartik K. Agaram 2023-12-04 21:34:39 -08:00
parent 8e17a56232
commit e93d43253d
16 changed files with 38 additions and 8 deletions

View File

@ -1,6 +1,8 @@
run_button = function(x, y)
styled_button('run', x,y,
function()
Show_overflow = false
Show_settings = false
-- ## run: initialize
clear_handlers()
local buf = table.concat(map(Current_pane.editor_state.lines, function(line) return line.data end), '\n')

View File

@ -5,6 +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 = function()
Show_overflow = false
Show_settings = false
Current_pane.car = car
Current_pane_index = Current_pane_index-1
Current_pane = Panes[Current_pane_index]

View File

@ -5,6 +5,8 @@ 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 = function()
Show_overflow = false
Show_settings = false
Current_pane.car = car
Current_pane_index = Current_pane_index+1
Current_pane = Panes[Current_pane_index]

View File

@ -1,6 +1,8 @@
new_pane_button = function(x, y, r)
return overflowable_button('new', x, y, r,
function()
Show_overflow = false
Show_settings = false
Current_pane_index = Current_pane_index+1
table.insert(Panes, Current_pane_index, new_pane())
Current_pane = Panes[Current_pane_index]

View File

@ -1,6 +1,8 @@
show_code_button = function(x, y, r)
return overflowable_button('show', x, y, r,
function()
Show_overflow = false
Show_settings = false
Show_code = true
end)
end

View File

@ -1,6 +1,8 @@
hide_code_button = function(x, y, r)
return overflowable_button('hide', x, y, r,
function()
Show_overflow = false
Show_settings = false
Show_code = false
end)
end

View File

@ -1,6 +1,8 @@
copy_button = function(x, y, r)
return overflowable_button('copy', x, y, r,
function()
Show_overflow = false
Show_settings = false
local e = Current_pane.editor_state
local s = Text.selection(e)
if s == nil then

View File

@ -1,6 +1,8 @@
paste_button = function(x, y, r)
return overflowable_button('paste', x, y, r,
function()
Show_overflow = false
Show_settings = false
local state = Current_pane.editor_state
-- initial state for recording undo operation
local before_line = state.cursor1.line
@ -17,4 +19,4 @@ paste_button = function(x, y, r)
state.cursor1.line)
})
end)
end
end

View File

@ -1,8 +1,8 @@
settings_button = function(x)
return right_justified_button('settings', x, Menu_top+5,
function()
Show_overflow = false
Show_settings = not Show_settings
if Show_settings then Show_overflow = false end
if not Show_settings then
-- On mobile devices, we can't depend on on.save_settings() triggering on quit
love.filesystem.write('config', json.encode(settings()))

View File

@ -1,4 +1,8 @@
clear_pane_button = function(x, y, r)
return overflowable_button('clear', x, y, r,
clear_pane)
function()
Show_overflow = false
Show_settings = false
clear_pane()
end)
end

View File

@ -1,6 +1,8 @@
delete_pane_button = function(x, y, r)
return overflowable_button('delete', x, y, r,
function()
Show_overflow = false
Show_settings = false
if Current_pane.example_name then
Deleted_example_panes[Current_pane.example_name] = true
end
@ -14,4 +16,4 @@ delete_pane_button = function(x, y, r)
Current_pane = Panes[Current_pane_index]
end,
--[[final button]] true)
end
end

View File

@ -1,5 +1,10 @@
stop_button = function(x, y)
styled_button('stop', x,y, clear_handlers)
styled_button('stop', x,y,
function()
Show_overflow = false
Show_settings = false
clear_handlers()
end)
local w = App.width('stop')+10
return x+w+10, y
end

View File

@ -1,8 +1,8 @@
overflow_button = function(x, y)
styled_button('>>', x,y,
function()
Show_settings = false
Show_overflow = not Show_overflow
if Show_overflow then Show_settings = false end
end)
return x, y+Line_height
end

View File

@ -1,7 +1,8 @@
save_button = function(x, y, r)
return overflowable_button('save', x, y, r,
function()
print('save')
Show_overflow = false
Show_settings = false
if Current_pane.filename == nil then
Show_file_dialog = true
File_dialog_callback = function(filename)

View File

@ -1,6 +1,8 @@
load_button = function(x, y, r)
return overflowable_button('load', x, y, r,
function()
Show_overflow = false
Show_settings = false
Show_file_dialog = true
File_dialog_callback = function(filename)
if filename == '' then

View File

@ -18,4 +18,4 @@ styled_button = function(name, x, y, onpress1)
}
end,
})
end
end