~akkartik/carousel.love

56268f09a4b6a0d49e025429266a53ddcd16dc74 — Kartik K. Agaram 4 months ago e81d371
add keyboard shortcuts for common operations
M 0013-on.keychord_press => 0013-on.keychord_press +10 -1
@@ 9,8 9,17 @@ 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 not Show_code and chord == 'f3' then
		press_show_button()
	elseif Show_code then
		if Current_pane.editor_state.cursor_x then
		if 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)
		end

M 0051-run_button => 0051-run_button +2 -28
@@ 1,31 1,5 @@
run_button = function(x, y)
	styled_button('run', x,y,
		function()
			Show_menu = nil
			-- ## run: initialize
			clear_handlers()
			local buf = table.concat(map(Current_pane.editor_state.lines, function(line) return line.data end), '\n')
			Current_pane.canvas = love.graphics.newCanvas()
			love.graphics.setCanvas(Current_pane.canvas)
			love.graphics.push('all')
			love.graphics.setBackgroundColor(1,1,1)
			edit.clear(Current_pane.output_editor_state)
			print = print_to_output
			-- ## run
			local status, result = live.eval(buf, 'editor')
			-- ## run: save some stuff, clean up the rest
			print = Real_print
			if result then
				-- could be either output or error
				table.insert(Current_pane.output_editor_state.lines, {data=tostring(result)})
			end
			if #Current_pane.output_editor_state.lines == 0 then
				table.insert(Current_pane.output_editor_state.lines, {data=''})
			end
			Text.redraw_all(Current_pane.output_editor_state)
			love.graphics.pop()
			love.graphics.setCanvas()
		end)
	styled_button('run', x,y, press_run_button)
	local w = Font:getWidth('run')+10
	return x+w+10, y
end
end
\ No newline at end of file

M 0059-previous_pane_button => 0059-previous_pane_button +2 -8
@@ 4,12 4,6 @@ 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.car = car
			Current_pane_index = Current_pane_index-1
			Current_pane = Panes[Current_pane_index]
			car = Current_pane.car or {}
		end,
		onpress1 = press_previous_pane_button,
	})
end
end
\ No newline at end of file

M 0060-next_pane_button => 0060-next_pane_button +2 -8
@@ 4,12 4,6 @@ next_pane_button = function(r)
			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.car = car
			Current_pane_index = Current_pane_index+1
			Current_pane = Panes[Current_pane_index]
			car = Current_pane.car or {}
		end,
		onpress1 = press_next_pane_button,
	})
end
end
\ No newline at end of file

M 0064-show_code_button => 0064-show_code_button +2 -6
@@ 1,7 1,3 @@
show_code_button = function(x, y, r)
	return overflowable_button('show', x, y, r,
		function()
			Show_menu = nil
			Show_code = true
		end)
end
	return overflowable_button('show', x, y, r, press_show_button)
end
\ No newline at end of file

M 0065-hide_code_button => 0065-hide_code_button +2 -6
@@ 1,7 1,3 @@
hide_code_button = function(x, y, r)
	return overflowable_button('hide', x, y, r,
		function()
			Show_menu = nil
			Show_code = false
		end)
end
	return overflowable_button('hide', x, y, r, press_hide_button)
end
\ No newline at end of file

M 0106-stop_button => 0106-stop_button +2 -9
@@ 1,12 1,5 @@
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)
	styled_button('stop', x,y, press_stop_button)
	local w = Font:getWidth('stop')+10
	return x+w+10, y
end
end
\ No newline at end of file

M 0116-save_button => 0116-save_button +1 -17
@@ 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)
end
\ No newline at end of file

A 0161-press_run_button => 0161-press_run_button +26 -0
@@ 0,0 1,26 @@
press_run_button = function()
	Show_menu = nil
	-- ## run: initialize
	clear_handlers()
	local buf = table.concat(map(Current_pane.editor_state.lines, function(line) return line.data end), '\n')
	Current_pane.canvas = love.graphics.newCanvas()
	love.graphics.setCanvas(Current_pane.canvas)
	love.graphics.push('all')
	love.graphics.setBackgroundColor(1,1,1)
	edit.clear(Current_pane.output_editor_state)
	print = print_to_output
	-- ## run
	local status, result = live.eval(buf, 'editor')
	-- ## run: save some stuff, clean up the rest
	print = Real_print
	if result then
		-- could be either output or error
		table.insert(Current_pane.output_editor_state.lines, {data=tostring(result)})
	end
	if #Current_pane.output_editor_state.lines == 0 then
		table.insert(Current_pane.output_editor_state.lines, {data=''})
	end
	Text.redraw_all(Current_pane.output_editor_state)
	love.graphics.pop()
	love.graphics.setCanvas()
end
\ No newline at end of file

A 0162-press_stop_button => 0162-press_stop_button +7 -0
@@ 0,0 1,7 @@
press_stop_button = function()
	if car.quit then
		call_protected(car.quit)
	end
	Show_menu = nil
	clear_handlers()
end
\ No newline at end of file

A 0163-press_show_button => 0163-press_show_button +4 -0
@@ 0,0 1,4 @@
press_show_button = function()
	Show_menu = nil
	Show_code = true
end
\ No newline at end of file

A 0164-press_hide_button => 0164-press_hide_button +4 -0
@@ 0,0 1,4 @@
press_hide_button = function()
	Show_menu = nil
	Show_code = false
end
\ No newline at end of file

A 0165-press_save_button => 0165-press_save_button +16 -0
@@ 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
\ No newline at end of file

A 0166-press_load_button => 0166-press_load_button +16 -0
@@ 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
\ No newline at end of file

A 0167-press_next_pane_button => 0167-press_next_pane_button +7 -0
@@ 0,0 1,7 @@
press_next_pane_button = function()
	Show_menu = nil
	Current_pane.car = car
	Current_pane_index = Current_pane_index+1
	Current_pane = Panes[Current_pane_index]
	car = Current_pane.car or {}
end
\ No newline at end of file

A 0168-press_previous_pane_button => 0168-press_previous_pane_button +7 -0
@@ 0,0 1,7 @@
press_previous_pane_button = function()
	Show_menu = nil
	Current_pane.car = car
	Current_pane_index = Current_pane_index-1
	Current_pane = Panes[Current_pane_index]
	car = Current_pane.car or {}
end
\ No newline at end of file