extract a helper for buttons

akkartik
Nov 26, 2023, 5:11 AM
SIJ5I4NZN5LFATNT5QIWUK75Z5W6P4B4AKNPVYFQ7IVRMOCVWR3AC

Dependencies

  • [2] VQYLKEGD handle still narrower screens on phones
  • [3] 6MQCFHXM remember when someone deletes an example
  • [4] X2YWEIZS bugfix: missing variable in a button
  • [5] YCPA257V copy entire buffer when there's no selection
  • [6] 5MEJ7XNH lay out buttons based on device dimensions
  • [7] QGSOEM7Z bugfix: 'show' button layout
  • [8] RK2ASPN7 add lots of buttons to the toolbar
  • [*] R5QXEHUI somebody stop me

Change contents

  • file addition: 0118-overflowable_button (----------)
    [10.2]
    overflowable_button = function(name, x, y, r, onpress1)
    local w = App.width(name)+10
    local x2, y2 = maybe_draw_overflow_button(x, y, w, r)
    if Overflow_button then
    -- overflow
    if not Show_overflow then
    return x, y
    else
    y = y2
    end
    end
    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)
    App.color(Normal_color)
    love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
    love.graphics.print(name, p.x+5,p.y+2)
    end,
    onpress1 = onpress1,
    })
    if Overflow_button then
    return x, y+Line_height
    else
    return x+w+10, y
    end
    end
  • replacement in 0076-delete_pane_button at line 2
    [6.1536][6.35:69](),[6.35][6.35:69](),[6.69][6.1537:1812](),[6.1812][6.167:350](),[6.167][6.167:350]()
    local w = App.width('delete')+10
    local x2, y2 = maybe_draw_overflow_button(x, y, w, r, --[[final button]] true)
    if Overflow_button then
    -- overflow
    if Show_overflow then
    y = y2
    else
    return x, y
    end
    end
    button(Global_state, 'delete', {x=x, y=y, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
    icon = function(p)
    App.color(Normal_color)
    love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
    love.graphics.print('delete', p.x+5,p.y+2)
    end,
    onpress1 = function()
    [6.1536]
    [3.779]
    return overflowable_button('delete', x, y, r,
    function()
  • replacement in 0076-delete_pane_button at line 15
    [6.595][6.595:606](),[6.606][6.1813:1894]()
    end,
    })
    if Overflow_button then
    return x, y+Line_height
    else
    return x+w+10, y
    end
    [6.595]
    [6.621]
    end)
  • replacement in 0074-clear_pane_button at line 2
    [6.1935][6.978:1011](),[6.978][6.978:1011](),[6.1011][6.1936:2189](),[6.2189][6.1108:1295](),[6.1108][6.1108:1295](),[6.1295][6.2190:2271]()
    local w = App.width('clear')+10
    local x2, y2 = maybe_draw_overflow_button(x, y, w, r)
    if Overflow_button then
    -- overflow
    if not Show_overflow then
    return x, y
    else
    y = y2
    end
    end
    button(Global_state, 'clear', {x=x, y=y, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
    icon = function(p)
    App.color(Normal_color)
    love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
    love.graphics.print('clear', p.x+5,p.y+2)
    end,
    onpress1 = clear_pane,
    })
    if Overflow_button then
    return x, y+Line_height
    else
    return x+w+10, y
    end
    [6.1935]
    [6.1310]
    return overflowable_button('clear', x, y, r,
    clear_pane)
  • replacement in 0067-paste_button at line 2
    [6.2311][6.3759:3792](),[6.3759][6.3759:3792](),[6.3792][6.2312:2565](),[6.2565][6.3889:4071](),[6.3889][6.3889:4071]()
    local w = App.width('paste')+10
    local x2, y2 = maybe_draw_overflow_button(x, y, w, r)
    if Overflow_button then
    -- overflow
    if not Show_overflow then
    return x, y
    else
    y = y2
    end
    end
    button(Global_state, 'paste', {x=x, y=y, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
    icon = function(p)
    App.color(Normal_color)
    love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
    love.graphics.print('paste', p.x+5,p.y+2)
    end,
    onpress1 = function()
    [6.2311]
    [6.4071]
    return overflowable_button('paste', x, y, r,
    function()
  • replacement in 0067-paste_button at line 6
    [6.4154][6.4154:4165](),[6.4165][6.2566:2707]()
    end,
    })
    if Overflow_button then
    -- we're past the overflow button; start drawing downward
    return x, y+Line_height
    else
    return x+w+10, y
    end
    [6.4154]
    [6.4180]
    end)
  • replacement in 0066-copy_button at line 2
    [6.2741][6.4254:4286](),[6.4254][6.4254:4286](),[6.4286][6.2742:2879](),[6.2879][2.0:17](),[2.17][6.2879:2977](),[6.2879][6.2879:2977](),[6.2977][6.4382:4563](),[6.4382][6.4382:4563]()
    local w = App.width('copy')+10
    local x2, y2 = maybe_draw_overflow_button(x, y, w, r)
    if Overflow_button then
    -- overflow
    if not Show_overflow then
    return x, y
    else
    y = y2
    end
    end
    button(Global_state, 'copy', {x=x, y=y, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
    icon = function(p)
    App.color(Normal_color)
    love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
    love.graphics.print('copy', p.x+5,p.y+2)
    end,
    onpress1 = function()
    [6.2741]
    [5.71]
    return overflowable_button('copy', x, y, r,
    function()
  • replacement in 0066-copy_button at line 14
    [5.424][6.4656:4667](),[6.4656][6.4656:4667](),[6.4667][6.2978:3059]()
    end,
    })
    if Overflow_button then
    return x, y+Line_height
    else
    return x+w+10, y
    end
    [5.424]
    [6.4682]
    end)
  • replacement in 0065-hide_code_button at line 2
    [6.3098][6.4760:4792](),[6.4760][6.4760:4792](),[6.4792][6.3099:3236](),[6.3236][2.18:35](),[2.35][6.3236:3334](),[6.3236][6.3236:3334](),[6.3334][6.4888:5069](),[6.4888][6.4888:5069]()
    local w = App.width('hide')+10
    local x2, y2 = maybe_draw_overflow_button(x, y, w, r)
    if Overflow_button then
    -- overflow
    if not Show_overflow then
    return x, y
    else
    y = y2
    end
    end
    button(Global_state, 'hide', {x=x, y=y, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
    icon = function(p)
    App.color(Normal_color)
    love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
    love.graphics.print('hide', p.x+5,p.y+2)
    end,
    onpress1 = function()
    [6.3098]
    [6.5069]
    return overflowable_button('hide', x, y, r,
    function()
  • replacement in 0065-hide_code_button at line 5
    [6.5090][6.5090:5101](),[6.5101][6.3335:3416]()
    end,
    })
    if Overflow_button then
    return x, y+Line_height
    else
    return x+w+10, y
    end
    [6.5090]
    [6.5116]
    end)
  • replacement in 0064-show_code_button at line 2
    [4.109][6.5199:5231](),[6.3452][6.5199:5231](),[6.5199][6.5199:5231](),[6.5231][2.36:201](),[2.201][6.3453:3540](),[6.5231][6.3453:3540](),[6.3540][6.5327:5508](),[6.5327][6.5327:5508]()
    local w = App.width('show')+10
    local x2, y2 = maybe_draw_overflow_button(x, y, w, r)
    if Overflow_button then
    -- overflow
    if not Show_overflow then
    return x, y
    else
    y = y2
    end
    end
    button(Global_state, 'show', {x=x, y=y, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
    icon = function(p)
    App.color(Normal_color)
    love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
    love.graphics.print('show', p.x+5,p.y+2)
    end,
    onpress1 = function()
    [4.109]
    [6.5508]
    return overflowable_button('show', x, y, r,
    function()
  • replacement in 0064-show_code_button at line 5
    [6.5528][6.5528:5539](),[6.5539][2.202:283]()
    end,
    })
    if Overflow_button then
    return x, y+Line_height
    else
    return x+w+10, y
    end
    [6.5528]
    [6.5554]
    end)
  • replacement in 0061-new_pane_button at line 2
    [6.3610][6.5694:5725](),[6.5694][6.5694:5725](),[6.5725][6.3611:3862](),[6.3862][6.5820:6000](),[6.5820][6.5820:6000]()
    local w = App.width('new')+10
    local x2, y2 = maybe_draw_overflow_button(x, y, w, r)
    if Overflow_button then
    -- overflow
    if not Show_overflow then
    return x, y
    else
    y = y2
    end
    end
    button(Global_state, 'new', {x=x, y=y, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
    icon = function(p)
    App.color(Normal_color)
    love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
    love.graphics.print('new', p.x+5,p.y+2)
    end,
    onpress1 = function()
    [6.3610]
    [6.6000]
    return overflowable_button('new', x, y, r,
    function()
  • replacement in 0061-new_pane_button at line 7
    [6.6144][6.6144:6155](),[6.6155][6.3863:3944]()
    end,
    })
    if Overflow_button then
    return x, y+Line_height
    else
    return x+w+10, y
    end
    [6.6144]
    [6.6170]
    end)