root/widgets/drop-list.r

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

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

Line 
1 drop-list: make rebface [
2         tip:    {
3                 USAGE:
4                         drop-list "1" data [1 2 3]
5                         drop-list data ["One" "Two" "Three"]
6                         drop-list data ctx-rebgui/locale*/colors
7
8                 DESCRIPTION:
9                         Single column modal selection list.
10                         At runtime face/text contains current selection.
11         }
12         size:   25x5
13         text:   ""
14         data:   []
15         edge:   outline-edge
16         font:   default-font
17         para:   make default-para [margin: as-pair sizes/slider + 2 2]
18         feel:   make default-feel [
19                 engage: make function! [face action event][
20                         face/pane/feel/engage face/pane action event
21                 ]
22         ]
23         action: make default-action [
24                 on-unfocus: make function! [face] [
25                         hide-popup
26                         face/hidden-text: face/hidden-caret: none
27                         true
28                         ;face/action face       ; causes problems when set-focus used from another widget to assign and then shift focus
29                 ]
30         ]
31         options:        [info]
32         hidden-caret: hidden-text: none
33         ;       Accessor functions
34         picked: make function! [] [
35                 index? find data text
36         ]
37         rebind: make function! [] [
38                 para/margin/x: sizes/line + 2
39         ]
40         init:   make function! [/local p] [
41                 unless block? data [gui-error "drop-list expected data block"]
42                 para: make para []      ; avoid shared para object for scrollable input widget
43                 p: self
44                 pane: make arrow [
45                         tip:    none
46                         offset: as-pair p/size/x - p/size/y + 1 1
47                         size:   as-pair p/size/y - 4 p/size/y - 4
48                         span:   if all [p/span find p/span #W] [#X]
49                         edge:   none
50                         action: make default-action [
51                                 on-click: make function! [face /filter-data fd [block!] /local data p v lines oft] [
52                                         unless filter-data [edit/unfocus]       ; unfocus if arrow pressed
53                                         p: face/parent-face
54                                         all [find p/options 'no-click exit]
55                                         data: either fd [fd] [p/data]
56                                         unless zero? lines: length? data [
57                                                 oft: either (lines * sizes/line) < (p/parent-face/size/y - p/offset/y - p/size/y) [
58                                                         ;       fits below
59                                                         p/offset + as-pair 0 p/size/y - 1
60                                                 ][
61                                                         either (lines * sizes/line) <= (p/parent-face/size/y - 4) [
62                                                                 ;       fits bottom
63                                                                 as-pair p/offset/x p/parent-face/size/y - 2 - (lines * sizes/line)
64                                                         ][
65                                                                 ;       align to bottom
66                                                                 as-pair p/offset/x p/parent-face/size/y - 2 - (sizes/line * to integer! p/parent-face/size/y / sizes/line)
67                                                         ]
68                                                 ]
69                                                 if v: choose p p/size/x oft data [
70                                                         p/text: form v
71                                                         p/hidden-text: p/hidden-caret: none
72                                                         p/action/on-click p
73                                                         either p/type = 'drop-list [show p edit/unfocus] [set-focus p]
74                                                 ]
75                                         ]
76                                 ]
77                         ]
78                 ]
79                 pane/init       ; draw arrow
80         ]
81 ]
Note: See TracBrowser for help on using the browser.