Skip to content

Instantly share code, notes, and snippets.

@GiuseppeChillemi
Last active August 17, 2023 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GiuseppeChillemi/c51a20ef17d4b659671e612800e12e9e to your computer and use it in GitHub Desktop.
Save GiuseppeChillemi/c51a20ef17d4b659671e612800e12e9e to your computer and use it in GitHub Desktop.
New SPACE MOLD save test
This code:
view [
host [
vlist [
bt: button "Press meee I am space!"
gr: grid-view source= table-data2 size 400x300 on-created [probe gr save %new-mold.txt gr]
with [
grid/widths: #(default 150)
grid/heights: #(default 20)
grid/pinned: 0x1
]
]
]
]
;--------------------------------
;Is it correct this SAVE output? Once loaded I see:
;1) No object container-
;2) The last CACHED is without square brackets
;--------------------------------
on-change*: func [word [any-word!] old [any-type!] new [any-type!]] [
on-change-dispatch 'grid-view self word :old :new
]
type: grid-view
size: 0x0
parent: none
draw: func [/on canvas [pair!] fill-x [logic!] fill-y [logic!]] [~/draw self canvas fill-x fill-y]
cache: [size map]
cached: []
limits: object [
min: 400x300
max: 400x300
]
origin: 0x0
weight: 1
content: object [
on-change*: func [word [any-word!] old [any-type!] new [any-type!]] [
on-change-dispatch 'window self word :old :new
]
type: window
size: 0x0
parent: none
draw: func [/on canvas [pair!] fill-x [logic!] fill-y [logic!]] [~/draw self canvas fill-x fill-y]
cache: none
cached: []
limits: none
pages: 10x10
origin: 0x0
content: object [
on-change*: func [word [any-word!] old [any-type!] new [any-type!]] [
on-change-dispatch 'grid self word :old :new
]
type: grid
size: none
parent: none
draw: func [/on canvas [pair!] fill-x [logic!] fill-y [logic!] /window xy1 [none! pair!] xy2 [none! pair!]] [
~/draw self canvas fill-x fill-y xy1 xy2
]
cache: []
cached: []
limits: none
kit: object [
format: func [] [~/format space]
do-batch: func ["(Generated) Evaluate plan for given space" space [object!] plan [block!]] [
do with self copy plan
]
]
margin: 5x5
spacing: 5x5
origin: 0x0
content: #()
spans: #()
widths: #(
default: 150
)
heights: #(
default: 20
)
autofit: area-total
pinned: 0x1
bounds: func [] [grid/cells/size]
frame: object [
canvas: none
bounds: none
heights: #()
cells: hash []
limits: []
invalid: []
]
on-invalidate: func [
grid [object!]
cell [none! object!]
scope [none! word!]
] [
repend grid/frame/invalid [cell scope]
cache/invalidate grid
]
map: []
wrap-space: func [xy [pair!] space [object!] /local pos] [
pos: any [find frame/cells xy tail frame/cells]
rechange pos [xy space]
space
]
cells: func [/pick xy [pair!] /size] [
either pick [
any [
grid/content/:xy
grid/content/:xy: grid/wrap-space xy wrap-data data/pick xy
]
] [data/size]
]
into: func [xy [pair!] /force child [object! none!]] [~/into self xy child]
get-span: func [
"Get the span value of a cell at XY"
xy [pair!] "Column (x) and row (y)"
] [
any [spans/:xy 1x1]
]
get-first-cell: func [
{Get the starting row & column of a multicell that occupies cell at XY}
xy [pair!] {Column (x) and row (y); returns XY unchanged if no such multicell} /local span
] [
span: get-span xy
if span +< 1x1 [xy: xy + span]
xy
]
set-span: func [
{Set the SPAN of a FIRST cell, breaking it if needed}
cell1 [pair!] {Starting cell of a multicell or normal cell that should become a multicell}
span [pair!] {1x1 for normal cell, more to span multiple rows/columns}
/force {Also break all multicells that intersect with the given area}
] [
~/set-span self cell1 span force
]
get-offset-from: func [
{Get pixel offset of left top corner of cell C2 from that of C1}
c1 [pair!] c2 [pair!]
] [
~/get-offset-from self c1 c2
]
locate-point: func [
{Map XY point on a grid into a cell it lands on, return [cell-xy offset]}
xy [pair!]
/screen "Point is on rendered viewport, not on the grid"
] [
~/locate-point self xy screen
]
row-height?: func [
"Get height of row Y (only calculate if necessary)"
y [integer!]
] [
~/row-height? self y
]
col-width?: func [
"Get width of column X"
x [integer!]
] [
any [widths/:x widths/default]
]
cell-size?: func [
{Get the size of a cell XY or a multi-cell starting at XY (with the spaces)}
xy [pair!]
] [
~/cell-size? self xy
]
is-cell-pinned?: func [
"Check if XY is within pinned row or column"
xy [pair!]
] [
not pinned +< xy
]
infinite?: func ["True if not all grid dimensions are finite" /local bounds] [
bounds: self/bounds
not all [bounds/x bounds/y]
]
calc-bounds: func [] [grid/cells/size]
available?: func [axis [word!] dir [integer!] from [integer!] requested [integer!]] [
~/available? self axis dir from requested
]
invalidate-range: func [xy1 [pair!] xy2 [pair!]] [
xyloop xy xy2 - xy1 + 1 [
remove/key grid/content xy + xy1 - 1
]
invalidate self
]
]
map: []
available?: func [
{Returns number of pixels up to REQUESTED from AXIS=FROM in direction DIR}
axis [word!] "x/y"
dir [integer!] "-1/1"
from [integer!] "axis coordinate to look ahead from"
requested [integer!] "max look-ahead required"
] [
~/available? self axis dir from requested
]
]
content-flow: planar
hscroll: object [
on-change*: func [word [any-word!] old [any-type!] new [any-type!]] [
on-change-dispatch 'scrollbar self word :old :new
]
type: hscroll
size: 100x16
parent: none
draw: func [] [~/draw self]
cache: [size map]
cached: []
limits: none
axis: x
offset: 0%
amount: 100%
arrow-size: 90%
map: []
back-arrow: object [
on-change*: func [word [any-word!] old [any-type!] new [any-type!]] [
on-change-dispatch 'triangle self word :old :new
]
type: back-arrow
size: 16x10
parent: none
draw: func [] [~/draw self]
cache: [size]
cached: []
limits: none
dir: w
margin: 2x2
]
back-page: object [
on-change*: func [word [any-word!] old [any-type!] new [any-type!]] [
on-change-dispatch 'rectangle self word :old :new
]
type: back-page
size: 20x10
parent: none
draw: func [] [[]]
cache: [size]
cached: []
limits: none
margin: 0x0
]
thumb: object [
on-change*: func [word [any-word!] old [any-type!] new [any-type!]] [
on-change-dispatch 'rectangle self word :old :new
]
type: thumb
size: 20x10
parent: none
draw: func [] [compose [box (margin) (size - margin)]]
cache: [size]
cached: []
limits: none
margin: 2x1
]
forth-page: object [
on-change*: func [word [any-word!] old [any-type!] new [any-type!]] [
on-change-dispatch 'rectangle self word :old :new
]
type: forth-page
size: 20x10
parent: none
draw: func [] [[]]
cache: [size]
cached: []
limits: none
margin: 0x0
]
forth-arrow: object [
on-change*: func [word [any-word!] old [any-type!] new [any-type!]] [
on-change-dispatch 'triangle self word :old :new
]
type: forth-arrow
size: 16x10
parent: none
draw: func [] [~/draw self]
cache: [size]
cached: []
limits: none
dir: e
margin: 2x2
]
into: func [xy [pair!] /force space [object! none!]] [~/into self xy space]
]
vscroll: object [
on-change*: func [word [any-word!] old [any-type!] new [any-type!]] [
on-change-dispatch 'scrollbar self word :old :new
]
type: vscroll
size: 16x100
parent: none
draw: func [] [~/draw self]
cache: [size map]
cached:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment