extract a function
This commit is contained in:
parent
e223182ad5
commit
5f2ef2faaf
5
main.lua
5
main.lua
|
@ -116,10 +116,7 @@ function love.draw()
|
|||
end
|
||||
end})
|
||||
if line_index == Cursor_line then
|
||||
-- cursor
|
||||
love.graphics.setColor(1,0,0)
|
||||
love.graphics.circle('fill', 25,y+math.floor(15*Zoom), 2)
|
||||
love.graphics.setColor(0,0,0)
|
||||
Text.draw_cursor(25, y)
|
||||
end
|
||||
y = y + math.floor(15*Zoom) -- text height
|
||||
elseif line.mode == 'drawing' then
|
||||
|
|
16
text.lua
16
text.lua
|
@ -32,20 +32,14 @@ function Text.draw(line, line_width, line_index, cursor_line, cursor_pos)
|
|||
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.setColor(1,0,0)
|
||||
love.graphics.circle('fill', x+Text.cursor_x2(frag, cursor_pos-pos+1),y+math.floor(15*Zoom), 2)
|
||||
love.graphics.setColor(0,0,0)
|
||||
Text.draw_cursor(x+Text.cursor_x2(frag, cursor_pos-pos+1), y)
|
||||
end
|
||||
end
|
||||
x = x + frag_width
|
||||
pos = pos + frag_len
|
||||
end
|
||||
if cursor_pos == pos then
|
||||
-- cursor
|
||||
love.graphics.setColor(1,0,0)
|
||||
love.graphics.circle('fill', x,y+math.floor(15*Zoom), 2)
|
||||
love.graphics.setColor(0,0,0)
|
||||
Text.draw_cursor(x, y)
|
||||
end
|
||||
return y
|
||||
end
|
||||
|
@ -54,6 +48,12 @@ end
|
|||
-- short words break on spaces
|
||||
-- long words break when they must
|
||||
|
||||
function Text.draw_cursor(x, y)
|
||||
love.graphics.setColor(1,0,0)
|
||||
love.graphics.circle('fill', x,y+math.floor(15*Zoom), 2)
|
||||
love.graphics.setColor(0,0,0)
|
||||
end
|
||||
|
||||
function Text.compute_fragments(line, line_width)
|
||||
line.fragments = {}
|
||||
local x = 25
|
||||
|
|
Loading…
Reference in New Issue