Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[ALLY] Re: Layout Bind or Context in stylized Layouts

From: jeff:rebol at: 10-Nov-2000 18:51

Howdy, Mike:
> I have created a sytlized button that I want to use to > leverage the view style. > > style more-info-button button 20x20 "..." > [view/new/offset layout > [ h1 "Customer Information" > txt "Some explanatory text here" button "Back" [unview] > ] 150x150]
. . .
> Works beautifully with only a line of code. > > currency-more-info: more-info-button. > > But what I want to do is create these and pass the values > that will appear in the h1 and txt values. And others as I > need to add them. This will give standard look and feel on > the more-info buttons and reduce the support code.
Here's a pretty easy way to get this: more-info-styles: stylize [ more-info-button: button 20x20 [ view/new layout [ h1 face/texts/2 txt face/texts/3 button "back" [unview] ] ] ] view layout [ styles more-info-styles txt "Stuff to learn about" more-info-button "..." "H1-text" "txt text" ] In the later REBOL/views, additional strings found after a style are collected by LAYOUT and deposited into the resulting face's 'texts block. The disadvantage of the above approach is you will have to include "..." each time you use a more-info-button because layout will consider the first text item to be the text of the style. Okay, so we need to outsmart layout somehow. Well, each style has a field called 'init which is called when making that style. We can hack something into 'init to always stick in the text we want for the more-info-button like this: more-info-styles: stylize [ more-info-button: button with [ append init [insert texts "..."] ] 20x20 [ view/new layout [ h1 face/texts/2 txt face/texts/3 button "back" [unview] ] ] ] view layout [ styles more-info-styles txt "Stuff to get information about" more-info-button "H1-text" "txt-text" ] We hack a little here with some dynamic code stuck in the right spot because we want to get around the normal way layout does things with your style. There's other ways to do it, too, but above is an okay way.
> For example: > > add-more-info: func [aHeading someDetail] [ > to-block rejoin ["h1 " aHeading > " txt " someDetail " button "Back" [unview] " > ] ]
Also, just FYI: When you use TO-BLOCK on a string, like above, you wind up with words that don't have a context. You could get what you want above using LOAD, or you could use REDUCE or COMPOSE: reduce ['h1 aHeading 'txt someDetail 'button "back" [unview]] or compose [h1 (aHeading) txt (someDetail) button "back" [unview]] Hope that was helpful! -jeff