1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays combinators fry kernel math math.order
4 math.ranges math.vectors namespaces opengl sequences ui.gadgets
6 IN: ui.gadgets.line-support
8 ! Some code shared by table and editor gadgets
11 GENERIC: line-leading ( gadget -- n )
13 M: gadget line-leading font>> font-metrics leading>> ;
15 GENERIC: line-height ( gadget -- n )
17 M: gadget line-height font>> font-metrics height>> ;
19 : y>line ( y gadget -- n )
20 [ line-leading ] [ line-height ] bi
21 [ [ - ] keep ] dip + /i ;
23 : line>y ( n gadget -- y )
24 [ line-height ] [ line-leading ] bi
27 : validate-line ( m gadget -- n )
28 control-value [ drop f ] [ length 1- min 0 max ] if-empty ;
30 : visible-line ( gadget quot -- n )
32 [ clip get @ origin get [ second ] bi@ - ] dip
34 ] keep validate-line ; inline
36 : first-visible-line ( gadget -- n )
37 [ loc>> ] visible-line ;
39 : last-visible-line ( gadget -- n )
40 [ [ loc>> ] [ dim>> ] bi v+ ] visible-line 1+ ;
42 : each-slice-index ( from to seq quot -- )
43 [ [ <slice> ] [ drop [a,b) ] 3bi ] dip 2each ; inline
45 GENERIC: draw-line ( line index gadget -- )
47 : draw-lines ( gadget -- )
49 [ first-visible-line ]
52 [ [ line-leading ] [ line-height ] bi + ]
56 [ _ draw-line ] with-translation