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

[ALLY] Making dynamic button layouts in VIEW

 [1/8] from: bo:rebol at: 29-Jan-2001 16:47


I get asked this question from time to time and there is some insight involved into how VIEW works, so I thought I would post an example to this list for the enlightenment of all: ;This is a template for a blank button button-layout: layout [button "text" []] ;This is your main VIEW view layout [ text "Enter names for some buttons divided by spaces" f: field 200 button "Show me!" [ ;; first, start off with an empty face to hold the buttons button-face: layout [] ;; keep an offset variable so we know where each button goes ofst: 0x0 ;; Break input from field above into a series of strings ;; and perform some actions on each one foreach item parse f/text none [ ;; The /pane is where sub-faces are stored. ;; This adds the modified blank button templates into the ;; blank button face we created above. append button-face/pane make button-layout/pane/1 [ offset: ofst ;; Buttons expect their label to be in a field called ;; 'texts' which is a block of strings. texts: reduce [item] ;; The action field determines what will be done when ;; the button is clicked. The COMPOSE statement ;; reduces only the items in parentheses (). action: func [f e] compose [request/ok (item)] ] ;; Increment the offset for the next button ofst: ofst + (button-layout/pane/1/size * 0x1) ] ;; Set the size for the button-face based on the last offset. button-face/size: ofst + button-layout/pane/1/size ;; View it! view/new button-face ] ] Have fun! -- Bohdan "Bo" Lechnowsky REBOL Adventure Guide REBOL Technologies 707-467-8000 (http://www.rebol.com) The Official Source for REBOL Books (http://www.REBOLpress.com)

 [2/8] from: larry::ecotope::com at: 29-Jan-2001 18:31


Hi Bo Nice example. Should we revive the ally-list by posting here and encouraging View questions to be posted here? It does seem better to me to keep the View stuff separate. If so it would be nice to have an *official* request to do that from RT to the main rebol-list. -Larry

 [3/8] 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

 [4/8] from: larry:ecotope at: 29-Jan-2001 23:35


Hi Jeff Very nice example. -Larry

 [5/8] from: bo:rebol at: 30-Jan-2001 9:41


Larry, Thanks! I'm not sure that we should forbid VIEW questions on the REBOL list. I think people will start moving over here on their own if the core VIEW group starts posting their VIEW stuff here. Perhaps when we get a conversation going we can tell people to check the ALLY list if they are interested in the topic. What do you think? -Bo On 29-Jan-2001/18:31:14-8:00, [larry--ecotope--com] wrote:
>Hi Bo >Nice example. Should we revive the ally-list by posting here and encouraging
<<quoted lines omitted: 17>>
>[ally-request--rebol--com] with "unsubscribe" in the >subject, without the quotes.
-- Bohdan "Bo" Lechnowsky REBOL Adventure Guide REBOL Technologies 707-467-8000 (http://www.rebol.com) The Official Source for REBOL Books (http://www.REBOLpress.com)

 [6/8] from: larry:ecotope at: 30-Jan-2001 10:07


Hi Bo Sounds fine to me. One major drawback of posting to the ally list is that it is not archived, so there is no way for folks to look back over prev posts. Perhaps this could be remedied with Sterlings new stuff? -Larry

 [7/8] from: gjones05:mail:orion at: 30-Jan-2001 12:14


Hi, Bo and Larry, I certainly would have no problems moving /View issues to the ALLY group, if you prefer.
> >-----snip demo code
Needless to probably say, but I didn't sign-up soon enough to get the post on making dynamic button layouts. Is this list archived someplace, or is it possible to repost that message? Thanks for any assistance that you can provide. --Scott

 [8/8] from: bo:rebol at: 30-Jan-2001 15:25


For the enlightenment of gjones and others that may have joined to late, I am replying to Jeff's response to my original post. Jeff shows a very good approach to dynamic layouts. I myself was pleasantly broadened by clever details in his solution of the problem. The method I show can be extended to handle more complex situations, as Jeff pointed out in his reply. It is Carl's desire that people realize how VID and VIEW faces are interrelated, but not at the expense of added complexity where it is not needed. Some day someone will write ''10,001 clever methods in REBOL/View''. This will just be scratching the tip of the iceberg. :-) -Bo On 29-Jan-2001/19:11:40-8:00, [jeff--rebol--com] wrote:
>Your example is elightening, Bo. I'm usually a little too >lazy of a VID programmer to redo the work that layout does for
<<quoted lines omitted: 94>>
>> >> Have fun!
-- Bohdan "Bo" Lechnowsky REBOL Adventure Guide REBOL Technologies 707-467-8000 (http://www.rebol.com) The Official Source for REBOL Books (http://www.REBOLpress.com)

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted