]> gitweb.factorcode.org Git - factor.git/blob - basis/ui/gadgets/line-support/line-support.factor
Disable font leading in line-support for now
[factor.git] / basis / ui / gadgets / line-support / line-support.factor
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
5 ui.render ui.text ;
6 IN: ui.gadgets.line-support
7
8 ! Some code shared by table and editor gadgets
9 SLOT: font
10
11 GENERIC: line-leading ( gadget -- n )
12
13 M: gadget line-leading font>> font-metrics leading>> ;
14
15 GENERIC: line-height ( gadget -- n )
16
17 M: gadget line-height font>> font-metrics height>> ;
18
19 : y>line ( y gadget -- n ) line-height /i ;
20
21 : line>y ( n gadget -- y ) line-height * ;
22
23 : validate-line ( m gadget -- n )
24     control-value [ drop f ] [ length 1- min 0 max ] if-empty ;
25
26 : visible-line ( gadget quot -- n )
27     '[
28         [ clip get @ origin get [ second ] bi@ - ] dip
29         y>line
30     ] keep validate-line ; inline
31
32 : first-visible-line ( gadget -- n )
33     [ loc>> ] visible-line ;
34
35 : last-visible-line ( gadget -- n )
36     [ [ loc>> ] [ dim>> ] bi v+ ] visible-line 1+ ;
37
38 : each-slice-index ( from to seq quot -- )
39     [ [ <slice> ] [ drop [a,b) ] 3bi ] dip 2each ; inline
40
41 GENERIC: draw-line ( line index gadget -- )
42
43 : draw-lines ( gadget -- )
44     {
45         [ first-visible-line ]
46         [ last-visible-line ]
47         [ control-value ]
48         [ line-height ]
49         [ ]
50     } cleave '[
51         0 over _ * 2array
52         [ _ draw-line ] with-translation
53     ] each-slice-index ;