Last active
March 22, 2018 04:18
-
-
Save dockimbel/c4ec0145e3a8ba776e05b4895a8d8733 to your computer and use it in GitHub Desktop.
Save and reload a View face tree
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 [ | |
Purpose: "Demo how to serialize/deserialize a face tree on disk" | |
] | |
mold-face: function [root [object!] return: [string!]][ | |
foreach-face root [ | |
face/parent: none face/state: none | |
if font: face/font [font/parent: none font/state: none] | |
if para: face/para [para/parent: none] | |
] | |
root/parent: root/state: none | |
if root/type = 'window [root/selected: none] | |
mold root | |
] | |
load-face: function [root [string! file! url! object!]][ | |
unless object? root [root: do load root] | |
if block? pane: root/pane [ | |
foreach f root/pane: reduce pane [load-face f] | |
] | |
root | |
] | |
;---- Usage example ---- | |
view lay: layout [button "ok" text "hello" panel [text "nested"]] | |
;-- Saving a cleaned-up face tree on disk | |
write %faces.red mold-face lay | |
;-- Loading a face tree from disk and displaying it | |
view load-face %faces.red |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment