Merge carousel.love

This commit is contained in:
Kartik K. Agaram 2024-02-25 00:26:08 -08:00
commit e04ea8590b
27 changed files with 136 additions and 64 deletions

View File

@ -26,5 +26,6 @@ on.draw = function()
-- menu and debug UI
draw_menu()
draw_next_frames_of_animations()
draw_button_tooltips(Global_state)
end
end
end

View File

@ -10,6 +10,16 @@ on.keychord_press = function(chord, key)
update_font_settings(Current_pane.editor_state.font_height-2)
elseif chord == 'C-0' then
update_font_settings(20)
elseif chord == 'C-left' then press_previous_pane_button()
elseif chord == 'C-right' then press_next_pane_button()
elseif chord == 'f1' then press_run_button()
elseif chord == 'f2' then press_stop_button()
elseif chord == 'f3' then press_hide_button()
elseif chord == 'f4' then press_save_button()
elseif chord == 'f5' then press_load_button()
elseif Current_pane.editor_state.cursor_x then
-- send keys to editor if cursor is visible
edit.keychord_press(Current_pane.editor_state, chord, key)
else
if Current_pane.editor_state.cursor_x then
-- send keys to editor if cursor is visible
@ -17,11 +27,13 @@ on.keychord_press = function(chord, key)
end
end
else
if car.keychord_press then
if chord == 'f3' then
press_show_button()
elseif car.keychord_press then
call_protected(car.keychord_press, chord, key)
end
if car.keypressed then
call_protected(car.keypressed, key)
end
end
end
end

View File

@ -1,12 +1,12 @@
on.resize = function(w, h)
_, _, Safe_width, Safe_height = love.window.getSafeArea()
for _,pane in ipairs(Panes) do
pane.editor_state.right = math.min(100+30*pane.editor_state.font:getWidth('m'), Safe_width*2/3)
pane.editor_state.right = editor_right_margin()
if pane.editor_state.right < pane.editor_state.left then
pane.editor_state.right = pane.editor_state.left+1
end
pane.editor_state.width = pane.editor_state.right - pane.editor_state.left
pane.editor_state.bottom = Safe_height/2-Line_height
pane.editor_state.bottom = code_editor_bottom_margin()
Text.redraw_all(pane.editor_state)
update_output_editor(pane)
end

View File

@ -13,7 +13,7 @@ update_font_settings = function(font_height)
for _,pane in ipairs(Panes) do
pane.editor_state.top = Menu_bottom + 20
pane.editor_state.left = Menu_left + 50 + Line_number_padding
pane.editor_state.right = math.min(100+30*Font:getWidth('m'), Safe_width*2/3)
pane.editor_state.right = editor_right_margin()
if pane.editor_state.right < pane.editor_state.left then
pane.editor_state.right = pane.editor_state.left+1
end

View File

@ -1,9 +1,5 @@
run_button = function(x, y)
styled_button('run', x,y,
function()
Show_menu = nil
run_app()
end)
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

View File

@ -4,10 +4,9 @@ previous_pane_button = function()
App.color{r=0.4,g=0.4,b=0.4}
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_menu = nil
Current_pane_index = Current_pane_index-1
Current_pane = Panes[Current_pane_index]
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
end

View File

