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 : line-height ( gadget -- n )
12 font>> "" text-height ;
14 : y>line ( y gadget -- n )
17 : line>y ( n gadget -- y )
20 : validate-line ( m gadget -- n )
21 control-value [ drop f ] [ length 1- min 0 max ] if-empty ;
23 : visible-line ( gadget quot -- n )
25 [ clip get @ origin get [ second ] bi@ - ] dip
27 ] keep validate-line ; inline
29 : first-visible-line ( gadget -- n )
30 [ loc>> ] visible-line ;
32 : last-visible-line ( gadget -- n )
33 [ [ loc>> ] [ dim>> ] bi v+ ] visible-line 1+ ;
35 : each-slice-index ( from to seq quot -- )
36 [ [ <slice> ] [ drop [a,b) ] 3bi ] dip 2each ; inline
38 GENERIC: draw-line ( line index gadget -- )
40 : draw-lines ( gadget -- )
42 [ first-visible-line ]
49 [ _ draw-line ] with-translation