Skip to content

Instantly share code, notes, and snippets.

@toomasv
Last active September 24, 2022 08:19
Show Gist options
  • Save toomasv/5fc2e81d4f0e1a507ac277a151ecd989 to your computer and use it in GitHub Desktop.
Save toomasv/5fc2e81d4f0e1a507ac277a151ecd989 to your computer and use it in GitHub Desktop.
Toy face-adder
Red []
move-faces: function [parent except inserted dim][
anti: select [x y x] dim
win: parent/parent
max-size: 0x0
last-size: parent/size
foreach-face/with parent [
sz: either face/offset = except/offset [
except/size/:dim + 10
][
inserted/size/:dim + 10
]
face/offset/:dim: face/offset/:dim + sz
max-size: max max-size face/offset + face/size
][
all [
face <> except
face/offset/:anti >= except/offset/:anti
face/offset/:anti <= (except/offset/:anti + inserted/size/:anti)
any [
face/offset = except/offset
face/offset/:dim > (except/offset/:dim + except/size/:dim)
]
]
]
parent/size: max parent/size max-size + 2
diff: parent/size - last-size
win/size: win/size + diff
pan/offset/y: win/size/y - pan/size/y - 10
]
add-face: function [face how reference name][
set name face
ofs: reference/offset
parent: reference/parent
append parent/pane face
face/offset: ofs
dim: pick [x y] to logic! find [before after] how
switch how [
below after [
move-faces parent reference face dim
]
above before [
move-faces parent face face dim
]
]
]
view [
below
p: panel 300x150 [
origin 2x2
b1: button "b1"
b2: button "b2" return
b3: button "b3"
b4: button "b4"
]
pan: panel [
origin 0x0
;row-col?: check "row/col"
spec: field 200 {'area ["world"] 'below b1 'w1} on-enter [
append face/text space
do head insert copy spec/data [
add-face make-face/spec
]
]
button "OK" [
do-actor spec none 'enter
]
]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment