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