simplify state management for menus
This commit is contained in:
parent
e93d43253d
commit
966f8a15bf
|
@ -6,13 +6,12 @@ on.mouse_press = function(x,y, mouse_button)
|
|||
Button_pressed = true
|
||||
return
|
||||
end
|
||||
Show_overflow = false
|
||||
-- == settings area
|
||||
if Show_settings then
|
||||
if Show_menu == 'settings' then
|
||||
if on_area(Settings_menu_area, x,y) then
|
||||
select_settings_slider(x,y, mouse_button)
|
||||
else
|
||||
Show_settings = false
|
||||
Show_menu = nil
|
||||
-- On mobile devices, we can't depend on on.save_settings() triggering on quit.
|
||||
-- So save settings every time we close the settings menu.
|
||||
love.filesystem.write('config', json.encode(settings()))
|
||||
|
@ -20,6 +19,7 @@ on.mouse_press = function(x,y, mouse_button)
|
|||
return
|
||||
end
|
||||
-- == main area
|
||||
Show_menu = nil
|
||||
if Show_code then
|
||||
if on_editor_scrollbar(Current_pane.editor_state, x,y) then
|
||||
Current_pane.editor_state.scrollbar_drag = true
|
||||
|
|
|
@ -6,7 +6,7 @@ on.mouse_release = function(x,y, mouse_button)
|
|||
return
|
||||
end
|
||||
-- == settings area
|
||||
if Show_settings then
|
||||
if Show_menu == 'settings' then
|
||||
if on_area(Settings_menu_area, x,y) then
|
||||
return
|
||||
end
|
||||
|
|
|
@ -49,7 +49,7 @@ draw_menu = function()
|
|||
if Current_pane_index < #Panes then
|
||||
next_pane_button(Menu_left + Safe_width)
|
||||
end
|
||||
if Show_settings then
|
||||
if Show_menu == 'settings' then
|
||||
draw_settings_menu()
|
||||
end
|
||||
end
|
|
@ -1,8 +1,7 @@
|
|||
run_button = function(x, y)
|
||||
styled_button('run', x,y,
|
||||
function()
|
||||
Show_overflow = false
|
||||
Show_settings = false
|
||||
Show_menu = nil
|
||||
-- ## run: initialize
|
||||
clear_handlers()
|
||||
local buf = table.concat(map(Current_pane.editor_state.lines, function(line) return line.data end), '\n')
|
||||
|
|
|
@ -5,8 +5,7 @@ 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
|
||||
Show_menu = nil
|
||||
Current_pane.car = car
|
||||
Current_pane_index = Current_pane_index-1
|
||||
Current_pane = Panes[Current_pane_index]
|
||||
|
|
|
@ -5,8 +5,7 @@ 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
|
||||
Show_menu = nil
|
||||
Current_pane.car = car
|
||||
Current_pane_index = Current_pane_index+1
|
||||
Current_pane = Panes[Current_pane_index]
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
new_pane_button = function(x, y, r)
|
||||
return overflowable_button('new', x, y, r,
|
||||
function()
|
||||
Show_overflow = false
|
||||
Show_settings = false
|
||||
Show_menu = nil
|
||||
Current_pane_index = Current_pane_index+1
|
||||
table.insert(Panes, Current_pane_index, new_pane())
|
||||
Current_pane = Panes[Current_pane_index]
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
show_code_button = function(x, y, r)
|
||||
return overflowable_button('show', x, y, r,
|
||||
function()
|
||||
Show_overflow = false
|
||||
Show_settings = false
|
||||
Show_menu = nil
|
||||
Show_code = true
|
||||
end)
|
||||
end
|
|
@ -1,8 +1,7 @@
|
|||
hide_code_button = function(x, y, r)
|
||||
return overflowable_button('hide', x, y, r,
|
||||
function()
|
||||
Show_overflow = false
|
||||
Show_settings = false
|
||||
Show_menu = nil
|
||||
Show_code = false
|
||||
end)
|
||||
end
|
|
@ -1,8 +1,7 @@
|
|||
copy_button = function(x, y, r)
|
||||
return overflowable_button('copy', x, y, r,
|
||||
function()
|
||||
Show_overflow = false
|
||||
Show_settings = false
|
||||
Show_menu = nil
|
||||
local e = Current_pane.editor_state
|
||||
local s = Text.selection(e)
|
||||
if s == nil then
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
paste_button = function(x, y, r)
|
||||
return overflowable_button('paste', x, y, r,
|
||||
function()
|
||||
Show_overflow = false
|
||||
Show_settings = false
|
||||
Show_menu = nil
|
||||
local state = Current_pane.editor_state
|
||||
-- initial state for recording undo operation
|
||||
local before_line = state.cursor1.line
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
settings_button = function(x)
|
||||
return right_justified_button('settings', x, Menu_top+5,
|
||||
function()
|
||||
Show_overflow = false
|
||||
Show_settings = not Show_settings
|
||||
if not Show_settings then
|
||||
if Show_menu == 'settings' then
|
||||
Show_menu = nil
|
||||
-- On mobile devices, we can't depend on on.save_settings() triggering on quit
|
||||
love.filesystem.write('config', json.encode(settings()))
|
||||
else
|
||||
Show_menu = 'settings'
|
||||
end
|
||||
end)
|
||||
end
|
|
@ -1,8 +1,7 @@
|
|||
clear_pane_button = function(x, y, r)
|
||||
return overflowable_button('clear', x, y, r,
|
||||
function()
|
||||
Show_overflow = false
|
||||
Show_settings = false
|
||||
Show_menu = nil
|
||||
clear_pane()
|
||||
end)
|
||||
end
|
|
@ -1,8 +1,7 @@
|
|||
delete_pane_button = function(x, y, r)
|
||||
return overflowable_button('delete', x, y, r,
|
||||
function()
|
||||
Show_overflow = false
|
||||
Show_settings = false
|
||||
Show_menu = nil
|
||||
if Current_pane.example_name then
|
||||
Deleted_example_panes[Current_pane.example_name] = true
|
||||
end
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Show_menu = nil
|
|
@ -1 +0,0 @@
|
|||
Show_settings =false
|
|
@ -1,5 +1,4 @@
|
|||
update_any_sliders = function(x,y)
|
||||
if not Show_settings then return end
|
||||
if Selected_slider == Settings_font_slider.name then
|
||||
update_font_settings(slider_value(Settings_font_slider, x))
|
||||
return true
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
select_settings_slider = function(x,y, mouse_button)
|
||||
if not Show_settings then return end
|
||||
local result = false
|
||||
if on_slider(Settings_font_slider, x,y) then
|
||||
Selected_slider = Settings_font_slider.name
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
stop_button = function(x, y)
|
||||
styled_button('stop', x,y,
|
||||
function()
|
||||
Show_overflow = false
|
||||
Show_settings = false
|
||||
Show_menu = nil
|
||||
clear_handlers()
|
||||
end)
|
||||
local w = App.width('stop')+10
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
-- True if the overflow menu has been opened and we want to render buttons within it.
|
||||
Show_overflow = false
|
|
@ -1,8 +1,11 @@
|
|||
overflow_button = function(x, y)
|
||||
styled_button('>>', x,y,
|
||||
function()
|
||||
Show_settings = false
|
||||
Show_overflow = not Show_overflow
|
||||
if Show_menu == 'overflow' then
|
||||
Show_menu = nil
|
||||
else
|
||||
Show_menu = 'overflow'
|
||||
end
|
||||
end)
|
||||
return x, y+Line_height
|
||||
end
|
|
@ -1,8 +1,7 @@
|
|||
save_button = function(x, y, r)
|
||||
return overflowable_button('save', x, y, r,
|
||||
function()
|
||||
Show_overflow = false
|
||||
Show_settings = false
|
||||
Show_menu = nil
|
||||
if Current_pane.filename == nil then
|
||||
Show_file_dialog = true
|
||||
File_dialog_callback = function(filename)
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
load_button = function(x, y, r)
|
||||
return overflowable_button('load', x, y, r,
|
||||
function()
|
||||
Show_overflow = false
|
||||
Show_settings = false
|
||||
Show_menu = nil
|
||||
Show_file_dialog = true
|
||||
File_dialog_callback = function(filename)
|
||||
if filename == '' then
|
||||
|
|
|
@ -5,7 +5,7 @@ overflowable_button = function(name, x, y, r, onpress1, final_button)
|
|||
local x2, y2 = maybe_draw_overflow_button(x, y, w, r, final_button)
|
||||
if Overflow_button then
|
||||
-- overflow
|
||||
if not Show_overflow then
|
||||
if Show_menu ~= 'overflow' then
|
||||
return x, y
|
||||
else
|
||||
y = y2
|
||||
|
|
Loading…
Reference in New Issue