Created
July 28, 2023 19:03
-
-
Save greggirwin/8e464dfcb859c92cf9706927244bf004 to your computer and use it in GitHub Desktop.
Associate set-words in a VID spec with a map, rather than globally.
This file contains hidden or 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 [] | |
;styles: keys-of system/view/vid/styles | |
style-name: [ | |
'base | 'button | 'text | 'field | 'area | 'rich-text | 'toggle | |
| 'check | 'radio | 'progress | 'slider | 'scroller | 'camera | |
| 'calendar | 'text-list | 'drop-list | 'drop-down | 'panel | |
| 'group-box | 'tab-panel | 'h1 | 'h2 | 'h3 | 'h4 | 'h5 | 'box | |
| 'image | |
] | |
make-assigner: function [ | |
ctx-name [word!] | |
face-name [any-word!] | |
][ | |
; All on one line here so there is no new-line marker before 'on-create when we insert it. | |
compose/deep [on-create [(to set-path! reduce [ctx-name to word! face-name]) face]] | |
] | |
map-view-spec: function [ | |
"Pre-process a layout, associating set-words in it to a map." | |
spec [block!] "VID layout spec; WND will refer to the root of the face tree in ctx-name." | |
ctx-name [word!] "Context name (refers to map) for face refs." | |
][ | |
spec: copy/deep spec | |
insert spec compose/deep [ | |
on-create [(to set-word! ctx-name) copy #()] | |
on-created [(to set-path! reduce [ctx-name 'wnd]) face] | |
] | |
parse spec [ | |
any [ | |
pos-1: set w set-word! style-name pos-2: | |
(insert pos-2 make-assigner ctx-name w) | |
( | |
if new-line? pos-1 [new-line next pos-1 on] ; Don't throw away new-line marker if it's there. | |
remove pos-1 ; remove after inserting, so pos-2 not messed with. | |
) | |
| skip | |
] | |
] | |
spec | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment