about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-07-08 15:07:55 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-07-08 15:12:17 -0700
commite39269b19ed4a02e088f2cf8522ea8d06e00375b (patch)
tree337ac1187d6833f0a4ed195b5e1fa96400485488
parent8efdb898c6092e070900ae8ce13fb31ab321d5f8 (diff)
downloadview.love-e39269b19ed4a02e088f2cf8522ea8d06e00375b.tar.gz
start passing left/right margins everywhere
I have a set of changes that passes all tests, but I'm going to commit
them very carefully to ensure I don't miss any call-sites. In this
commit I'm adding the args to:
  - Text.draw
  - Text.tweak_screen_top_and_cursor

But calls within them don't yet pass them where they should. In this
manner I'm going to progress systematically from the top down.
-rw-r--r--main.lua4
-rw-r--r--text.lua16
2 files changed, 10 insertions, 10 deletions
diff --git a/main.lua b/main.lua
index b95fb00..2c79b77 100644
--- a/main.lua
+++ b/main.lua
@@ -191,7 +191,7 @@ function App.resize(w, h)
   App.screen.width, App.screen.height = w, h
   Text.redraw_all()
   Selection1 = {}  -- no support for shift drag while we're resizing
-  Text.tweak_screen_top_and_cursor()
+  Text.tweak_screen_top_and_cursor(Margin_left, App.screen.height-Margin_right)
   Last_resize_time = App.getTime()
 end
 
@@ -272,7 +272,7 @@ function App.draw()
         line.startpos = Screen_top1.pos
       end
 --?       print('text.draw', y, line_index)
-      y, Screen_bottom1.pos = Text.draw(line, line_index)
+      y, Screen_bottom1.pos = Text.draw(line, line_index, line.starty, Margin_left, App.screen.width-Margin_right)
       y = y + Line_height
 --?       print('=> y', y)
     end
diff --git a/text.lua b/text.lua
index d0eab42..97a340f 100644
--- a/text.lua
+++ b/text.lua
@@ -11,12 +11,12 @@ require 'text_tests'
 -- return values:
 --  y coordinate drawn until in px
 --  position of start of final screen line drawn
-function Text.draw(line, line_index)
+function Text.draw(line, line_index, top, left, right)
 --?   print('text.draw', line_index)
   love.graphics.setColor(0,0,0)
   -- wrap long lines
-  local x = Margin_left
-  local y = line.starty
+  local x = left
+  local y = top
   local pos = 1
   local screen_line_starting_pos = 1
   if line.fragments == nil then
@@ -30,9 +30,9 @@ function Text.draw(line, line_index)
     local frag_width = App.width(frag_text)
     local frag_len = utf8.len(frag)
 --?     local s=tostring
---?     print('('..s(x)..','..s(y)..') '..frag..'('..s(frag_width)..' vs '..s(App.screen.width-Margin_right)..') '..s(line_index)..' vs '..s(Screen_top1.line)..'; '..s(pos)..' vs '..s(Screen_top1.pos)..'; bottom: '..s(Screen_bottom1.line)..'/'..s(Screen_bottom1.pos))
-    if x + frag_width > App.screen.width-Margin_right then
-      assert(x > Margin_left)  -- no overfull lines
+--?     print('('..s(x)..','..s(y)..') '..frag..'('..s(frag_width)..' vs '..s(right)..') '..s(line_index)..' vs '..s(Screen_top1.line)..'; '..s(pos)..' vs '..s(Screen_top1.pos)..'; bottom: '..s(Screen_bottom1.line)..'/'..s(Screen_bottom1.pos))
+    if x + frag_width > right then
+      assert(x > left)  -- no overfull lines
       -- update y only after drawing the first screen line of screen top
       if Text.lt1(Screen_top1, {line=line_index, pos=pos}) then
         y = y + Line_height
@@ -43,7 +43,7 @@ function Text.draw(line, line_index)
         screen_line_starting_pos = pos
 --?         print('text: new screen line', y, App.screen.height, screen_line_starting_pos)
       end
-      x = Margin_left
+      x = left
     end
 --?     print('checking to draw', pos, Screen_top1.pos)
     -- don't draw text above screen top
@@ -917,7 +917,7 @@ function Text.populate_screen_line_starting_pos(line)
   end
 end
 
-function Text.tweak_screen_top_and_cursor()
+function Text.tweak_screen_top_and_cursor(left, right)
 --?   print('a', Selection1.line)
   if Screen_top1.pos == 1 then return end
   local line = Lines[Screen_top1.line]