Still not working: clicking on text to move the cursor aborts up/down motions still move by logical lines rather than screen lines
H2DPLWMVRFYTO2CQTG54FMT2LF3B6UKLXH32CUA22DNQJVP5XBNQC
4C375P53EXHUPXUFQSI3LA7THEP2WOKX5ZB57OQ5ZSM7LYOVW5HAC
BULPIBEGL7TMK6CVIE7IS7WGAHGOSUJBGJSFQK542MOWGHP2ADQQC
B3IWYWSRDSZ7AG5HDS3TELNTG2IKRZYPI25B6LJGVFAJYTHVXZZAC
XNFTJHC4QSHNSIWNN7K6QZEZ37GTQYKHS4EPNSVPQCUSWREROGIQC
UWNHC4AAO3SPOYLPANTO4WKCTZL7KAYC73Q2YUZFFW7K26FVJ7FQC
OTIBCAUJ3KDQJLVDN3A536DLZGNRYMGJLORZVR3WLCGXGO6UGO6AC
DLQMM2656JHXX3ONOEM6UIOXKFJFT5QT7RHWK7YS2W77PVZWHRSAC
function Text.draw(line, line_index, cursor_line, cursor_pos)
function Text.compute_fragments(line, line_width)
line.fragments = {}
local x = 25
-- try to wrap at word boundaries
for frag in line.data:gmatch('%S*%s*') do
local frag_text = love.graphics.newText(love.graphics.getFont(), frag)
local frag_width = math.floor(frag_text:getWidth()*Zoom)
--? print('x: '..tostring(x)..'; '..tostring(line_width-x)..'px to go')
--? print('frag: ^'..frag..'$ is '..tostring(frag_width)..'px wide')
if x + frag_width > line_width then
while x + frag_width > line_width do
if x < 0.8*line_width then
-- long word; chop it at some letter
-- We're not going to reimplement TeX here.
local b = Text.nearest_cursor_pos(frag, line_width - x)
--? print('space for '..tostring(b)..' graphemes')
local frag1 = string.sub(frag, 1, b)
local frag1_text = love.graphics.newText(love.graphics.getFont(), frag1)
local frag1_width = math.floor(frag1_text:getWidth()*Zoom)
--? print('inserting '..frag1..' of width '..tostring(frag1_width)..'px')
table.insert(line.fragments, {data=frag1, text=frag1_text})
frag = string.sub(frag, b+1)
frag_text = love.graphics.newText(love.graphics.getFont(), frag)
frag_width = math.floor(frag_text:getWidth()*Zoom)
end
x = 25 -- new line
end
end
if #frag > 0 then
--? print('inserting '..frag..' of width '..tostring(frag_width)..'px')
table.insert(line.fragments, {data=frag, text=frag_text})
end
end
end
function Text.draw(line, line_width, line_index, cursor_line, cursor_pos)
love.graphics.setColor(0.75,0.75,0.75)
love.graphics.line(line_width, 0, line_width, Screen_height)
local love_text = love.graphics.newText(love.graphics.getFont(), line.data)
love.graphics.draw(love_text, 25,line.y, 0, Zoom)
if line_index == cursor_line then
-- cursor
love.graphics.print('_', Text.cursor_x(line.data, cursor_pos), line.y+6) -- drop the cursor down a bit to account for the increased font size
-- wrap long lines
local x = 25
local y = line.y
local pos = 1
if line.fragments == nil then
Text.compute_fragments(line, line_width)
end
for _, f in ipairs(line.fragments) do
local frag, frag_text = f.data, f.text
-- render fragment
local frag_width = math.floor(frag_text:getWidth()*Zoom)
if x + frag_width > line_width then
assert(x > 25) -- no overfull lines
y = y + math.floor(15*Zoom)
x = 25
end
love.graphics.draw(frag_text, x,y, 0, Zoom)
-- render cursor if necessary
local frag_len = utf8.len(frag)
if line_index == cursor_line then
if pos <= cursor_pos and pos + frag_len > cursor_pos then
-- cursor
love.graphics.print('_', x+Text.cursor_x2(frag, cursor_pos-pos+1), y+6) -- drop the cursor down a bit to account for the increased font size
end
end
x = x + frag_width
pos = pos + frag_len