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