switch all handlers to run either the app or editor

This commit is contained in:
Kartik K. Agaram 2023-12-31 16:21:21 -08:00
parent 347d863a9d
commit fdc84789fc
13 changed files with 115 additions and 161 deletions

View File

@ -1,16 +1,19 @@
on.update = function(dt)
refresh_debug_animations()
-- == menu area
if Active_button and Active_button.expire <= Current_time then
Active_button = nil
if not Show_code then
if car.update then call_protected(car.update, dt) end
else
-- == menu area
if Active_button and Active_button.expire <= Current_time then
Active_button = nil
end
-- == settings area
update_sliders(Global_state, App.mouse_x())
-- == main area
if Current_pane.editor_state.scrollbar_drag then
adjust_scrollbar(Current_pane.editor_state, App.mouse_y())
elseif Current_pane.output_editor_state.scrollbar_drag then
adjust_scrollbar(Current_pane.output_editor_state, App.mouse_y())
end
end
-- == settings area
update_sliders(Global_state, App.mouse_x())
-- == main area
if Current_pane.editor_state.scrollbar_drag then
adjust_scrollbar(Current_pane.editor_state, App.mouse_y())
elseif Current_pane.output_editor_state.scrollbar_drag then
adjust_scrollbar(Current_pane.output_editor_state, App.mouse_y())
end
if car.update then call_protected(car.update, dt) end
end

View File

@ -1,26 +1,30 @@
on.draw = function()
Global_state.button_handlers = {}
Global_state.slider_handlers = {}
-- modal dialog
if Show_file_dialog then
draw_file_dialog()
return
end
Overflow_button = nil
love.graphics.setBackgroundColor(Background_color.r, Background_color.g, Background_color.b)
App.color(Foreground_color)
if car.draw then call_protected(car.draw) end
love.graphics.setFont(Font)
App.color(Normal_color)
love.graphics.setLineWidth(1)
if Show_code then
if not Show_code then
if car.draw then call_protected(car.draw) end
else
-- modal dialog
if Show_file_dialog then
draw_file_dialog()
return
end
Overflow_button = nil
love.graphics.setBackgroundColor(Background_color.r, Background_color.g, Background_color.b)
App.color(Foreground_color)
-- code editor
love.graphics.setFont(Font)
App.color(Normal_color)
love.graphics.setLineWidth(1)
draw_editor_border()
edit.draw(Current_pane.editor_state, --[[implicitly use Foreground_color]] nil, --[[hide_cursor]] nil, --[[show_line_numbers]] true)
draw_scrollbar(Current_pane.editor_state)
-- output
draw_output_border()
edit.draw(Current_pane.output_editor_state, Foreground_color, --[[hide cursor]] true)
draw_scrollbar(Current_pane.output_editor_state)
-- menu and debug UI
draw_menu()
draw_next_frames_of_animations()
end
draw_menu()
draw_next_frames_of_animations()
end

View File

@ -1,21 +1,22 @@
on.keychord_press = function(chord, key)
if Show_file_dialog then
keychord_press_on_file_dialog(chord, key)
return
end
if chord == 'C-=' then
update_font_settings(Current_pane.editor_state.font_height+2)
elseif chord == 'C--' then
update_font_settings(Current_pane.editor_state.font_height-2)
elseif chord == 'C-0' then
update_font_settings(20)
elseif Show_code then
if Current_pane.editor_state.cursor_x then
-- send keys to editor if cursor is visible
edit.keychord_press(Current_pane.editor_state, chord, key)
if Show_code then
if Show_file_dialog then
keychord_press_on_file_dialog(chord, key)
return
end
if chord == 'C-=' then
update_font_settings(Current_pane.editor_state.font_height+2)
elseif chord == 'C--' then
update_font_settings(Current_pane.editor_state.font_height-2)
elseif chord == 'C-0' then
update_font_settings(20)
else
if Current_pane.editor_state.cursor_x then
-- send keys to editor if cursor is visible
edit.keychord_press(Current_pane.editor_state, chord, key)
end
end
else
-- editors hidden
if car.keychord_press then
call_protected(car.keychord_press, chord, key)
end

View File

@ -1,12 +1,11 @@
on.text_input = function(t)
if Show_file_dialog then
text_input_on_file_dialog(t)
elseif Show_code then
if Current_pane.editor_state.cursor_x then
if Show_code then
if Show_file_dialog then
text_input_on_file_dialog(t)
elseif Current_pane.editor_state.cursor_x then
edit.text_input(Current_pane.editor_state, t)
end
else
-- editors hidden
if car.text_input then
call_protected(car.text_input, t)
end

View File

@ -4,7 +4,6 @@ on.key_release = function(key, scancode)
edit.key_release(Current_pane.editor_state, key, scancode)
end
else
-- editors hidden
if car.key_release then
call_protected(car.key_release, key, scancode)
end

View File

