affordance to adjust width for word wrap

This commit is contained in:
Kartik K. Agaram 2022-06-17 21:36:07 -07:00
parent 0fb98d2ac9
commit efbbdfc586
2 changed files with 43 additions and 1 deletions

View File

@ -1,5 +1,19 @@
icon = {}
function icon.line_width(x, y)
love.graphics.setColor(0.7,0.7,0.7)
love.graphics.line(x+0,y+0, x+9,y+0)
love.graphics.line(x+0,y+1, x+9,y+1)
love.graphics.line(x+0,y+2, x+9,y+2)
love.graphics.line(x+0,y+3, x+9,y+3)
love.graphics.line(x+0,y+4, x+9,y+4)
love.graphics.line(x+0,y+5, x+9,y+5)
love.graphics.line(x+1,y+6, x+8,y+6)
love.graphics.line(x+2,y+7, x+7,y+7)
love.graphics.line(x+3,y+8, x+6,y+8)
love.graphics.line(x+4,y+9, x+5,y+9)
end
function icon.insert_drawing(x, y)
love.graphics.setColor(0.7,0.7,0.7)
love.graphics.rectangle('line', x,y, 12,12)

View File

@ -93,6 +93,9 @@ Last_resize_time = nil
-- blinking cursor
Cursor_time = 0
-- line-width indicator
Line_width_hover = nil
end -- App.initialize_globals
function App.initialize(arg)
@ -216,6 +219,12 @@ function App.draw()
end
end
-- line-width indicator
button('line-width', {x=Margin_left+Line_width-4,y=Margin_top-10, w=10,h=10, color={1,1,1},
icon = icon.line_width,
onpress1 = function() Line_width_hover = App.getTime() end,
})
assert(Text.le1(Screen_top1, Cursor1))
Cursor_y = -1
local y = Margin_top
@ -228,6 +237,7 @@ function App.draw()
Screen_bottom1.line = line_index
if line.mode == 'text' and line.data == '' then
line.y = y
-- insert new drawing
button('draw', {x=4,y=y+4, w=12,h=12, color={1,1,0},
icon = icon.insert_drawing,
onpress1 = function()
@ -238,7 +248,8 @@ function App.draw()
end
schedule_save()
record_undo_event({before=Drawing.before, after=snapshot(line_index-1, line_index+1)})
end})
end
})
if Search_term == nil then
if line_index == Cursor1.line then
Text.draw_cursor(Margin_left, y)
@ -279,6 +290,18 @@ function App.update(dt)
Last_resize_time = nil
end
end
-- update Line_width with some hysteresis while the indicator is dragged
if Line_width_hover then
if App.getTime() - Line_width_hover > 0.1 then
Line_width = App.mouse_x() - Margin_left
Text.redraw_all()
if App.mouse_down(1) then
Line_width_hover = App.getTime()
else
Line_width_hover = nil
end
end
end
Drawing.update(dt)
if Next_save and Next_save < App.getTime() then
save_to_disk(Lines, Filename)
@ -296,6 +319,11 @@ function App.mousepressed(x,y, mouse_button)
if Search_term then return end
propagate_to_button_handlers(x,y, mouse_button)
-- we seem to sometimes get phantom clicks if the mouse moves down into text while adjusting line-width
if Line_width_hover then
Selection1 = {}
return
end
for line_index,line in ipairs(Lines) do
if line.mode == 'text' then
if Text.in_line(line_index,line, x,y) then