root/widgets/tab-panel.r

Revision 112, 3.6 kB (checked in by ashley, 10 months ago)

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

Line 
1tab-panel: make rebface [
2        tip:    {
3                USAGE:
4                        tab-panel data ["A" [field] "B" [field] "C" [field]]
5                        tab-panel data ["1" [field] action [face/color: red] "2" [field]]
6
7                DESCRIPTION:
8                        A panel with a set of tabs.
9                        Each tab spec may be preceded by an action block spec.
10
11                OPTIONS:
12                        'action do action of initial tab (if any)
13                        [tab n] where n specifies tab to initially open with (default 1)
14                        no-tabs do not display tabs (overlay mode)
15        }
16        size:   -1x-1
17        pane:   copy []
18        tabs:   0
19        ;
20        ;       Access functions
21        ;
22        selected: make function! [] [
23                either find options 'no-tabs [data] [pane/(tabs + data)/text]
24        ]
25        select-tab: make function! [num [integer!]] [
26                if any [num < 1 num > tabs] [exit]
27                pane/:data/show?: false
28                edit/unfocus
29                either find options 'no-tabs [
30                        pane/(data: num)/show?: true
31                ][
32                        pane/(tabs + data)/color: colors/theme-dark
33                        pane/(tabs + data)/font/color: colors/page
34                        pane/(data: num)/show?: true
35                        pane/(tabs + data)/color: colors/page
36                        pane/(tabs + data)/font/color: colors/text
37                ]
38                pane/(data)/action pane/:data
39                show self
40        ]
41        replace-tab: make function! [num [integer!] block [block!] /title text [string!]] [
42                pane/:num: layout/only block
43                pane/:num/offset: as-pair 0 either find options 'no-tabs [0] [sizes/line]
44                pane/:num/color: colors/page
45                pane/:num/edge: outline-edge
46                all [title pane/(tabs + num)/text: text]
47                if data <> num [pane/:num/show?: false]
48                show self
49        ]
50        ;
51        ;       Init
52        ;
53        init:   make function! [/local tab tab-offset trigger] [
54                tab-offset: 0x0
55                foreach [title spec] data [
56                        either title = 'action [
57                                trigger: spec
58                        ][
59                                ;       tab number
60                                tabs: tabs + 1
61                                ;       insert panel
62                                tab:                    layout/only spec
63                                tab/offset/y:   either find options 'no-tabs [0] [sizes/line]
64                                tab/color:              colors/page
65                                tab/edge:               outline-edge
66                                tab/show?:              false
67                                tab/span:               #LV
68                                tab/action:             either trigger [make function! [face /local var] trigger] [none]
69                                insert at pane tabs tab
70                                ;       insert tab
71                                unless find options 'no-tabs [
72                                        insert tail pane make subface [
73                                                offset: tab-offset
74                                                size:   as-pair 1 sizes/line + 1
75                                                text:   title
76                                                effect: reduce ['round colors/outline-light effects/radius sizes/edge]
77                                                data:   tabs
78                                                color:  colors/theme-dark
79                                                font:   make default-font [color: colors/page align: 'center]
80                                                para:   default-para
81                                                feel:   make default-feel [
82                                                        over: make function! [face act pos] [
83                                                                face/color: either act [colors/theme-light] [
84                                                                        either face/data = face/parent-face/data [colors/page] [colors/theme-dark]
85                                                                ]
86                                                                show face
87                                                        ]
88                                                        engage: make function! [face act event /local p] [
89                                                                all [find [down alt-down] act face/parent-face/select-tab face/data]
90                                                        ]
91                                                ]
92                                        ]
93                                        tab: last pane
94                                        tab/size/x: sizes/line + first size-text tab    ; set tab title width
95                                        tab-offset/x: tab-offset/x + tab/size/x + 2             ; set offset for next tab title
96                                ]
97                                trigger: none
98                        ]
99                ]
100                ;       auto size adjustments
101                all [
102                        negative? size/x
103                        repeat i tabs [size/x: max size/x pane/:i/size/x]
104                ]
105                all [
106                        negative? size/y
107                        repeat i tabs [size/y: max size/y pane/:i/size/y]
108                        size/y: size/y + either find options 'no-tabs [0] [sizes/line]
109                ]
110                ;       set tab sizes
111                repeat i tabs [
112                        all [span find span #H insert pane/:i/span #H]
113                        all [span find span #W insert pane/:i/span #W]
114                ]
115                ;       show selected tab
116                pane/(data: any [select options 'tab 1])/show?: true
117                unless find options 'no-tabs [select-tab data] ;pane/(tabs + data)/color: colors/page]
118                all [find options 'action pane/(data)/action pane/:data]
119        ]
120]
Note: See TracBrowser for help on using the browser.