Skip to content

Instantly share code, notes, and snippets.

@dockimbel
Last active March 22, 2018 04:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dockimbel/c4ec0145e3a8ba776e05b4895a8d8733 to your computer and use it in GitHub Desktop.
Save dockimbel/c4ec0145e3a8ba776e05b4895a8d8733 to your computer and use it in GitHub Desktop.
Save and reload a View face tree
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