2009-08-09 2 views

Antwort

2

Ein ziemlich einfacher Trick besteht darin, einen Stil mit der gewünschten Aktion einzurichten und einen Benutzerdatenwert anzeigen zu lassen, den Sie beim Generieren des Gesichts bei Bedarf festlegen.

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 
+0

Hallo vielen Dank Gregg für alle Ihre Antworten! –

2

Es gibt viele Möglichkeiten, dies zu tun. Sie geben nicht an, wie Sie die Bildergalerie erstellen, aber ich nehme an, dass Sie ein Layout von IMAGE-Stilen erstellen und dieses Layout dann anzeigen.

Es klingt auch wie Sie wollen Freiheit, um bestimmte Dinge mit jedem Bild zu tun, so schlage ich vor, Sie bauen einen separaten Stil, möglicherweise von IMAGE abgeleitet. Sie können das so tun:

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

Setzen Sie den Code vor dem Layout. Auf diese Weise können Sie komplexen Code für das Verhalten von IMAGE außerhalb des Layoutblocks speichern. Wenn Sie auf diese Weise arbeiten, wird der Stil global geändert.

Sie können auch erstellen Sie einfach einen neuen Stil, indem Sie den Namen zu ändern:

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

IMAGE unberührt gelassen werden, während Sie IMAGE2 in Ihrem Layout verwenden können.

Warum STYLIZE/MASTER? Ich benutze STYLIZE/MASTER aus Gewohnheit, so dass ich keine spezifische Stilliste im Layout angeben muss und ich kann eine Codezeile für jedes Layout abschneiden.

1

ist, dass wieder Lassen Sie versuchen:

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 
+1

Sie können Ihre Antworten bearbeiten, Sie müssen nicht doppelt posten. – Sekhat

4

Wie gesagt, ist das beste, einen Stil erstellen Sie den Code in das Layout minimiert. Der Stil ist also bereits für die gewünschten Aktionen konfiguriert.

Für eine Bildergalerie würde ich einen Daumenstil mit meinen Anforderungen erstellen.

Aber Sie brauchen kein 'Engagement func für einfache Dinge! Wenn Sie Links/Rechtsklicken benötigen, dann sind ein oder zwei Aktionsblöcke ausreichend und viel einfacher.

Hier ist ein vollständiges Beispiel:

Rebol [ 
    title: "Basic image gallery" 
] 

thumb-size: 100x100 ; size of the thumbnails 
thumbs-per-row: 6 ; number of thumbs per row 

; Here is the actions I want to use when clicking/right clicking the image face. 
; It's just a block: it's the 'layout function that will make it a function 
; with 'face and 'value arguments 
thumb-action: [ 
    ; left click: show full size image 
    view/new layout [ 
     origin 2 space 2 
     vh3 form (either any [file? face/user-data url? face/user-data text? face/user-data] [face/user-data] ["An image without reference"]) 
     image face/image 
    ] 
] 
thumb-alt-action: [ 
    ; right click: open up the folder/web site where the file is 
    switch/default type?/word face/user-data [ 
     file! [call/shell join "explorer " to-local-file first split-path face/user-data] 
     url! [browse face/user-data] 
    ] [alert rejoin ["Can't do anything with " type? face/user-data " type of value ! Sorry."]] 
] 

; Our styles for the gallery 
gallery-styles: probe stylize [ 
    ; Here is a style for the thumbnails, with the actions wanted 
    thumb: image thumb-size effect [aspect] thumb-action thumb-alt-action 
] 

; Some samples images 
imgs: [ 
    ; This paths are for a typical Windows7 installation 
    %/c/windows/web/wallpaper/nature/img1.jpg 
    %/c/windows/web/wallpaper/nature/img2.jpg 
    %/c/windows/web/wallpaper/nature/img3.jpg 
    %/c/windows/web/wallpaper/nature/img4.jpg 
    ; URLs as examples 
    http://www.rebol.com/graphics/reb-logo.gif 
    http://www.rebol.com/graphics/ref-card.jpg 
] 

; Base for your gallery layout 
gallery-lay: copy [ 
    origin 2 space 2 across 
    styles gallery-styles 
    vh2 "Image gallery" 
] 

; Builds the final layout 
count: 0 
foreach img imgs [ 
    ; This for handling only a defined number of thumbs per row 
    if 0 = (count // thumbs-per-row) [append gallery-lay 'return] 
    count: count + 1 
    ; Here you add the layout code for the current image 
    append gallery-lay compose [thumb (img) user-data (img)] 
] 

; Here we are: the result 
view layout gallery-lay 
Verwandte Themen