@ -1,13 +1,13 @@
next_pane_button = function(r)
button(Global_state, 'right', {x=r-30, y=Menu_bottom, w=100, h=App.screen.height, bg={r=0.5, g=0.5, b=0.5, a=0.2},
button(Global_state, 'right', {x=r-30, y=Menu_bottom, w=30, h=App.screen.height, bg={r=0.5, g=0.5, b=0.5, a=0.2},
icon = function(p)
App.color{r=0.4,g=0.4,b=0.4}
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_menu = nil
Current_pane_index = Current_pane_index+1
Current_pane = Panes[Current_pane_index]
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
end

View File

@ -1,10 +1,10 @@
code_editor_state = function()
local result = edit.initialize_state(
Menu_bottom + 20, -- top
Safe_height/2-Line_height, -- bottom
code_editor_bottom_margin(),
Menu_left + 50 + Line_number_padding, -- left
math.min(100+30*Font:getWidth('m'), Safe_width*2/3), -- right
editor_right_margin(),
Font, Font_height, Line_height)
Text.redraw_all(result)
return result
end
end

View File

@ -1,19 +1,3 @@
save_button = function(x, y, r)
return overflowable_button('save', x, y, r,
function()
Show_menu = nil
if Current_pane.filename == nil then
Show_file_dialog = true
File_dialog_callback = function(filename)
if filename == '' then return end
Current_pane.filename = filename
one_time_save()
-- 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
else
one_time_save()
end
end)
return overflowable_button('save', x, y, r, press_save_button, --[[final button?]] false, not Is_mobile and Show_code and 'F4')
end

View File

@ -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

View File

@ -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

View File

@ -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

4
0161-press_run_button Normal file
View File

@ -0,0 +1,4 @@
press_run_button = function()
Show_menu = nil
run_app()
end

7
0162-press_stop_button Normal file
View File

@ -0,0 +1,7 @@
press_stop_button = function()
if car.quit then
call_protected(car.quit)
end
Show_menu = nil
clear_handlers()
end

4
0163-press_show_button Normal file
View File

@ -0,0 +1,4 @@
press_show_button = function()
Show_menu = nil
Show_code = true
end

4
0164-press_hide_button Normal file
View File

@ -0,0 +1,4 @@
press_hide_button = function()
Show_menu = nil
Show_code = false
end

16
0165-press_save_button Normal file
View File

@ -0,0 +1,16 @@
press_save_button = function()
Show_menu = nil
if Current_pane.filename == nil then
Show_file_dialog = true
File_dialog_callback = function(filename)
if filename == '' then return end
Current_pane.filename = filename
one_time_save()
-- 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
else
one_time_save()
end
end

16
0166-press_load_button Normal file
View File

@ -0,0 +1,16 @@
press_load_button = 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

View File

@ -0,0 +1,6 @@
press_next_pane_button = function()
Show_menu = nil
if Current_pane_index >= #Panes then return end
Current_pane_index = Current_pane_index+1
Current_pane = Panes[Current_pane_index]
end

View File

@ -0,0 +1,6 @@
press_previous_pane_button = function()
Show_menu = nil
if Current_pane_index <=1 then return end
Current_pane_index = Current_pane_index-1
Current_pane = Panes[Current_pane_index]
end

3
0169-editor_right_margin Normal file
View File

@ -0,0 +1,3 @@
editor_right_margin = function()
return math.min(100+30*Font:getWidth('m'), Safe_width*2/3)
end

View File

@ -0,0 +1,3 @@
code_editor_bottom_margin = function()
return Safe_height/2-Line_height
end

1
0172-Tooltip_background Normal file
View File

@ -0,0 +1 @@
Tooltip_background = {r=0.8, g=0.8, b=0.8}

1
0173-Tooltip_foreground Normal file
View File

@ -0,0 +1 @@
Tooltip_foreground = {r=0, g=0, b=0}

1
0174-Is_mobile Normal file
View File

@ -0,0 +1 @@
Is_mobile = (OS == 'Android' or OS == 'iOS')

8
0175-show_tooltip Normal file
View File

@ -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

View File

@ -22,7 +22,7 @@ function mouse_press_consumed_by_any_button(State, x, y, mouse_button)
local button_pressed = false
local consume_press = true
for _,ev in ipairs(State.button_handlers) do
if x>ev.x and x<ev.x+ev.w and y>ev.y and y<ev.y+ev.h then
if x>ev.x and x<ev.x+ev.w-1 and y>ev.y and y<ev.y+ev.h-1 then
if ev.onpress1 and mouse_button == 1 then
button_pressed = true
if ev.onpress1() then
@ -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-1 and y>ev.y and y<ev.y+ev.h-1 then
ev.tooltip(x,y)
end
end
end
end