first draft of load/save buttons

akkartik
Nov 26, 2023, 7:36 AM
FIUQJVL2MCC4VKKX7JBT6377TWIGPTUC5NXMUABV5JILB3ZDWZFAC

Dependencies

  • [2] 5MEJ7XNH lay out buttons based on device dimensions
  • [3] ZENSSO3D pass remaining love handlers through
  • [4] 5RUFNRJO start of the visual skeleton
  • [5] VAVXKWZV aggregate global state inside a 'pane' object
  • [6] 6RYGW5H3 bugfix: output border color
  • [*] R5QXEHUI somebody stop me
  • [*] RK2ASPN7 add lots of buttons to the toolbar
  • [*] ZM7NOBRM new fork: carousel shell
  • [*] PRE6XPRN responsively 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.filename
    load_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 = nil
    end
  • 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.filename
    save_to_disk(Current_pane.editor_state)
    -- Don't autosave yet; undo isn't accessible in mobile devices.
    Current_pane.editor_state.filename = nil
    end
  • 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) do
    if file_info.type == 'file' then
    table.insert(Directory_contents, file_info.name)
    end
    end
    table.sort(Directory_contents)
    end
  • file addition: 0122-Directory_contents (----------)
    [8.2]
    -- filenames inside directory
    Directory_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 enabled
    refresh_directory_contents()
    end
    local x, y = Menu_left+10, Menu_bottom+10
    for _,filename in ipairs(Directory_contents) do
    local w = App.width(filename) + 10
    if x == Menu_left+10 or x+w < Safe_width-Menu_left-10 then
    styled_button(filename, x,y, function()
    File_dialog_callback(filename)
    Show_file_dialog = false
    File_dialog_callback = nil
    end)
    x = x+w+10
    else
    x = Menu_left+10
    y = y+Line_height+10
    if y > Safe_height-Menu_bottom-10 then
    break
    end
    end
    end
    end
  • 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 system
    Show_file_dialog = true
    File_dialog_callback = function(filename)
    Current_pane.filename = filename
    one_time_load()
    end
    end)
    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 then
    Directory_contents = nil -- refresh from file system
    Show_file_dialog = true
    File_dialog_callback = function(filename)
    Current_pane.filename = filename
    one_time_save()
    end
    else
    one_time_save()
    end
    end)
    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 name
    Title_font = nil
  • edit in 0021-draw_menu at line 31
    [9.7920]
    [2.4528]
    x, y = save_button(x, y, r)
    x, y = load_button(x, y, r)
  • replacement in 0020-draw_editor_border at line 2
    [4.1173][4.195:220]()
    App.color(Normal_color)
    [4.1173]
    [4.2221]
    App.color{r=0.5, g=0.5, b=0.5}
  • replacement in 0020-draw_editor_border at line 8
    [4.1340][4.1340:1374]()
    love.graphics.line(x1,y1, x2,y1)
    [4.1340]
    [4.1374]
    if Current_pane.filename then
    -- title in between if it exists
    local old_font = love.graphics.getFont()
    if Title_font == nil then
    Title_font = love.graphics.newFont(15) -- 20 pixels between menu and upper border - 5
    end
    love.graphics.setFont(Title_font)
    local tx1 = Current_pane.editor_state.left
    local 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)
    else
    love.graphics.line(x1,y1, x2,y1)
    end
  • edit in 0013-on.keychord_press at line 2
    [10.2800]
    [11.2035]
    if Show_file_dialog then
    Show_file_dialog = false
    return
    end
  • edit in 0012-on.draw at line 3
    [4.4113]
    [2.4963]
    -- modal dialog
    if Show_file_dialog then
    draw_file_dialog()
    return
    end
  • edit in 0011-on.initialize at line 2
    [10.3103]
    [3.333]
    App.mkdir(Directory)