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

[ALLY] Re: Making dynamic button layouts in VIEW

From: jeff:rebol at: 29-Jan-2001 19:11

Your example is elightening, Bo. I'm usually a little too lazy of a VID programmer to redo the work that layout does for me, though, so I generally take a different approach to those kinds of layouts. Here's an alternative way to do the same: view layout [ text "Enter names for some buttons divided by spaces" f: field 200 (go: [ buttons: copy [space 0 style bt button [request/ok face/text]] foreach item parse f/text none [repend buttons ['bt item]] view/new layout/origin buttons 0x0 ]) button "Show me!" go ] The above approach can be called "Meta-programming VID" which means we use REBOL to generate the VID code that we send off to LAYOUT. You see this meta-programming when we use FOREACH to add a BT style to the layout we're constructing for each text peice. In the end we don't have to worry about where anything's placed or how big the window is because that's what layout does for us. Not all VIEW programming problems are amenable to meta-programming, though. Especially in situations where you have a layout that you are not going to be re-laying out or you have moving and changing faces in a layout-- then directly modifying faces and sizes, offsets and other face facets becomes very necessary. But if you're just going to create a single layout out of some random stuff, why not use metaprogramming? One other notable difference is instead of reconstructing each button and directly setting its action function separately, we just created a STYLE, BT, which takes care of the same action for all other instances of that style. That's the kind of thing styles are good at taking care of. -jeff