@@ -154,19 +154,47 @@ impl EditorView {
154
154
} ;
155
155
156
156
let lines_count = lines. len ( ) ;
157
- let longest_line_length = longest_left. max ( longest_center) ;
158
157
159
- if longest_line_length as u16 > view. area . width || lines_count as u16 >= view. area . height {
158
+ let y_start = view. area . y + ( view. area . height / 2 ) . saturating_sub ( lines_count as u16 / 2 ) ;
159
+ let y_center = view. area . x + view. area . width / 2 ;
160
+
161
+ // max valid padding where the text does not overflow
162
+ let max_padding = view. area . width as i16
163
+ - longest_left as i16
164
+ - view. area . x as i16
165
+ - view. area . width as i16 / 2
166
+ + longest_left as i16 / 2 ;
167
+
168
+ // Despite being in the mathematical left, we want to start drawing the "left"
169
+ // lines a little bit extra to the right so it looks good
170
+ //
171
+ // this is because of text density: at the start the text density is high, but
172
+ // towards the end it is low. Therefore to achieve an optical balance we must
173
+ // do a little offset
174
+ //
175
+ // this padding of 4 is not cruicial though, so if we can't fit it on the screen
176
+ // we just decrease it until it is 0. Once that happens, if it still overflows
177
+ // we don't want to draw the welcome screen.
178
+ let padding = 4 . min ( max_padding. max ( 0 ) as u16 ) ;
179
+
180
+ let x_start_left =
181
+ padding + view. area . x + ( view. area . width / 2 ) . saturating_sub ( longest_left as u16 / 2 ) ;
182
+
183
+ let has_x_overflow = ( ( x_start_left + longest_left as u16 ) > view. area . width )
184
+ || longest_center as u16 > view. area . width ;
185
+
186
+ // we want lines_count < view.area.height so it does not get drawn
187
+ // over the status line
188
+ let has_y_overflow = lines_count as u16 >= view. area . height ;
189
+
190
+ if has_x_overflow || has_y_overflow {
160
191
return ;
161
192
}
162
193
163
- let y_start = view. area . y + view. area . height / 2 - lines_count as u16 / 2 ;
164
- let x_start_left = view. area . x + view. area . width / 2 - longest_left as u16 / 2 ;
165
-
166
194
for ( lines_drawn, ( line, align) ) in lines. iter ( ) . enumerate ( ) {
167
195
let x = match align {
168
- Align :: Left => x_start_left + 4 ,
169
- Align :: Center => view . area . x + view . area . width / 2 - line. width ( ) as u16 / 2 ,
196
+ Align :: Left => x_start_left,
197
+ Align :: Center => y_center - line. width ( ) as u16 / 2 ,
170
198
} ;
171
199
surface. set_spans ( x, y_start + lines_drawn as u16 , line, line. width ( ) as u16 ) ;
172
200
}
0 commit comments