diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-05-25 13:38:33 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-05-25 13:38:33 -0700 |
commit | c2eee640cfd01d64e1a0576ca3d6d99d6615561d (patch) | |
tree | b8162d20a2380a9fb180de67d58cc9a06f6a5f41 | |
parent | 442133fe7f629a825bbf30b05e29cc85b836c93c (diff) | |
download | text.love-c2eee640cfd01d64e1a0576ca3d6d99d6615561d.tar.gz |
test and App helper for mouse clicks
-rw-r--r-- | app.lua | 6 | ||||
-rw-r--r-- | text.lua | 19 |
2 files changed, 24 insertions, 1 deletions
diff --git a/app.lua b/app.lua index 311be18..3ed3aa8 100644 --- a/app.lua +++ b/app.lua @@ -186,6 +186,12 @@ function App.run_after_keychord(key) App.draw() end +function App.run_after_mousepress(x,y, button) + App.mousepressed(x,y, button) + App.screen.contents = {} + App.draw() +end + function App.width(text) return text.text:getWidth() end diff --git a/text.lua b/text.lua index 5fbff05..dbba139 100644 --- a/text.lua +++ b/text.lua @@ -140,6 +140,23 @@ function test_edit_wrapping_text() App.screen.check(y, 'ghij', 'F - test_edit_wrapping_text/screen:3') end +function test_move_cursor_using_mouse() + io.write('\ntest_move_cursor_using_mouse') + App.screen.init{width=50, height=60} + Lines = load_array{'abc', 'def', 'xyz'} + Line_width = App.screen.width + Cursor1 = {line=1, pos=1} + Screen_top1 = {line=1, pos=1} + Screen_bottom1 = {} + Zoom = 1 + App.draw() -- populate line.y for each line in Lines + local screen_top_margin = 15 -- pixels + local screen_left_margin = 25 -- pixels + App.run_after_mousepress(screen_left_margin+8,screen_top_margin+5, '1') + check_eq(Cursor1.line, 1, 'F - test_move_cursor_using_mouse/cursor:line') + check_eq(Cursor1.pos, 2, 'F - test_move_cursor_using_mouse/cursor:pos') +end + function test_pagedown() io.write('\ntest_pagedown') App.screen.init{width=120, height=45} @@ -980,7 +997,7 @@ end function Text.in_line(line, x,y) if line.y == nil then return false end -- outside current page - if x < 16 then return false end + if x < 25 then return false end if y < line.y then return false end if line.screen_line_starting_pos == nil then return y < line.y + math.floor(15*Zoom) end return y < line.y + #line.screen_line_starting_pos * math.floor(15*Zoom) |