first draft of load/save buttons
Dependencies
- [2]
5MEJ7XNHlay out buttons based on device dimensions - [3]
ZENSSO3Dpass remaining love handlers through - [4]
5RUFNRJOstart of the visual skeleton - [5]
VAVXKWZVaggregate global state inside a 'pane' object - [6]
6RYGW5H3bugfix: output border color - [*]
R5QXEHUIsomebody stop me - [*]
RK2ASPN7add lots of buttons to the toolbar - [*]
ZM7NOBRMnew fork: carousel shell - [*]
PRE6XPRNresponsively increase/decrease font height
Change contents
- file addition: 0127-one_time_load[8.2]
one_time_load = function()print('loading '..Current_pane.filename)Current_pane.editor_state.filename = Directory..Current_pane.filenameload_from_disk(Current_pane.editor_state)Text.redraw_all(Current_pane.editor_state)-- Disable autosave; undo isn't accessible in mobile devices.Current_pane.editor_state.filename = nilend - file addition: 0126-one_time_save[8.2]
one_time_save = function()print('saving to '..Current_pane.filename)Current_pane.editor_state.filename = Directory..Current_pane.filenamesave_to_disk(Current_pane.editor_state)-- Don't autosave yet; undo isn't accessible in mobile devices.Current_pane.editor_state.filename = nilend - file addition: 0125-File_dialog_callback[8.2]
-- Function that is called when a 'filename' is selected from the file dialog, e.g. to load from or save to a file.File_dialog_callback = nil - file addition: 0123-refresh_directory_contents[8.2]
refresh_directory_contents = function()Directory_contents = {}local files_info = nativefs.getDirectoryItemsInfo(Directory)for _,file_info in ipairs(files_info) doif file_info.type == 'file' thentable.insert(Directory_contents, file_info.name)endendtable.sort(Directory_contents)end - file addition: 0122-Directory_contents[8.2]
-- filenames inside directoryDirectory_contents = nil - file addition: 0121-Directory[8.2]
Directory = love.filesystem.getSourceBaseDirectory()..'/carousel_data/' - file addition: 0120-Show_file_dialog[8.2]
Show_file_dialog = false - file addition: 0119-draw_file_dialog[8.2]
draw_file_dialog = function()App.color(Menu_background)love.graphics.rectangle('fill',Menu_left+5,Menu_bottom+5,Safe_width-Menu_left-10,Safe_height-Menu_bottom-10)if Directory_contents == nil then-- on the first frame after dialog is enabledrefresh_directory_contents()endlocal x, y = Menu_left+10, Menu_bottom+10for _,filename in ipairs(Directory_contents) dolocal w = App.width(filename) + 10if x == Menu_left+10 or x+w < Safe_width-Menu_left-10 thenstyled_button(filename, x,y, function()File_dialog_callback(filename)Show_file_dialog = falseFile_dialog_callback = nilend)x = x+w+10elsex = Menu_left+10y = y+Line_height+10if y > Safe_height-Menu_bottom-10 thenbreakendendendend - file addition: 0117-load_button[8.2]
load_button = function(x, y, r)return overflowable_button('load', x, y, r,function()Directory_contents = nil -- refresh from file systemShow_file_dialog = trueFile_dialog_callback = function(filename)Current_pane.filename = filenameone_time_load()endend)end - file addition: 0116-save_button[8.2]
save_button = function(x, y, r)return overflowable_button('save', x, y, r,function()print('save')if Current_pane.filename == nil thenDirectory_contents = nil -- refresh from file systemShow_file_dialog = trueFile_dialog_callback = function(filename)Current_pane.filename = filenameone_time_save()endelseone_time_save()endend)end - file addition: 0115-Title_font[8.2]
-- Lua Carousel is almost entirely in a single (adjustable) font, but we make one exception to squeeze in a file nameTitle_font = nil - edit in 0021-draw_menu at line 31
x, y = save_button(x, y, r)x, y = load_button(x, y, r) - replacement in 0020-draw_editor_border at line 2
App.color(Normal_color)App.color{r=0.5, g=0.5, b=0.5} - replacement in 0020-draw_editor_border at line 8
love.graphics.line(x1,y1, x2,y1)if Current_pane.filename then-- title in between if it existslocal old_font = love.graphics.getFont()if Title_font == nil thenTitle_font = love.graphics.newFont(15) -- 20 pixels between menu and upper border - 5endlove.graphics.setFont(Title_font)local tx1 = Current_pane.editor_state.leftlocal tx2 = tx1 + App.width(Current_pane.filename)love.graphics.print(Current_pane.filename, tx1, y1-15+5)love.graphics.setFont(old_font)love.graphics.line(x1,y1, tx1-5,y1)love.graphics.line(math.min(tx2+5,x2), y1, x2,y1)elselove.graphics.line(x1,y1, x2,y1)end - edit in 0013-on.keychord_press at line 2[10.2800][11.2035]
if Show_file_dialog thenShow_file_dialog = falsereturnend - edit in 0012-on.draw at line 3
-- modal dialogif Show_file_dialog thendraw_file_dialog()returnend - edit in 0011-on.initialize at line 2
App.mkdir(Directory)