Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- ]
- ]
Add Comment
Please, Sign In to add comment