@ -1,29 +1,36 @@
on.mouse_press = function(x,y, mouse_button)
-- == menu area
-- some hysteresis right after a button has been pressed
if Active_button then return end
if mouse_press_consumed_by_any_button(Global_state, x,y, mouse_button) then
Button_pressed = true
return
end
-- == settings area
if mouse_press_consumed_by_any_slider(Global_state, x,y) then
return
end
if Show_menu == 'settings' then
if on_area(Settings_menu_area, x,y) then
-- nothing atm in settings menu that isn't a button or slider
else
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()))
if not Show_code then
if car.mouse_press then
call_protected(car.mouse_press, x,y, mouse_button)
end
return
end
-- == main area
Show_menu = nil
if Show_code then
if car.mousepressed then
call_protected(car.mousepressed, x,y, mouse_button)
end
else
-- == menu area
-- some hysteresis right after a button has been pressed
if Active_button then return end
if mouse_press_consumed_by_any_button(Global_state, x,y, mouse_button) then
Button_pressed = true
return
end
-- == settings area
if mouse_press_consumed_by_any_slider(Global_state, x,y) then
return
end
if Show_menu == 'settings' then
if on_area(Settings_menu_area, x,y) then
-- nothing atm in settings menu that isn't a button or slider
else
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()))
end
return
end
-- == main area
Show_menu = nil
if on_editor_scrollbar(Current_pane.editor_state, x,y) then
Current_pane.editor_state.scrollbar_drag = true
local sbtopy = compute_scrollbar_topy(Current_pane.editor_state)
@ -40,13 +47,5 @@ on.mouse_press = function(x,y, mouse_button)
elseif on_editor_scrollbar_area(Current_pane.output_editor_state, x,y) then
-- nothing
end
else
-- editors hidden
if car.mouse_press then
call_protected(car.mouse_press, x,y, mouse_button)
end
if car.mousepressed then
call_protected(car.mousepressed, x,y, mouse_button)
end
end
end
end

View File

@ -1,18 +1,25 @@
on.mouse_release = function(x,y, mouse_button)
-- == menu area
if Button_pressed then
Button_pressed = nil
return
end
-- == settings area
Global_state.selected_slider = nil
if Show_menu == 'settings' then
if on_area(Settings_menu_area, x,y) then
if not Show_code then
if car.mouse_release then
call_protected(car.mouse_release, x,y, mouse_button)
end
if car.mousereleased then
call_protected(car.mousereleased, x,y, mouse_button)
end
else
-- == menu area
if Button_pressed then
Button_pressed = nil
return
end
end
-- == main area
if Show_code then
-- == settings area
Global_state.selected_slider = nil
if Show_menu == 'settings' then
if on_area(Settings_menu_area, x,y) then
return
end
end
-- == main area
if Current_pane.editor_state.scrollbar_drag then
adjust_scrollbar(Current_pane.editor_state, y)
Current_pane.editor_state.scrollbar_drag = nil
@ -28,13 +35,5 @@ on.mouse_release = function(x,y, mouse_button)
elseif on_editor_scrollbar_area(Current_pane.output_editor_state, x,y) then
adjust_scrollbar(Current_pane.output_editor_state, y)
end
else
-- editors hidden
if car.mouse_release then
call_protected(car.mouse_release, x,y, mouse_button)
end
if car.mousereleased then
call_protected(car.mousereleased, x,y, mouse_button)
end
end
end

View File

@ -11,36 +11,10 @@ draw_menu = function()
App.color(Normal_color)
x = x+5 + App.width(tostring(Current_pane_index)) + 10
x = run_button(x, y)
x = stop_button(x, y)
-- assume screen will always be wide enough to print this far without overflow
if not Overflow_button then
local w = App.width('code')+10
local w2 = App.width('>>')+10
if x+w+10+w2+10 < r then
App.color{r=0.5, g=0.5, b=0.5}
love.graphics.print('code', x, y)
x = x+w+10
end
end
if Show_code then
x, y = hide_code_button(x, y, r)
else
x, y = show_code_button(x, y, r)
end
x, y = save_button(x, y, r)
x, y = load_button(x, y, r)
x, y = copy_button(x, y, r)
x, y = paste_button(x, y, r)
x, y = clear_pane_button(x, y, r)
if not Overflow_button then
local w = App.width('screen')+10
local w2 = App.width('>>')+10
if x+w+10+w2+10 < r then
App.color{r=0.5, g=0.5, b=0.5}
love.graphics.print('screen', x, y)
x = x+w+10
end
end
x, y = new_pane_button(x, y, r)
x, y = delete_pane_button(x, y, r)
-- nav buttons along sides

View File

@ -1,7 +0,0 @@
show_code_button = function(x, y, r)
return overflowable_button('show', x, y, r,
function()
Show_menu = nil
Show_code = true
end)
end

View File

@ -1,7 +0,0 @@
hide_code_button = function(x, y, r)
return overflowable_button('hide', x, y, r,
function()
Show_menu = nil
Show_code = false
end)
end

View File

@ -1,17 +1,16 @@
on.mouse_wheel_move = function(dx,dy)
if Show_code then
if App.mouse_y() < Current_pane.editor_state.bottom then
edit.mouse_wheel_move(Current_pane.editor_state, dx,dy)
else
edit.mouse_wheel_move(Current_pane.output_editor_state, dx,dy)
end
else
-- editors hidden
if not Show_code then
if car.mouse_wheel_move then
call_protected(car.mouse_wheel_move, dx,dy)
end
if car.wheelmoved then
call_protected(car.wheelmoved, dx,dy)
end
else
if App.mouse_y() < Current_pane.editor_state.bottom then
edit.mouse_wheel_move(Current_pane.editor_state, dx,dy)
else
edit.mouse_wheel_move(Current_pane.output_editor_state, dx,dy)
end
end
end

View File

@ -1,12 +0,0 @@
stop_button = function(x, y)
styled_button('stop', x,y,
function()
if car.quit then
call_protected(car.quit)
end
Show_menu = nil
clear_handlers()
end)
local w = App.width('stop')+10
return x+w+10, y
end

3
0158-on.quit Normal file
View File

@ -0,0 +1,3 @@
on.quit = function()
call_protected(car.quit)
end