diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-06-17 21:36:07 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-06-17 21:36:07 -0700 |
commit | efbbdfc58645dbee12a36a1a2f4c22054b969acc (patch) | |
tree | 692e08b469cf4c52c7dd2a1ee3a32bcf6760fcdf /main.lua | |
parent | 0fb98d2ac9e35cde15a08f0fec3c7e99700325f3 (diff) | |
download | text.love-efbbdfc58645dbee12a36a1a2f4c22054b969acc.tar.gz |
affordance to adjust width for word wrap
Diffstat (limited to 'main.lua')
-rw-r--r-- | main.lua | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/main.lua b/main.lua index 6e0272f..ffe6838 100644 --- a/main.lua +++ b/main.lua @@ -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 |