tab-panel: make rebface [ tip: { USAGE: tab-panel data ["A" [field] "B" [field] "C" [field]] tab-panel data ["1" [field] action [face/color: red] "2" [field]] DESCRIPTION: A panel with a set of tabs. Each tab spec may be preceded by an action block spec. OPTIONS: 'action do action of initial tab (if any) [tab n] where n specifies tab to initially open with (default 1) no-tabs do not display tabs (overlay mode) } size: -1x-1 pane: copy [] tabs: 0 ; ; Access functions ; selected: make function! [] [ either find options 'no-tabs [data] [pane/(tabs + data)/text] ] select-tab: make function! [num [integer!]] [ if any [num < 1 num > tabs] [exit] pane/:data/show?: false edit/unfocus either find options 'no-tabs [ pane/(data: num)/show?: true ][ pane/(tabs + data)/color: colors/theme-dark pane/(tabs + data)/font/color: colors/page pane/(data: num)/show?: true pane/(tabs + data)/color: colors/page pane/(tabs + data)/font/color: colors/text ] pane/(data)/action pane/:data show self ] replace-tab: make function! [num [integer!] block [block!] /title text [string!]] [ pane/:num: layout/only block pane/:num/offset: as-pair 0 either find options 'no-tabs [0] [sizes/line] pane/:num/color: colors/page pane/:num/edge: outline-edge all [title pane/(tabs + num)/text: text] if data <> num [pane/:num/show?: false] show self ] ; ; Init ; init: make function! [/local tab tab-offset trigger] [ tab-offset: 0x0 foreach [title spec] data [ either title = 'action [ trigger: spec ][ ; tab number tabs: tabs + 1 ; insert panel tab: layout/only spec tab/offset/y: either find options 'no-tabs [0] [sizes/line] tab/color: colors/page tab/edge: outline-edge tab/show?: false tab/span: #LV tab/action: either trigger [make function! [face /local var] trigger] [none] insert at pane tabs tab ; insert tab unless find options 'no-tabs [ insert tail pane make subface [ offset: tab-offset size: as-pair 1 sizes/line + 1 text: title effect: reduce ['round colors/outline-light effects/radius sizes/edge] data: tabs color: colors/theme-dark font: make default-font [color: colors/page align: 'center] para: default-para feel: make default-feel [ over: make function! [face act pos] [ face/color: either act [colors/theme-light] [ either face/data = face/parent-face/data [colors/page] [colors/theme-dark] ] show face ] engage: make function! [face act event /local p] [ all [find [down alt-down] act face/parent-face/select-tab face/data] ] ] ] tab: last pane tab/size/x: sizes/line + first size-text tab ; set tab title width tab-offset/x: tab-offset/x + tab/size/x + 2 ; set offset for next tab title ] trigger: none ] ] ; auto size adjustments all [ negative? size/x repeat i tabs [size/x: max size/x pane/:i/size/x] ] all [ negative? size/y repeat i tabs [size/y: max size/y pane/:i/size/y] size/y: size/y + either find options 'no-tabs [0] [sizes/line] ] ; set tab sizes repeat i tabs [ all [span find span #H insert pane/:i/span #H] all [span find span #W insert pane/:i/span #W] ] ; show selected tab pane/(data: any [select options 'tab 1])/show?: true unless find options 'no-tabs [select-tab data] ;pane/(tabs + data)/color: colors/page] all [find options 'action pane/(data)/action pane/:data] ] ]