]> gitweb.factorcode.org Git - factor.git/blob - basis/ui/gadgets/line-support/line-support.factor
Merge branch 'master' into new_ui
[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 : line-height ( gadget -- n )
12     font>> "" text-height ;
13
14 : y>line ( y gadget -- n )
15     line-height /i ;
16
17 : line>y ( n gadget -- y )
18     line-height * ;
19
20 : validate-line ( m gadget -- n )
21     control-value [ drop f ] [ length 1- min 0 max ] if-empty ;
22
23 : visible-line ( gadget quot -- n )
24     '[
25         [ clip get @ origin get [ second ] bi@ - ] dip
26         y>line
27     ] keep validate-line ; inline
28
29 : first-visible-line ( gadget -- n )
30     [ loc>> ] visible-line ;
31
32 : last-visible-line ( gadget -- n )
33     [ [ loc>> ] [ dim>> ] bi v+ ] visible-line 1+ ;
34
35 : each-slice-index ( from to seq quot -- )
36     [ [ <slice> ] [ drop [a,b) ] 3bi ] dip 2each ; inline
37
38 GENERIC: draw-line ( line index gadget -- )
39
40 : draw-lines ( gadget -- )
41     {
42         [ first-visible-line ]
43         [ last-visible-line ]
44         [ control-value ]
45         [ line-height ]
46         [ ]
47     } cleave '[
48         0 over _ * 2array
49         [ _ draw-line ] with-translation
50     ] each-slice-index ;