Last active
January 25, 2018 01:09
-
-
Save luce80/fc8825613a4e8aeedcf700ec47aae518 to your computer and use it in GitHub Desktop.
Create iterated faces in Red as those found in Rebol View
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 [ | |
title: "Iterated faces in Red" | |
file: %iterated-faces.red | |
author: "Marco Antoniazzi" | |
license: "Do with this code whatever you want, giving credit to me is NOT required" | |
email: [luce80 AT alice DOT it] | |
date: 13-01-2018 | |
version: 0.0.6 | |
Purpose: "Create iterated faces as those found in Rebol View" | |
Needs: View | |
] | |
iter-func: func [ | |
iterated-face [object!] | |
index [integer! pair!] | |
][ | |
; RETURNS: face, index number, or none | |
; if index is integer! return face | |
; if index is pair! return iteration number | |
?? index | |
either integer? index [ | |
; Draw needs to know offset and text: | |
iterated-face/offset/y: index - 1 * (iterated-face/size/y) | |
if iterated-face/offset/y > iterated-face/parent/size/y [return none] | |
iterated-face/text: form iterated-face/offset | |
iterated-face/color: either iterated-face/extra/selected = index [blue] [red] | |
return iterated-face | |
][ | |
; Events need to know iteration number: | |
return to-integer index/y / (iterated-face/size/y) + 1 | |
] | |
none | |
] | |
call_and_draw_iters: func[ | |
;itering-func [function!] ; using functions is currently problematic | |
itering-face [object!] | |
image [image!] | |
/local | |
draw-blk index current-face | |
][ | |
draw-blk: [image 0 0x0 10x10] | |
index: 1 | |
while [current-face: iter-func itering-face index ] [ | |
index: index + 1 | |
draw-blk/2: to-image current-face | |
draw-blk/3: current-face/offset | |
draw-blk/4: current-face/offset + current-face/size | |
draw image draw-blk | |
] | |
image | |
] | |
view compose [ | |
below space 4x4 | |
text "Select a line by clicking on it" | |
panel [ | |
below | |
canvas: image 300x190 green all-over | |
on-over [ | |
probe iter-func line-text event/offset | |
] | |
on-down [ | |
line-text/extra/selected: iter-func line-text event/offset | |
call_and_draw_iters line-text face/image | |
] | |
line-text: text "abcd" red yellow hidden extra object [selected: false] | |
] on-created [ | |
call_and_draw_iters line-text canvas/image | |
] | |
] |
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 [ | |
title: "Iterated fields in Red" | |
file: %iterated-fields.red | |
author: "Marco Antoniazzi" | |
license: "Do with this code whatever you want, giving credit to me is NOT required" | |
email: [luce80 AT alice DOT it] | |
date: 14-01-2018 | |
version: 0.0.6 | |
Purpose: "Create iterated faces as those found in Rebol View" | |
Needs: View | |
] | |
iter-func: func [ | |
iterated-face [object!] | |
index [integer! pair!] | |
][ | |
; RETURNS: face, index number, or none | |
; if index is integer! return face | |
; if index is pair! return iteration number | |
?? index | |
either integer? index [ | |
; Draw needs to know offset and text: | |
iterated-face/offset/y: index - 1 * (iterated-face/size/y + 1) | |
if iterated-face/offset/y > iterated-face/parent/size/y [return none] | |
iterated-face/text: form iterated-face/offset | |
;iterated-face/color: either iterated-face/extra/selected = index [blue] [red] | |
return iterated-face | |
][ | |
; Events need to know iteration number: | |
return to-integer index/y / (iterated-face/size/y + 1) + 1 | |
] | |
none | |
] | |
call_and_draw_iters: func[ | |
;itering-func [function!] ; using functions is currently problematic | |
itering-face [object!] | |
image [image!] | |
/local | |
draw-blk index current-face | |
][ | |
draw-blk: [image 0 0x0 10x10] | |
index: 1 | |
while [current-face: iter-func itering-face index ] [ | |
index: index + 1 | |
draw-blk/2: to-image current-face | |
draw-blk/3: current-face/offset | |
draw-blk/4: current-face/offset + current-face/size | |
draw image draw-blk | |
] | |
image | |
] | |
view compose [ | |
below space 4x4 | |
text "Select a line by clicking on it" | |
panel [origin 0x0 | |
below | |
canvas: image 300x190 green all-over | |
on-over [ | |
probe iter-func line-text event/offset | |
] | |
on-down [ | |
line-field/visible?: true | |
iter-func line-field iter-func line-field event/offset | |
set-focus line-field | |
line-text/extra/selected: iter-func line-text event/offset | |
call_and_draw_iters line-text face/image | |
] | |
line-text: field "abcd" hidden extra object [selected: false] | |
line-field: field hidden | |
] on-created [ | |
call_and_draw_iters line-text canvas/image | |
] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment