tags:

views:

75

answers:

3

I know how to build a pictures gallery dynamically, how do I now allow to trigger an event when the user clicks on a picture ?

I don't want to have the engage function inside the layout but outside: is it possible ?

Not sure I am clear so tell me.

+1  A: 

A pretty easy trick is to set up a style with the action you want, and have it look at a user-data value you set when you generate the face if necessary.

lay: [ across style my-box box [print [face/user-data face/color]] ] repeat i 4 [ repeat j 4 [ repend lay [ 'my-box 50x50 get random/only [red green blue yellow] 'user-data to pair! reduce [i j] ] ] append lay 'return ] view layout lay

Hi thanks a lot Gregg for all your answers !
Rebol Tutorial
+1  A: 

There are many ways to do this. You don't specify how you are building the picture gallery, but I'm assuming that you are building a layout of IMAGE styles and then displaying that layout.

It sounds also like you want freedom to do specific things with each image, so I suggest you build a separate style, possibly derived from IMAGE. You can do that like this:

stylize/master [
 image: image with [
  feel: make feel [
   engage: func [face act event] [
    ; do my custom engage function
   ]
  ]
 ]
]

Put the code before the layout. This way, you can keep complex code for the behavior of IMAGE outside of the layout block. When you work this way, the style is globally changed.

You can also just create a new style, by altering the name:

stylize/master [
 image2: image with [
  ...
 ]
]

IMAGE will be left untouched, while you can use IMAGE2 in your layout.

Why STYLIZE/MASTER? I use STYLIZE/MASTER out of habit, so I don't have to specify a specific style list in the layout and I can shave off a line of code for each layout.

Henrik Mikael Kristensen
+1  A: 

Let's try that again:

lay: [
    across
    style my-box box [print [face/user-data face/color]]
]
repeat i 4 [
    repeat j 4 [
        repend lay [
            'my-box 50x50 get random/only [red green blue yellow] 
            'user-data to pair! reduce [i j]
        ]
    ]
    append lay 'return
]
view layout lay
You can edit your answers, no need to double post.
Sekhat