use editor state font for width calculations

akkartik
Jan 12, 2024, 1:23 PM
AQMZJXUR5NFNATJ4LPTVGVLQFIKRKRSPYAICXWHGQCQ4WLMQ2JTQC

Dependencies

  • [2] VSA3FN7X .
  • [3] VNVRFP2V bugfix: rendering hyperlinks in wrapping lines
  • [4] IM7UEBMK bugfix: highlight search patterns on the right line
  • [5] UBA2ZUCP remove a duplicate print to screen
  • [6] PXSQR2AD hide line numbers from log browser
  • [7] G3DLS5OU audit all asserts
  • [8] AIHGJ4BT bugfix: infinite loop inside a very narrow window
  • [9] UCW27FJK bugfix: utf-8
  • [10] GAPPXISY moar bugfix X-(
  • [11] ZMBPXIZ4 bugfix
  • [12] KZ5GAYRP this fixes the immediate regression
  • [13] HIKLULFQ extract a function
  • [14] BOFNXP5G clicking now moves the cursor even on long, wrapped lines
  • [15] VSBSWTE4 bugfix: where cursor is drawn
  • [16] IMEJA43L snapshot
  • [17] R3KXFRZN get rid of to_text
  • [18] J3I6DVMB drop an unused arg
  • [19] H22OAXWE couple of TODOs
  • [20] 5L7K4GBD clicking to the right of a wrapped line
  • [21] EGH7XDBK support non-text lines in Text.to2
  • [22] MXA3RZYK deduce left/right from state where possible
  • [23] 2Y7YH7UP infrastructure for caching LÖVE text objects
  • [24] KMSL74GA support selections in the source editor
  • [25] FBVUNLS4 clean up some debug prints
  • [26] MP2TBKU6 bugfix: crash in Text.up() after return
  • [27] GZ5WULJV switch source side to new screen-line-based render
  • [28] VHQCNMAR several more modules
  • [29] BULPIBEG beginnings of a module for the text editor
  • [30] 54HEXCWV clearer API for drawing a button
  • [31] UPCIYZEU drop an unnecessary level of indent
  • [32] FHSZYAZ2 more precise search highlighting
  • [33] X3F7ECSL add state arg to some functions
  • [34] DAENUOGV eliminate assumptions that line length == size in bytes
  • [35] S2MISTTM add state arg to a few functions
  • [36] C2M4RUU5 reorganize some comments
  • [37] 356GY7IQ unify two similar functions
  • [38] LXTTOB33 extract a couple of files
  • [39] KCLRP4VW rename a couple of variables
  • [40] KKMFQDR4 editing source code from within the app
  • [41] ULKLJBN6 couple of renames
  • [42] IWYLK45K clicking to the right of a line within line width
  • [43] T57DTBX6 add args to some functions
  • [44] LK4ZW4BB bugfix
  • [45] HOSPP2AN crisp font rendering
  • [46] AOZX2G5F source: no commandline args
  • [47] H4R5BHVY no more Text allocations
  • [48] AH744RFR show when we're naming a point
  • [49] 4KC7I3E2 make colors easier to edit
  • [50] ILOA5BYF separate data structure for each line's cache data
  • [51] ISOFHXB2 App.width can no longer take a Text
  • [52] GL4Q5WCV keep text from overflowing right margin
  • [53] BE3WIEVK update cursor in search box
  • [54] SDEY7LFJ rename a variable
  • [55] G54H3YG2 get rid of all bifold text
  • [56] KV7GGVER couple of accidental globals
  • [57] Z5HLXU4P add state arg to a few functions
  • [58] P4376EXK add state arg to few functions
  • [59] CWQIPU7U always show line numbers in source editor
  • [60] UQI34GQF make button backgrounds optional
  • [61] HALS7E5U more clearly skip prints before screen top
  • [62] UHB4GARJ left/right margin -> left/right coordinates
  • [63] S2QMLRXL stop creating a singleton table for every word
  • [64] TWXPV2AC hoist and duplicate a conditional
  • [65] PFT5Y2ZY move
  • [66] 7JH2ZT3F add state arg to Drawing.draw
  • [67] MYC7XR5Q bugfix: lines that aren't drawn from the start
  • [68] SWZAQHGR bugfix: up arrow when line above is a drawing
  • [69] 2L4DL7PG go through App in a couple more places
  • [70] AIBA4RWQ hide cursor in log browser window
  • [71] 5XA7TKWY pull font into editor
  • [72] LAW2O3NW extract variable Margin_left
  • [73] Z4XRNDTR find text
  • [74] AJB4LFRB try to maintain a reasonable line width
  • [75] KURLAXXI clean up some prints
  • [76] OI4FPFIN support drawings in the source editor
  • [77] DFSDPDO7 bugfix
  • [78] I64IPGJX avoid saving fragments in lines
  • [79] QYIFOHW3 first test!
  • [80] 5BMR5HRT click to the left of a line
  • [81] LF7BWEG4 group all editor globals
  • [82] ZPUQSPQP extract a few methods
  • [83] W5WCQNMP bugfix: Windows pushing title bar off screen
  • [84] JLU2RMC4 allow Text.nearest_pos_less_than to return 0
  • [85] 4VKEE43Z bugfix
  • [*] BLWAYPKV extract a module

Change contents

  • replacement in text.lua at line 44
    [4.169][4.169:265]()
    Text.draw_cursor(State, State.left+Text.x(screen_line, State.cursor1.pos-pos+1), y)
    [4.169]
    [4.265]
    Text.draw_cursor(State, State.left+Text.x(State.font, screen_line, State.cursor1.pos-pos+1), y)
  • replacement in text.lua at line 49
    [11.232][11.243:339](),[4.571][11.243:339](),[11.869][11.243:339]()
    Text.draw_cursor(State, State.left+Text.x(screen_line, State.cursor1.pos-pos+1), y)
    [4.571]
    [11.530]
    Text.draw_cursor(State, State.left+Text.x(State.font, screen_line, State.cursor1.pos-pos+1), y)
  • replacement in text.lua at line 98
    [11.747][11.89:128]()
    local frag_width = App.width(frag)
    [11.168]
    [11.1613]
    local frag_width = State.font:getWidth(frag)
  • replacement in text.lua at line 105
    [11.331][11.1821:1892]()
    local bpos = Text.nearest_pos_less_than(frag, State.width - x)
    [11.331]
    [8.0]
    local bpos = Text.nearest_pos_less_than(State.font, frag, State.width - x)
  • replacement in text.lua at line 115
    [11.2074][11.175:212](),[11.1160][11.175:212]()
    frag_width = App.width(frag)
    [11.2074]
    [11.1367]
    frag_width = State.font:getWidth(frag)
  • replacement in text.lua at line 422
    [11.4882][11.1024:1138]()
    State.cursor1.pos = screen_line_starting_pos + Text.nearest_cursor_pos(s, State.cursor_x, State.left) - 1
    [11.4882]
    [11.1691]
    State.cursor1.pos = screen_line_starting_pos + Text.nearest_cursor_pos(State.font, s, State.cursor_x, State.left) - 1
  • replacement in text.lua at line 432
    [11.5703][11.1139:1253]()
    State.cursor1.pos = new_screen_line_starting_pos + Text.nearest_cursor_pos(s, State.cursor_x, State.left) - 1
    [11.5703]
    [11.5811]
    State.cursor1.pos = new_screen_line_starting_pos + Text.nearest_cursor_pos(State.font, s, State.cursor_x, State.left) - 1
  • replacement in text.lua at line 457
    [11.537][11.537:641]()
    pos = Text.nearest_cursor_pos(State.lines[new_cursor_line].data, State.cursor_x, State.left),
    [11.537]
    [11.641]
    pos = Text.nearest_cursor_pos(State.font, State.lines[new_cursor_line].data, State.cursor_x, State.left),
  • replacement in text.lua at line 479
    [11.7111][11.1606:1720]()
    State.cursor1.pos = new_screen_line_starting_pos + Text.nearest_cursor_pos(s, State.cursor_x, State.left) - 1
    [11.7111]
    [11.7219]
    State.cursor1.pos = new_screen_line_starting_pos + Text.nearest_cursor_pos(State.font, s, State.cursor_x, State.left) - 1
  • replacement in text.lua at line 742
    [11.1751][11.3151:3393]()
    --? print('return', mx, Text.nearest_cursor_pos(s, mx, State.left), '=>', screen_line_starting_pos + Text.nearest_cursor_pos(s, mx, State.left) - 1)
    return screen_line_starting_pos + Text.nearest_cursor_pos(s, mx, State.left) - 1
    [11.1751]
    [11.1279]
    --? print('return', mx, Text.nearest_cursor_pos(State.font, s, mx, State.left), '=>', screen_line_starting_pos + Text.nearest_cursor_pos(State.font, s, mx, State.left) - 1)
    return screen_line_starting_pos + Text.nearest_cursor_pos(State.font, s, mx, State.left) - 1
  • replacement in text.lua at line 763
    [11.1530][11.213:245]()
    return App.width(screen_line)
    [11.1530]
    [11.1649]
    return State.font:getWidth(screen_line)
  • replacement in text.lua at line 777
    [2.25][11.670:718](),[11.670][11.670:718]()
    function Text.nearest_cursor_pos(line, x, left)
    [2.25]
    [11.956]
    function Text.nearest_cursor_pos(font, line, x, left)
  • replacement in text.lua at line 782
    [11.383][11.719:760]()
    local max_x = left+Text.x(line, len+1)
    [11.383]
    [11.598]
    local max_x = left+Text.x(font, line, len+1)
  • replacement in text.lua at line 794
    [11.208][11.761:853]()
    local currxmin = left+Text.x(line, curr)
    local currxmax = left+Text.x(line, curr+1)
    [11.208]
    [11.209]
    local currxmin = left+Text.x(font, line, curr)
    local currxmax = left+Text.x(font, line, curr+1)
  • replacement in text.lua at line 819
    [2.48][11.3424:3469](),[11.3424][11.3424:3469]()
    function Text.nearest_pos_less_than(line, x)
    [2.48]
    [11.619]
    function Text.nearest_pos_less_than(font, line, x)
  • replacement in text.lua at line 822
    [11.7300][11.1065:1105]()
    local max_x = Text.x_after(line, len)
    [11.7300]
    [11.7344]
    local max_x = Text.x_after(font, line, len)
  • replacement in text.lua at line 829
    [11.7496][11.1106:1202]()
    local currxmin = Text.x_after(line, curr+1)
    local currxmax = Text.x_after(line, curr+2)
    [11.7496]
    [11.673]
    local currxmin = Text.x_after(font, line, curr+1)
    local currxmax = Text.x_after(font, line, curr+2)
  • replacement in text.lua at line 847
    [11.3662][11.1203:1233]()
    function Text.x_after(s, pos)
    [11.3662]
    [9.4]
    function Text.x_after(font, s, pos)
  • replacement in text.lua at line 852
    [11.3817][11.246:275]()
    return App.width(s_before)
    [11.3817]
    [11.7876]
    return font:getWidth(s_before)
  • replacement in text.lua at line 855
    [11.7881][11.1234:1258]()
    function Text.x(s, pos)
    [11.7881]
    [11.1258]
    function Text.x(font, s, pos)
  • replacement in text.lua at line 858
    [11.1333][11.276:305]()
    return App.width(s_before)
    [11.1333]
    [11.1434]
    return font:getWidth(s_before)
  • replacement in source_text.lua at line 17
    [6.153][6.153:239]()
    love.graphics.print(line_index, State.left-Line_number_width*App.width('m')+10,y)
    [6.153]
    [6.239]
    love.graphics.print(line_index, State.left-Line_number_width*State.font:getWidth('m')+10,y)
  • replacement in source_text.lua at line 35
    [11.764][11.764:850]()
    local lo, hi = Text.clip_wikiword_with_screen_line(line, line_cache, i, s, e)
    [11.764]
    [11.850]
    local lo, hi = Text.clip_wikiword_with_screen_line(State.font, line, line_cache, i, s, e)
  • replacement in source_text.lua at line 65
    [4.741][4.741:837]()
    Text.draw_cursor(State, State.left+Text.x(screen_line, State.cursor1.pos-pos+1), y)
    [4.741]
    [4.837]
    Text.draw_cursor(State, State.left+Text.x(State.font, screen_line, State.cursor1.pos-pos+1), y)
  • replacement in source_text.lua at line 70
    [11.488][11.626:722](),[4.1143][11.626:722](),[11.88889][11.626:722]()
    Text.draw_cursor(State, State.left+Text.x(screen_line, State.cursor1.pos-pos+1), y)
    [4.1143]
    [11.89003]
    Text.draw_cursor(State, State.left+Text.x(State.font, screen_line, State.cursor1.pos-pos+1), y)
  • replacement in source_text.lua at line 79
    [5.537][5.537:567]()
    x = x+App.width(frag)
    [5.537]
    [11.89029]
    x = x+State.font:getWidth(frag)
  • replacement in source_text.lua at line 123
    [11.2472][11.2472:2511]()
    local frag_width = App.width(frag)
    [11.2472]
    [11.2511]
    local frag_width = State.font:getWidth(frag)
  • replacement in source_text.lua at line 130
    [11.2815][11.2815:2886]()
    local bpos = Text.nearest_pos_less_than(frag, State.width - x)
    [11.2815]
    [8.193]
    local bpos = Text.nearest_pos_less_than(State.font, frag, State.width - x)
  • replacement in source_text.lua at line 140
    [11.3180][11.3180:3217]()
    frag_width = App.width(frag)
    [11.3180]
    [11.3217]
    frag_width = State.font:getWidth(frag)
  • replacement in source_text.lua at line 175
    [11.3993][11.3993:4065]()
    function Text.clip_wikiword_with_screen_line(line, line_cache, i, s, e)
    [11.3993]
    [11.4065]
    function Text.clip_wikiword_with_screen_line(font, line, line_cache, i, s, e)
  • replacement in source_text.lua at line 197
    [11.4555][3.7:93]()
    return App.width(line.data:sub(soff, loff-1)), App.width(line.data:sub(soff, hoff))
    [11.4555]
    [11.94273]
    return font:getWidth(line.data:sub(soff, loff-1)), font:getWidth(line.data:sub(soff, hoff))
  • replacement in source_text.lua at line 484
    [11.7881][11.7881:7995]()
    State.cursor1.pos = screen_line_starting_pos + Text.nearest_cursor_pos(s, State.cursor_x, State.left) - 1
    [11.7881]
    [11.7995]
    State.cursor1.pos = screen_line_starting_pos + Text.nearest_cursor_pos(State.font, s, State.cursor_x, State.left) - 1
  • replacement in source_text.lua at line 494
    [11.110929][11.110929:111043]()
    State.cursor1.pos = new_screen_line_starting_pos + Text.nearest_cursor_pos(s, State.cursor_x, State.left) - 1
    [11.110929]
    [11.111043]
    State.cursor1.pos = new_screen_line_starting_pos + Text.nearest_cursor_pos(State.font, s, State.cursor_x, State.left) - 1
  • replacement in source_text.lua at line 519
    [11.9229][11.9229:9333]()
    pos = Text.nearest_cursor_pos(State.lines[new_cursor_line].data, State.cursor_x, State.left),
    [11.9229]
    [11.9333]
    pos = Text.nearest_cursor_pos(State.font, State.lines[new_cursor_line].data, State.cursor_x, State.left),
  • replacement in source_text.lua at line 541
    [11.116648][11.116648:116762]()
    State.cursor1.pos = new_screen_line_starting_pos + Text.nearest_cursor_pos(s, State.cursor_x, State.left) - 1
    [11.116648]
    [11.116762]
    State.cursor1.pos = new_screen_line_starting_pos + Text.nearest_cursor_pos(State.font, s, State.cursor_x, State.left) - 1
  • replacement in source_text.lua at line 804
    [11.5140][11.5140:5382]()
    --? print('return', mx, Text.nearest_cursor_pos(s, mx, State.left), '=>', screen_line_starting_pos + Text.nearest_cursor_pos(s, mx, State.left) - 1)
    return screen_line_starting_pos + Text.nearest_cursor_pos(s, mx, State.left) - 1
    [11.5140]
    [11.135329]
    --? print('return', mx, Text.nearest_cursor_pos(State.font, s, mx, State.left), '=>', screen_line_starting_pos + Text.nearest_cursor_pos(State.font, s, mx, State.left) - 1)
    return screen_line_starting_pos + Text.nearest_cursor_pos(State.font, s, mx, State.left) - 1
  • replacement in source_text.lua at line 825
    [11.135976][11.520:552]()
    return App.width(screen_line)
    [11.135976]
    [11.136090]
    return State.font:getWidth(screen_line)
  • replacement in source_text.lua at line 839
    [11.137622][11.137622:137670]()
    function Text.nearest_cursor_pos(line, x, left)
    [11.137622]
    [11.137670]
    function Text.nearest_cursor_pos(font, line, x, left)
  • replacement in source_text.lua at line 844
    [11.137737][11.137737:137778]()
    local max_x = left+Text.x(line, len+1)
    [11.137737]
    [11.137778]
    local max_x = left+Text.x(font, line, len+1)
  • replacement in source_text.lua at line 856
    [11.138077][11.138077:138169]()
    local currxmin = left+Text.x(line, curr)
    local currxmax = left+Text.x(line, curr+1)
    [11.138077]
    [11.138169]
    local currxmin = left+Text.x(font, line, curr)
    local currxmax = left+Text.x(font, line, curr+1)
  • replacement in source_text.lua at line 881
    [11.138708][11.138708:138753]()
    function Text.nearest_pos_less_than(line, x)
    [11.138708]
    [11.138753]
    function Text.nearest_pos_less_than(font, line, x)
  • replacement in source_text.lua at line 884
    [11.138835][11.138835:138875]()
    local max_x = Text.x_after(line, len)
    [11.138835]
    [11.138875]
    local max_x = Text.x_after(font, line, len)
  • replacement in source_text.lua at line 891
    [11.139009][11.139009:139105]()
    local currxmin = Text.x_after(line, curr+1)
    local currxmax = Text.x_after(line, curr+2)
    [11.139009]
    [11.139105]
    local currxmin = Text.x_after(font, line, curr+1)
    local currxmax = Text.x_after(font, line, curr+2)
  • replacement in source_text.lua at line 909
    [11.139394][11.139394:139424]()
    function Text.x_after(s, pos)
    [11.139394]
    [9.91]
    function Text.x_after(font, s, pos)
  • replacement in source_text.lua at line 914
    [11.139549][11.553:582]()
    return App.width(s_before)
    [11.139549]
    [11.139650]
    return font:getWidth(s_before)
  • replacement in source_text.lua at line 917
    [11.139655][11.139655:139679]()
    function Text.x(s, pos)
    [11.139655]
    [11.139679]
    function Text.x(font, s, pos)
  • replacement in source_text.lua at line 920
    [11.139754][11.583:612]()
    return App.width(s_before)
    [11.139754]
    [11.139855]
    return font:getWidth(s_before)
  • replacement in source_select.lua at line 60
    [11.25854][11.615:647]()
    lo_px = App.width(before)
    [11.25854]
    [11.25962]
    lo_px = State.font:getWidth(before)
  • replacement in source_select.lua at line 64
    [11.26225][11.648:727]()
    love.graphics.rectangle('fill', x+lo_px,y, App.width(s),State.line_height)
    [11.26225]
    [11.26302]
    love.graphics.rectangle('fill', x+lo_px,y, State.font:getWidth(s),State.line_height)
  • replacement in source.lua at line 129
    [11.169468][10.45:217]()
    Editor_state = edit.initialize_state(Margin_top, Margin_left + Line_number_width*App.width('m'), right, font, settings.font_height, math.floor(settings.font_height*1.3))
    [11.169468]
    [11.169599]
    Editor_state = edit.initialize_state(Margin_top, Margin_left + Line_number_width*font:getWidth('m'), right, font, settings.font_height, math.floor(settings.font_height*1.3))
  • replacement in source.lua at line 157
    [11.51][11.304:482]()
    Editor_state = edit.initialize_state(Margin_top, Margin_left + Line_number_width*App.width('m'), App.screen.width-Margin_right, font, font_height, math.floor(font_height*1.3))
    [11.51]
    [11.115]
    Editor_state = edit.initialize_state(Margin_top, Margin_left + Line_number_width*font:getWidth('m'), App.screen.width-Margin_right, font, font_height, math.floor(font_height*1.3))
  • replacement in select.lua at line 60
    [11.514][11.785:817]()
    lo_px = App.width(before)
    [11.514]
    [11.622]
    lo_px = State.font:getWidth(before)
  • replacement in select.lua at line 64
    [11.152][11.818:897]()
    love.graphics.rectangle('fill', x+lo_px,y, App.width(s),State.line_height)
    [11.152]
    [11.153]
    love.graphics.rectangle('fill', x+lo_px,y, State.font:getWidth(s),State.line_height)
  • replacement in search.lua at line 16
    [11.1671][11.899:962]()
    Text.draw_cursor(State, 25+App.width(State.search_term),y-5)
    [11.1671]
    [11.49698]
    Text.draw_cursor(State, 25+State.font:getWidth(State.search_term),y-5)
  • replacement in log_browser.lua at line 97
    [11.262][11.262:358]()
    love.graphics.line(xleft+50+App.width(line.section_name)+2,sectiony, xright,sectiony)
    [11.262]
    [7.6565]
    love.graphics.line(xleft+50+State.font:getWidth(line.section_name)+2,sectiony, xright,sectiony)
  • replacement in log_browser.lua at line 104
    [11.420][11.420:516]()
    love.graphics.line(xleft+50+App.width(line.section_name)+2,sectiony, xright,sectiony)
    [11.420]
    [11.196398]
    love.graphics.line(xleft+50+State.font:getWidth(line.section_name)+2,sectiony, xright,sectiony)
  • replacement in log_browser.lua at line 140
    [11.197661][11.517:681]()
    love.graphics.print(line.section_stack[i].name, x+State.font_height+5, App.screen.height-App.width(line.section_stack[i].name)-5, --[[vertically]] math.pi/2)
    [11.197661]
    [11.197834]
    love.graphics.print(line.section_stack[i].name, x+State.font_height+5, App.screen.height-State.font:getWidth(line.section_stack[i].name)-5, --[[vertically]] math.pi/2)
  • replacement in log_browser.lua at line 155
    [11.198357][11.682:826]()
    love.graphics.print(line.section_stack[i].name, x, App.screen.height-App.width(line.section_stack[i].name)-5, --[[vertically]] math.pi/2)
    [11.198357]
    [11.198510]
    love.graphics.print(line.section_stack[i].name, x, App.screen.height-State.font:getWidth(line.section_stack[i].name)-5, --[[vertically]] math.pi/2)
  • replacement in help.lua at line 12
    [11.460][11.18665:18762]()
    love.graphics.print("then press the mouse button to drop it", State.left+30+bullet_indent(),y)
    [11.460]
    [11.564]
    love.graphics.print("then press the mouse button to drop it", State.left+30+State.font:getWidth('* '),y)
  • edit in help.lua at line 147
    [11.11320][11.11320:11325](),[11.11346][11.11346:11371](),[11.11371][11.832:857]()
    end
    function bullet_indent()
    return App.width('* ')
  • replacement in drawing.lua at line 64
    [11.404][11.1055:1095]()
    name_width = App.width('m')
    [11.404]
    [11.488]
    name_width = State.font:getWidth('m')
  • replacement in drawing.lua at line 66
    [11.503][11.1096:1139]()
    name_width = App.width(p.name)
    [11.503]
    [11.582]
    name_width = State.font:getWidth(p.name)