1 ! Copyright (C) 2006, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel math math.functions math.parser models
4 models.filter models.range models.compose sequences ui
5 ui.gadgets ui.gadgets.frames ui.gadgets.labels ui.gadgets.packs
6 ui.gadgets.sliders ui.render math.geometry.rect accessors
7 ui.gadgets.grids colors ;
10 ! Simple example demonstrating the use of models.
12 : <color-slider> ( model -- gadget )
15 TUPLE: color-preview < gadget ;
17 : <color-preview> ( model -- gadget )
18 color-preview new-gadget
22 M: color-preview model-changed
23 swap value>> >>interior relayout-1 ;
25 : <color-model> ( model -- model )
26 [ first3 [ 256 /f ] tri@ 1 <rgba> <solid> ] <filter> ;
28 : <color-sliders> ( -- model gadget )
29 3 [ 0 0 0 255 <range> ] replicate
30 dup [ range-model ] map <compose>
34 [ <color-slider> add-gadget ] each ;
36 : <color-picker> ( -- gadget )
41 [ <color-model> <color-preview> @center grid-add ]
43 [ [ truncate number>string ] map " " join ] <filter> <label-control>
48 : color-picker-window ( -- )
49 [ <color-picker> "Color Picker" open-window ] with-ui ;
51 MAIN: color-picker-window