Created
August 2, 2018 18:44
-
-
Save greggirwin/01bd4ea16fcc9458f531352cfdf6100f to your computer and use it in GitHub Desktop.
Red foreach-face examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
win: layout [ | |
title "VID test" | |
;below | |
text "Hello" | |
button "Hello" 100x40 [bar/data: random 100%] | |
button "World" | |
return | |
button "China" | |
text "Red Language" 100 right | |
field 120 on-enter [probe do face/text clear face/text] | |
return | |
group-box 3 [ | |
style but: button 25 font [name: "Comic Sans MS" size: 12 color: blue] | |
base 0.233.1.177 "ok" 25x25 | |
text "in panel" | |
but "A" but "B" but "C" | |
but "D" but "E" but "F" | |
] | |
tab-panel [ | |
"tab1" [at 10x10 base 0.2.233.188 15x15 at 50x50 button "one"] | |
"tab2" [at 80x10 text "two"] | |
] | |
below | |
slider 5% | |
pad 10x0 bar: progress 50% 130 | |
base 255.0.0.138 50x50 draw [fill-pen blue circle 25x25 15] | |
across | |
return middle | |
check "option 1" font-size 14 | |
check "option 2" font-color orange | |
radio "option 3" font-name "Times New Roman" | |
radio "option 4" | |
return top | |
list: text-list data ["one" "two" "three" "four"] ;[probe pick face/data event/selected] | |
drop-list data ["one" 4 "two" 5 "three" 6 "four" 7] | |
drop-down data ["one" "two" "three" "four"] | |
return | |
style but1: button | |
style txt1: text 30 | |
style base1: base 10x10 | |
but1 "1" txt1 "1" base1 "1" | |
return | |
group-box [ | |
style but1: but1 font-color red | |
style txt1: txt1 red center | |
style base1: base1 red | |
but1 "1" txt1 "1" base1 "1" | |
] return | |
but1 "1" txt1 "1" base1 "1" | |
at (list/offset + 130x50) base 5x5 red | |
do [append list/data "five"] | |
] | |
foreach-face/with win [probe reduce [face/text face/offset face/size]] [find face/text #"i"] | |
print "" | |
foreach-face/with win [probe reduce [face/text face/offset face/size]] [find face/text #"1"] | |
print "" | |
foreach-face win [probe face/type] | |
foreach-pane: function [ | |
"Evaluates body once per pane (not once per face) in a face tree" | |
face [object!] "Root face of the face tree" | |
body [block! function!] "Body block (`face` object) or function `func [face [object!]]`" | |
][ | |
foreach-face/with face body [block? face/pane] | |
] | |
print "" | |
foreach-pane win [print [face/type "at" face/offset "contains" length? face/pane "faces"]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Red [] | |
win: layout [ | |
across | |
button field return | |
button field return | |
button field return | |
] | |
rows: 3 | |
win/actors: object [ | |
on-resizing: function [face [object!] event [event!]][ | |
w: face | |
foreach-face/with win [face/size/x: w/size/x - face/offset/x - 10] [face/type = 'field] | |
y: w/size/y / rows | |
i: 0 | |
foreach-face win [ | |
face/size/y: y - 10 | |
face/offset/y: y * (i / 2) + 5 | |
i: i + 1 | |
] | |
] | |
] | |
view/flags win [resize] | |
;------------------------------------------------------------------------------- | |
win: layout [ | |
across | |
style area: area 200x50 | |
button area return | |
button area return | |
button area return | |
] | |
rows: 3 | |
win/actors: object [ | |
on-resizing: function [face [object!] event [event!]][ | |
w: face | |
foreach-face/with win [face/size/x: w/size/x - face/offset/x - 10] [face/type = 'area] | |
y: w/size/y / rows | |
i: 0 | |
foreach-face win [ | |
if face/type = 'area [face/size/y: y - 10] | |
face/offset/y: y * (i / 2) + 5 | |
i: i + 1 | |
] | |
] | |
] | |
view/flags win [resize] | |
;------------------------------------------------------------------------------- | |
pct-pair: func [pair pct /x /y][ | |
pair: as-pair pair/x * pct pair/y * pct | |
case [x pair/x y pair/y 'else pair] | |
] | |
;pct-pair 100x50 66% | |
;pct-pair/x 100x50 66% | |
;pct-pair/y 100x50 66% | |
org: 10x10 | |
spc: 8x8 | |
win: layout [ | |
across origin org | |
b-1: button extra [25%] f-1: field extra [75% b-1] return | |
b-2: button extra [50%] f-2: field extra [50% b-2] return | |
b-3: button extra [75%] f-3: field extra [25% b-3] return | |
] | |
rows: 3.0 | |
win/actors: object [ | |
on-resizing: function [face [object!] event [event!]][ | |
w: face | |
; Set widths (have to cast to integer manually right now) | |
foreach-face win [face/size/x: to integer! (w/size/x * face/extra/1 - org/x - spc/x)] | |
; Set X offsets for faces with an anchor face | |
foreach-face/with win [ | |
prev-face: get face/extra/2 | |
face/offset/x: prev-face/offset/x + prev-face/size/x + spc/x | |
] [face/extra/2] | |
; Set heights and Y offsets | |
y: to integer! w/size/y / rows | |
i: 0 | |
foreach-face win [ | |
face/size/y: y - org/y | |
face/offset/y: y * (i / 2) + 5 | |
i: i + 1 | |
] | |
] | |
] | |
view/flags win [resize] | |
;------------------------------------------------------------------------------- | |
win: layout [ | |
across | |
style text: text 50 | |
button text "Name:" field return | |
button text "Rank:" field return | |
button text "Ser #:" field return | |
] | |
rows: 3 | |
win/actors: object [ | |
on-resizing: function [face [object!] event [event!]][ | |
w: face ; reference to our window, to use in foreach-face | |
foreach-face/with win [face/size/x: w/size/x - face/offset/x - 10] [face/type = 'field] | |
] | |
] | |
view/flags win [resize] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment