keep surface bounds updated when zooming out

scenario:
  move a buffer way outside the initial boundary
  press C-g to zoom out

Before this commit, C-g always zoomed out to the bounds computed at the
start of the session.
This commit is contained in:
Kartik K. Agaram 2023-06-15 18:41:16 -07:00
parent 1976dd0b48
commit 6602038fd7
3 changed files with 22 additions and 0 deletions

View File

@ -1,5 +1,6 @@
zoom_out = function()
Save_viewport = copy_viewport(Viewport)
initialize_global_viewport()
snapshot_canvas()
Animating = {
copy_viewport(Global_viewport),

1
0108-Global_viewport Normal file
View File

@ -0,0 +1 @@
Global_viewport = nil

View File

@ -0,0 +1,20 @@
initialize_global_viewport = function()
local minx, miny, maxx, maxy = surface_bounds(Definitions)
-- ensure 1px of white background all around
-- just in case the viewport ever goes
-- outside canvas bounds while animating
minx,miny, maxx,maxy = minx-1,miny-1, maxx+2,maxy+1
local zoomx = App.screen.width/(maxx-minx)
local zoomy = App.screen.height/(maxy-miny)
local zoom, cw, ch
if zoomx < zoomy then
zoom = zoomx
cw = maxx-minx
ch = cw*App.screen.height/App.screen.width
else
zoom = zoomy
ch = maxy-miny
cw = ch*App.screen.width/App.screen.height
end
Global_viewport = {x=minx, y=miny, w=cw, h=ch, zoom=zoom}
end