about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-12-23 16:57:04 -0800
committerKartik K. Agaram <vc@akkartik.com>2022-12-23 16:57:04 -0800
commite2e3aea2b1b9504bf849d1ab3ca9eb16544b651d (patch)
tree943a0bcb49c2f3fab753b3528e21c0e83403cf9e
parentdf0aec10d03cd0146add06a3ed51aed4e4273e45 (diff)
downloadview.love-e2e3aea2b1b9504bf849d1ab3ca9eb16544b651d.tar.gz
require editor margins to be ints
Not directly relevant here, but forks of this project that permit
zooming can run into weird glitches if margins are not a whole number of
pixels.

I'd always assumed a type system that divided ints into floats was
strictly superior, but now I have experienced a situation where
requiring ints isn't just a compromise for the underlying CPU
implementation. Particularly since Lua's print() silently hides really
tiny fractions.
-rw-r--r--Manual_tests.md3
-rw-r--r--edit.lua4
2 files changed, 5 insertions, 2 deletions
diff --git a/Manual_tests.md b/Manual_tests.md
index 358ea8b..cde027f 100644
--- a/Manual_tests.md
+++ b/Manual_tests.md
@@ -46,6 +46,9 @@ Lua is dynamically typed. Tests can't patch over lack of type-checking.
 * Like any high-level language, it's easy to accidentally alias two non-scalar
   variables. I wish there was a way to require copy when assigning.
 
+* I wish I could require pixel coordinates to integers. The editor defensively
+  converts input margins to integers.
+
 * My test harness automatically runs `test_*` methods -- but only at the
   top-level. I wish there was a way to raise warnings if someone defines such
   a function inside a dict somewhere.
diff --git a/edit.lua b/edit.lua
index 0a30c77..4945529 100644
--- a/edit.lua
+++ b/edit.lua
@@ -90,8 +90,8 @@ function edit.initialize_state(top, left, right, font_height, line_height)  -- c
     em = App.newText(love.graphics.getFont(), 'm'),  -- widest possible character width
 
     top = top,
-    left = left,
-    right = right,
+    left = math.floor(left),
+    right = math.floor(right),
     width = right-left,
 
     filename = love.filesystem.getUserDirectory()..'/lines.txt',  -- '/' should work even on Windows
2c97fb62c9f02f8e9d8bd'>^
1b717024 ^
95dbb68b ^
278cd9dd ^
95dbb68b ^


278cd9dd ^
95dbb68b ^







278cd9dd ^
95dbb68b ^
1b717024 ^
95dbb68b ^






1b717024 ^
95dbb68b ^





1b717024 ^
95dbb68b ^



















1b717024 ^
95dbb68b ^

1b717024 ^
95dbb68b ^





1b717024 ^
95dbb68b ^










1b717024 ^
95dbb68b ^
1b717024 ^
95dbb68b ^















1b717024 ^
95dbb68b ^




1b717024 ^
95dbb68b ^








1b717024 ^
95dbb68b ^






1b717024 ^

95dbb68b ^








7e620763 ^

95dbb68b ^
1b717024 ^
7e620763 ^










2429d23f ^
7e620763 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183