As recommended by Nextjournal (https://www.youtube.com/watch?v=A0TafHXszgM) and Jack Rusher (http://akkartik.name/archives/foc/share-your-work/1658973003.417109.html#1658994188.140719).
The poor aesthetics are all me. Also, I'm putting the menu/palette up top due to a technical difficulty: the basic contract of the editor widget from lines.love is to draw from a given (top,left,right) to the bottom of the screen. There's currently no way to specify a bottom.
YKRUNSPXQMYUZM2HC2BWRL3OLVF5X3Y3XASG7JCT4TW4VUHZD6ZAC
5E6DJTFMGUDYGZ3WT5BGSR7KO5WWZ3LV47HNMTHWVIJLBACTRWVQC
4R6FTCNUKS6IDJLNESSHZNPT5BNNZ64OEL3RBFCCZFZNP5OUSBQAC
EWK46OTWI2QK7ZZGYOCWWBHXHBXZQWR2FDW6LRTTKCN4K3ZFE5JAC
OTIBCAUJ3KDQJLVDN3A536DLZGNRYMGJLORZVR3WLCGXGO6UGO6AC
4BX4GJEWW7Z5LA4SJUXADYLAHOYFL4IBOYH4J4DJYRAVKKGGFHGQC
J3ER7DFO2TXYUMJAXZUFEHQNLFDNIXSYDTE7HEFGQ2RYB3A6RFPAC
QL7T6VAFKSK2AOIIRT3HGDY4UXYFKY747FM4BICGPSKFDUZM62DQC
3JDTNKUEWV3V2ABWCOAR4I5LHY3R4MARCFAAQ3KEYGKYHQOXCC2QC
UEL3EA2ENBNEUPJUQE4PJYN65R5SOAF7JFRRCBPGQZYWF4KEUIRAC
SKMUH5RWOBUHRAQ3TUEIH5EEHN3YOC35GJOJY7GPY7VY6QXLSODAC
IZAQ4C7DZ3OTGUPDYVRYJPHO6HT67HL7DZLPNIPWINBHNNLK42OAC
JPX4LCTO7AWAFUFO7G2TRQQAQ4CKDYZ52PX7XXROIBKXJYNZITOQC
GQBUV2XOMEPMTXMPCBQWGGIUXGQDX77VTGPFIG6YT7G64ASOYHXQC
Header_height = 5 + Line_height + 5
Menu_status_bar_height = 5 + Line_height + 5
Column_header_height = 5 + Line_height + 5
Header_height = Menu_status_bar_height + Column_header_height
Menu_text_cache = {} -- a few text objects we can avoid recomputing unless the font changes
love.graphics.rectangle('fill', sx-Display_settings.x - Margin_left, 0, Margin_left + Display_settings.column_width + Margin_right, Header_height)
love.graphics.rectangle('fill', sx-Display_settings.x - Margin_left, Menu_status_bar_height, Margin_left + Display_settings.column_width + Margin_right, Column_header_height)
-- We incrementally create the menu based on context. Menu_cursor tracks how
-- far along the screen width we've gotten.
Menu_cursor = 0
Palette_cursor = {y=0, x=0}
function draw_menu_bar()
if App.run_tests then return end -- disable in tests
App.color(Command_palette_background_color)
love.graphics.rectangle('fill', 0,0, App.screen.width, Menu_status_bar_height)
App.color(Command_palette_border_color)
love.graphics.rectangle('line', 0,0, App.screen.width, Menu_status_bar_height)
if Display_settings.show_palette then
return
end
App.color(Command_palette_command_color)
love.graphics.print('ctrl+enter: search commands...', 5,5)
App.color(Command_palette_border_color)
Menu_cursor = 360
love.graphics.line(Menu_cursor-10,2, Menu_cursor-10,Menu_status_bar_height-2)
if Display_settings.mode == 'normal' then
local pane = Surface[Cursor_pane.col][Cursor_pane.row]
if not pane.editable then
local left_sx = left_edge_sx(Cursor_pane.col)
local up_sy = up_edge_sy(Cursor_pane.col, Cursor_pane.row)
if overlap(left_sx, left_sx+Display_settings.column_width, Display_settings.x, Display_settings.x+App.screen.width)
and overlap(up_sy, up_sy+pane.height, Display_settings.y, Display_settings.y+App.screen.height-Header_height) then
add_hotkey_to_menu('ctrl+e: edit')
add_panning_hotkeys_to_menu()
end
add_hotkey_to_menu('x/X: narrower/wider columns')
else
if pane.cursor_x >= 0 and pane.cursor_x < App.screen.width and pane.cursor_y >= Header_height and pane.cursor_y < App.screen.height then
add_hotkey_to_menu('ctrl+e: stop editing')
else
add_panning_hotkeys_to_menu()
end
end
end
add_hotkey_to_menu('ctrl+= ctrl+- ctrl+0: zoom')
end
function add_panning_hotkeys_to_menu()
add_hotkey_to_menu('arrows shift+arrows ctrl+up/down: pan')
end
function add_hotkey_to_menu(s)
if Menu_text_cache[s] == nil then
Menu_text_cache[s] = App.newText(love.graphics.getFont(), s)
end
local width = App.width(Menu_text_cache[s])
if Menu_cursor + width > App.screen.width - 5 then
return
end
App.color(Command_palette_command_color)
App.screen.draw(Menu_text_cache[s], Menu_cursor,5)
Menu_cursor = Menu_cursor + width + 30
end
-- unused
function draw_maximized_mode_menu_bar(left, right)
App.color(Command_palette_background_color)
love.graphics.rectangle('fill', left-Margin_left,0, Margin_left+right-left+Margin_right, Menu_status_bar_height)
App.color(Command_palette_border_color)
love.graphics.rectangle('line', left-Margin_left,0, Margin_left+right-left+Margin_right, Menu_status_bar_height)
end
local y = top+5+Line_height+5+5
for _,cmd in ipairs(candidates()) do
love.graphics.print(cmd, left+5,y)
y = y+Line_height
if y >= top+height then
break
end
Palette_cursor = {y=Menu_status_bar_height+5, x=5, nextx=5}
for i,cmd in ipairs(candidates()) do
add_command_to_palette(cmd)
end
end
function add_command_to_palette(s)
if Menu_text_cache[s] == nil then
Menu_text_cache[s] = App.newText(love.graphics.getFont(), s)
end
local width = App.width(Menu_text_cache[s])
if Palette_cursor.x + width/2 > App.screen.width - 5 then
return
end
App.screen.draw(Menu_text_cache[s], Palette_cursor.x, Palette_cursor.y)
Palette_cursor.nextx = math.max(Palette_cursor.nextx, Palette_cursor.x+width+10)
Palette_cursor.y = Palette_cursor.y + Line_height
if Palette_cursor.y >= Menu_status_bar_height + 5+5*Line_height then
love.graphics.line(Palette_cursor.nextx, Menu_status_bar_height+2, Palette_cursor.nextx, Menu_status_bar_height + 5+5*Line_height+5)
Palette_cursor.x = Palette_cursor.nextx + 5
Palette_cursor.y = Menu_status_bar_height+5