1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors colors combinators combinators.smart formatting
4 kernel literals math math.functions models sorting.human
5 sorting.slots strings ui ui.gadgets.scrollers
6 ui.gadgets.search-tables ui.gadgets.tables ;
9 ! ui.gadgets.tables demo
10 SINGLETON: color-renderer
14 CONSTANT: full-block-string $[ 10 CHAR: full-block <string> ]
16 : rgba>hex ( rgba -- hex )
17 [ red>> ] [ green>> ] [ blue>> ] tri
18 [ 255 * round >integer ] tri@ "%02X%02X%02X" sprintf ;
22 M: color-renderer filled-column
25 M: color-renderer column-titles
26 drop { "Color" "Name" "Red" "Green" "Blue" "Hex" } ;
28 M: color-renderer row-columns
30 full-block-string swap
32 [ red>> "%.5f" sprintf ]
33 [ green>> "%.5f" sprintf ]
34 [ blue>> "%.5f" sprintf ]
39 M: color-renderer row-color
42 M: color-renderer row-value
45 : <color-table> ( -- table )
46 named-colors { human<=> } sort-by <model>
48 [ ] <search-table> dup table>>
50 COLOR: dark-gray >>column-line-color
54 MAIN-WINDOW: color-table-demo { { title "Colors" } { pref-dim { 500 300 } } }
55 <color-table> <scroller> >>gadgets ;