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.functions 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 ) line-height /i ;
21 : line>y ( n gadget -- y ) line-height * >integer ;
23 : validate-line ( m gadget -- n )
24 control-value [ drop f ] [ length 1- min 0 max ] if-empty ;
26 : visible-line ( gadget quot -- n )
28 [ clip get @ origin get [ second ] bi@ - ] dip
30 ] keep validate-line ; inline
32 : first-visible-line ( gadget -- n )
33 [ loc>> ] visible-line ;
35 : last-visible-line ( gadget -- n )
36 [ [ loc>> ] [ dim>> ] bi v+ ] visible-line 1+ ;
38 : each-slice-index ( from to seq quot -- )
39 [ [ <slice> ] [ drop [a,b) ] 3bi ] dip 2each ; inline
41 GENERIC: draw-line ( line index gadget -- )
43 : draw-lines ( gadget -- )
45 [ first-visible-line ]
51 0 over _ * >integer 2array
52 [ _ draw-line ] with-translation