bugfix: don't rely on Screen_bottom1 while scrolling

Setting up the test just right to test the thing I want to test was a
rube goldberg machine of constants.
This commit is contained in:
Kartik K. Agaram 2022-05-23 08:52:13 -07:00
parent 37f1313b16
commit 4f6a324975
3 changed files with 23 additions and 12 deletions

View File

@ -93,7 +93,7 @@ end
-- App.font{ -- App.font{
-- height=15 -- height=15
-- } -- }
-- App.run_after_keypress('pagedown') -- App.run_after_keychord('pagedown')
-- App.check_screen_contents{ -- App.check_screen_contents{
-- y0='ghi' -- y0='ghi'
-- y15='' -- y15=''

View File

@ -122,8 +122,10 @@ function App.draw()
local y = 15 local y = 15
if Debug_main then print('== draw') end if Debug_main then print('== draw') end
for line_index,line in ipairs(Lines) do for line_index,line in ipairs(Lines) do
print(y, line_index, line)
if Debug_main then print('draw:', line_index, y) end if Debug_main then print('draw:', line_index, y) end
if y + math.floor(15*Zoom) > App.screen.height then break end if y + math.floor(15*Zoom) > App.screen.height then break end
print('a')
if line_index >= Screen_top1.line then if line_index >= Screen_top1.line then
Screen_bottom1.line = line_index Screen_bottom1.line = line_index
if line.mode == 'text' and line.data == '' then if line.mode == 'text' and line.data == '' then
@ -226,12 +228,13 @@ function App.keychord_pressed(chord)
end end
save_to_disk(Lines, Filename) save_to_disk(Lines, Filename)
elseif chord == 'pagedown' then elseif chord == 'pagedown' then
print('setting top to', Screen_bottom1.line)
Screen_top1.line = Screen_bottom1.line Screen_top1.line = Screen_bottom1.line
Screen_top1.pos = Screen_bottom1.pos Screen_top1.pos = Screen_bottom1.pos
print('setting top to', Screen_top1.line)
Cursor1.line = Screen_top1.line Cursor1.line = Screen_top1.line
Cursor1.pos = Screen_top1.pos Cursor1.pos = Screen_top1.pos
Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necessary() Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necessary()
print('top now', Screen_top1.line)
elseif chord == 'pageup' then elseif chord == 'pageup' then
-- duplicate some logic from love.draw -- duplicate some logic from love.draw
local y = App.screen.height local y = App.screen.height

View File

@ -9,6 +9,7 @@ local Debug_new_render = false
-- y coordinate drawn until in px -- y coordinate drawn until in px
-- position of start of final screen line drawn -- position of start of final screen line drawn
function Text.draw(line, line_width, line_index) function Text.draw(line, line_width, line_index)
print('text.draw')
love.graphics.setColor(0,0,0) love.graphics.setColor(0,0,0)
-- wrap long lines -- wrap long lines
local x = 25 local x = 25
@ -126,11 +127,11 @@ end
function test_pagedown_skip_drawings() function test_pagedown_skip_drawings()
print('test_pagedown_skip_drawings') print('test_pagedown_skip_drawings')
-- some lines of text with a drawing intermixed -- some lines of text with a drawing intermixed
App.screen.init{width=50, height=45} App.screen.init{width=50, height=80}
Lines = load_array{'abc', Lines = load_array{'abc', -- height 15
'```lines', '```', '```lines', '```', -- height 25
'def', 'def', -- height 15
'ghi'} 'ghi'} -- height 15
check_eq(Lines[2].mode, 'drawing', 'F - test_pagedown_skip_drawings/baseline/lines') check_eq(Lines[2].mode, 'drawing', 'F - test_pagedown_skip_drawings/baseline/lines')
Line_width = App.screen.width Line_width = App.screen.width
Cursor1 = {line=1, pos=1} Cursor1 = {line=1, pos=1}
@ -138,17 +139,19 @@ function test_pagedown_skip_drawings()
Screen_bottom1 = {} Screen_bottom1 = {}
Zoom = 1 Zoom = 1
local screen_top_margin = 15 -- pixels local screen_top_margin = 15 -- pixels
local drawing_height = App.screen.width / 2 -- default local text height = 15
-- initially the screen displays the first line and part of the drawing local drawing_height = 20 + App.screen.width / 2 -- default
-- initially the screen displays the first line and the drawing
-- 15px margin + 15px line1 + 10px margin + 25px drawing + 10px margin = 75px < screen height 80px
App.draw() App.draw()
local y = screen_top_margin local y = screen_top_margin
App.screen.check(y, 'abc', 'F - test_pagedown_skip_drawings/baseline/screen:1') App.screen.check(y, 'abc', 'F - test_pagedown_skip_drawings/baseline/screen:1')
-- after pagedown the screen draws the screen up top -- after pagedown the screen draws the screen up top
-- 15px margin + 10px margin + 25px drawing + 10px margin + 15px line3 = 75px < screen height 80px
App.run_after_keychord('pagedown') App.run_after_keychord('pagedown')
print('test: top:', Screen_top1.line)
y = screen_top_margin + drawing_height y = screen_top_margin + drawing_height
App.screen.check(y, 'def', 'F - test_pagedown_skip_drawings/screen:1') App.screen.check(y, 'def', 'F - test_pagedown_skip_drawings/screen:1')
y = y + line_height
App.screen.check(y, 'ghi', 'F - test_pagedown_skip_drawings/screen:2')
end end
function Text.compute_fragments(line, line_width) function Text.compute_fragments(line, line_width)
@ -418,10 +421,13 @@ function Text.cursor_at_final_screen_line()
end end
function Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necessary() function Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necessary()
local y = 15 -- top margin
while Cursor1.line <= #Lines do while Cursor1.line <= #Lines do
if Lines[Cursor1.line].mode == 'text' then if Lines[Cursor1.line].mode == 'text' then
break break
end end
print('cursor skips', Cursor1.line)
y = y + 20 + Drawing.pixels(Lines[Cursor1.line].h)
Cursor1.line = Cursor1.line + 1 Cursor1.line = Cursor1.line + 1
end end
-- hack: insert a text line at bottom of file if necessary -- hack: insert a text line at bottom of file if necessary
@ -429,7 +435,9 @@ function Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necess
assert(Cursor1.line == #Lines+1) assert(Cursor1.line == #Lines+1)
table.insert(Lines, {mode='text', data=''}) table.insert(Lines, {mode='text', data=''})
end end
if Cursor1.line > Screen_bottom1.line then --? print(y, App.screen.height, App.screen.height-math.floor(15*Zoom))
if y > App.screen.height - math.floor(15*Zoom) then
--? if Cursor1.line > Screen_bottom1.line then
print('scroll up') print('scroll up')
Screen_top1.line = Cursor1.line Screen_top1.line = Cursor1.line
Text.scroll_up_while_cursor_on_screen() Text.scroll_up_while_cursor_on_screen()