GENERIC: line-height ( gadget -- n )
-M: line-gadget line-height font>> font-metrics height>> ;
+M: line-gadget line-height font>> font-metrics height>> ceiling ;
: y>line ( y gadget -- n ) line-height /i ;
: line>y ( n gadget -- y ) line-height * >integer ;
: validate-line ( m gadget -- n )
- control-value [ drop f ] [ length 1- min 0 max ] if-empty ;
+ control-value [ drop f ] [ length 1 - min 0 max ] if-empty ;
+
+: valid-line? ( n gadget -- ? )
+ control-value length 1 - 0 swap between? ;
: visible-line ( gadget quot -- n )
'[
[ loc>> ] visible-line ;
: last-visible-line ( gadget -- n )
- [ [ loc>> ] [ dim>> ] bi v+ ] visible-line 1+ ;
+ [ [ loc>> ] [ dim>> ] bi v+ ] visible-line 1 + ;
: each-slice-index ( from to seq quot -- )
[ [ <slice> ] [ drop [a,b) ] 3bi ] dip 2each ; inline
[ -1/0. or * ] [ 1/.0 or * ] bi-curry* bi
[ max ] [ min ] bi* ;
+: em ( font -- x ) "m" text-width ;
+
+PRIVATE>
+
: line-gadget-width ( pref-dim gadget -- w )
- [ first ] [ [ font>> "m" text-width ] [ min-cols>> ] [ max-cols>> ] tri ] bi* clamp ;
+ [ first ] [ [ font>> em ] [ min-cols>> ] [ max-cols>> ] tri ] bi* clamp ;
: line-gadget-height ( pref-dim gadget -- h )
[ second ] [ [ line-height ] [ min-rows>> ] [ max-rows>> ] tri ] bi* clamp ;
-PRIVATE>
-
M: line-gadget pref-viewport-dim
[ pref-dim ] keep
[ line-gadget-width ]
2bi 2array ;
: visible-lines ( gadget -- n )
- [ visible-dim second ] [ line-height ] bi /i 1- ;
\ No newline at end of file
+ [ visible-dim second ] [ line-height ] bi /i ;