root/widgets/spinner.r

Revision 112, 2.9 kB (checked in by ashley, 8 months ago)

Added pill.r
Scroller fixes
Major color / theme management changes (in progress)

Line 
1spinner: make rebface [
2        tip:    {
3                USAGE:
4                        spinner
5                        spinner options [$1 $10 $1] data $5
6
7                DESCRIPTION:
8                        Similar to a field, with arrows to increment/decrement a value by a nominated step amount.
9
10                OPTIONS:
11                        [min max step] block of minimum, maximum and step amounts
12        }
13        size:   20x5
14        text:   ""
15        edge:   theme-edge
16        font:   default-font-right
17        para:   make default-para []
18        feel:   edit/feel
19        options: [1 10 1] ; min, max, increment
20        pane:   copy []
21        action: make default-action [
22                on-scroll: make function! [face scroll /page] [
23                        face/text: either any [none? face/data page] [
24                                form data: either negative? scroll/y [second face/options] [first face/options]
25                        ][
26                                form face/data + either negative? scroll/y [last face/options] [negate last face/options]
27                        ]
28                        face/action/on-unfocus face
29                ]
30                on-unfocus: make function! [face] [
31                        either empty? face/text [
32                                face/data: none
33                        ][
34                                face/data: any [attempt [to type? first face/options face/text] face/data]
35                                face/text: either face/data [form face/data: min max face/data first face/options second face/options] [copy ""]
36                                show face
37                        ]
38                        face/action/on-click face
39                        true
40                ]
41        ]
42        init:   make function! [/local p] [
43                all [data text: form data]
44                all [not empty? text data: to type? first options text]
45                para/margin/x: size/y - sizes/cell
46                ;       make up & down button
47                p: self
48                insert pane make arrow [
49                        tip:    none
50                        offset: as-pair p/size/x - p/size/y + sizes/cell 0
51                        size:   as-pair p/size/y - sizes/cell p/size/y / 2
52                        span:   all [
53                                p/span
54                                case [
55                                        all [find p/span #L find p/span #W] [#OX]
56                                        find p/span #W [#X]
57                                        find p/span #L [#O]
58                                ]
59                        ]
60                        data:   'up
61                        edge:   none
62                        action: make default-action [
63                                on-click: make function! [face /local p] [
64                                        p: face/parent-face
65                                        p/data: any [attempt [to type? first p/options p/text] p/data first p/options]
66                                        p/data: p/data + third p/options
67                                        if p/data > second p/options [p/data: second p/options]
68                                        p/text: form p/data
69                                        edit/unlight-text
70                                        view*/caret: none
71                                        show p
72                                        p/action/on-click p
73                                ]
74                        ]
75                ]
76                pane/1/init
77                insert tail pane make arrow [
78                        tip:    none
79                        offset: as-pair p/size/x - p/size/y + sizes/cell p/size/y / 2
80                        size:   as-pair p/size/y - sizes/cell p/size/y / 2
81                        span:   all [
82                                p/span
83                                case [
84                                        all [find p/span #L find p/span #W] [#OX]
85                                        find p/span #W [#X]
86                                        find p/span #L [#O]
87                                ]
88                        ]
89                        edge:   none
90                        action: make default-action [
91                                on-click: make function! [face /local p] [
92                                        p: face/parent-face
93                                        p/data: any [attempt [to type? first p/options p/text] p/data first p/options]
94                                        p/data: p/data - third p/options
95                                        if p/data < first p/options [p/data: first p/options]
96                                        p/text: form p/data
97                                        edit/unlight-text
98                                        view*/caret: none
99                                        show p
100                                        p/action/on-click p
101                                ]
102                        ]
103                ]
104                pane/2/init
105        ]
106        esc:    none
107        caret:  none
108        undo:   copy []
109]
Note: See TracBrowser for help on using the browser.