| 1 | radio-group: make rebface [
|
|---|
| 2 | tip: {
|
|---|
| 3 | USAGE:
|
|---|
| 4 | radio-group data ["Option A" "Option B"]
|
|---|
| 5 | radio-group data [2 "On" "Off"]
|
|---|
| 6 |
|
|---|
| 7 | DESCRIPTION:
|
|---|
| 8 | Group of mutually exclusive radio buttons.
|
|---|
| 9 | Alignment is vertical unless height is specified as line height.
|
|---|
| 10 | An integer provided as the first entry in the block indicates the default selection.
|
|---|
| 11 | }
|
|---|
| 12 | size: 50x-1
|
|---|
| 13 | pane: []
|
|---|
| 14 | picked: none
|
|---|
| 15 | selected: make function! [] [
|
|---|
| 16 | all [picked pick data picked]
|
|---|
| 17 | ]
|
|---|
| 18 | select-item: make function! [item [integer! none!]] [
|
|---|
| 19 | either any [none? item zero? item] [
|
|---|
| 20 | item: either picked = 1 [2] [1]
|
|---|
| 21 | pane/:item/feel/engage/reset pane/:item 'down none
|
|---|
| 22 | ][
|
|---|
| 23 | all [item <> picked pane/:item/feel/engage pane/:item 'down none]
|
|---|
| 24 | ]
|
|---|
| 25 | ]
|
|---|
| 26 | init: make function! [/local off siz pos index] [
|
|---|
| 27 | ; picked?
|
|---|
| 28 | unless string? first data: reduce data [
|
|---|
| 29 | picked: first data
|
|---|
| 30 | remove data
|
|---|
| 31 | ]
|
|---|
| 32 | ; vertical or horizontal?
|
|---|
| 33 | all [negative? size/y size/y: sizes/line * length? data]
|
|---|
| 34 | off: either size/y > sizes/line [
|
|---|
| 35 | siz: as-pair size/x sizes/line
|
|---|
| 36 | as-pair 0 sizes/line
|
|---|
| 37 | ][
|
|---|
| 38 | siz: as-pair size/x / length? data sizes/line
|
|---|
| 39 | as-pair siz/x 0
|
|---|
| 40 | ]
|
|---|
| 41 | ; insert labels
|
|---|
| 42 | pos: 0x0
|
|---|
| 43 | index: 1
|
|---|
| 44 | foreach label data [
|
|---|
| 45 | insert tail pane make subface [
|
|---|
| 46 | offset: pos
|
|---|
| 47 | size: siz
|
|---|
| 48 | text: label
|
|---|
| 49 | effect: compose/deep [draw [pen (colors/outline-light) fill-pen (colors/page) circle (as-pair sizes/cell * 1.5 sizes/cell * 2.5) (sizes/cell * 1.5)]]
|
|---|
| 50 | data: index
|
|---|
| 51 | font: default-font
|
|---|
| 52 | para: default-para-indented
|
|---|
| 53 | feel: make default-feel [
|
|---|
| 54 | over: make function! [face act pos] [
|
|---|
| 55 | face/effect/draw/pen: either act [colors/outline-dark] [colors/outline-light]
|
|---|
| 56 | show face
|
|---|
| 57 | ]
|
|---|
| 58 | engage: make function! [face act event /reset /local pf] [
|
|---|
| 59 | do select [
|
|---|
| 60 | down [
|
|---|
| 61 | if all [pf: face/parent-face pf/picked <> face/data] [
|
|---|
| 62 | ; deflag old
|
|---|
| 63 | all [
|
|---|
| 64 | pf/picked
|
|---|
| 65 | clear skip pf/pane/(pf/picked)/effect/draw 7
|
|---|
| 66 | show pf/pane/(pf/picked)
|
|---|
| 67 | ]
|
|---|
| 68 | either reset [pf/picked: none] [
|
|---|
| 69 | ; flag new
|
|---|
| 70 | pf/picked: face/data
|
|---|
| 71 | insert tail face/effect/draw reduce [
|
|---|
| 72 | 'pen colors/state-dark 'fill-pen colors/state-dark 'circle as-pair sizes/cell * 1.5 sizes/cell * 2.5 sizes/cell - 1
|
|---|
| 73 | ]
|
|---|
| 74 | show face
|
|---|
| 75 | pf/action/on-click pf
|
|---|
| 76 | ]
|
|---|
| 77 | ]
|
|---|
| 78 | ]
|
|---|
| 79 | away [face/feel/over face false 0x0]
|
|---|
| 80 | ] act
|
|---|
| 81 | ]
|
|---|
| 82 | ]
|
|---|
| 83 | ]
|
|---|
| 84 | pos: pos + off
|
|---|
| 85 | index: index + 1
|
|---|
| 86 | ]
|
|---|
| 87 | ; initial selection
|
|---|
| 88 | all [
|
|---|
| 89 | integer? picked
|
|---|
| 90 | insert tail pane/:picked/effect/draw reduce [
|
|---|
| 91 | 'pen colors/state-dark 'fill-pen colors/state-dark 'circle as-pair sizes/cell * 1.5 sizes/cell * 2.5 sizes/cell - 1
|
|---|
| 92 | ]
|
|---|
| 93 | ]
|
|---|
| 94 | ]
|
|---|
| 95 | ] |
|---|