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-height ( gadget -- n )
13 M: gadget line-height font>> "" text-height ;
15 : y>line ( y gadget -- n )
18 : line>y ( n gadget -- y )
21 : validate-line ( m gadget -- n )
22 control-value [ drop f ] [ length 1- min 0 max ] if-empty ;
24 : visible-line ( gadget quot -- n )
26 [ clip get @ origin get [ second ] bi@ - ] dip
28 ] keep validate-line ; inline
30 : first-visible-line ( gadget -- n )
31 [ loc>> ] visible-line ;
33 : last-visible-line ( gadget -- n )
34 [ [ loc>> ] [ dim>> ] bi v+ ] visible-line 1+ ;
36 : each-slice-index ( from to seq quot -- )
37 [ [ <slice> ] [ drop [a,b) ] 3bi ] dip 2each ; inline
39 GENERIC: draw-line ( line index gadget -- )
41 : draw-lines ( gadget -- )
43 [ first-visible-line ]
50 [ _ draw-line ] with-translation