Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: building layout/view dynamically
Pages: [1] Print
Author Topic: building layout/view dynamically  (Read 580 times)
gabrielcrowe
Newbie
*
Offline Offline

Posts: 4


View Profile
building layout/view dynamically
« on: August 07, 2006, 09:57:27 AM »

first post, from an excited vbscript refugee.

i'v had a search, and a poke around at various pieces of source, but this one is killing me.

i can load files from disk and such, csv, in this case. and i can build a gui by hand, a static one, thats not a problem. what i really would like to do is use the data from a text file to position buttons and to assign them functions. their labels, colours and such, should all be defined from the txt file.

i tried to do some magic from inside the view[] but it errors every time, a simple array loop would do it, but..always an error.

is what i need actually possible?  :huh:

thanks for your time everyone.
Logged
Graham
Full Member
***
Offline Offline

Posts: 113


View Profile
Re: building layout/view dynamically
« Reply #1 on: August 08, 2006, 01:48:00 AM »

A vid layout is dynamically constructed!

If you have a VID layout as a file, you can try something like this

; read it in first
lo: read %mylayout.r

; convert to block so it can be parsed
lo: to-block lo

; now bind it so that Rebol understands what context the words are to be interpreted
; let's bind it to layout

bind lo 'layout

; now you can do this

view layout lo

; untested and hope it helps.
Logged

Gabriele
Full Member
***
Offline Offline

Posts: 182


View Profile WWW
Re: building layout/view dynamically
« Reply #2 on: August 08, 2006, 04:52:25 AM »

Graham, in that case, just do:
Code:
view layout load %mylayout.r
But I think he's asking for something different.

gabrielcrowe, you may either need COMPOSE or doing something like:

Code:
lay: copy [
   ; any initial VID code before the buttons you are adding
]
foreach [text size] ["One" 100 "Two" 200 "Three" 110] [
    append lay compose [btn (text) (size)]
]
view layout lay

Basically you just build the layout block by appending code to it (or manipulating it in any other way - it's just a block), then call LAYOUT on it.
Logged
gabrielcrowe
Newbie
*
Offline Offline

Posts: 4


View Profile
Re: building layout/view dynamically
« Reply #3 on: August 08, 2006, 06:21:58 AM »

spot on, and both raised some interesting ideas.

Code:
REBOL []
   defaultdata: read/lines %default.txt
lay: copy [

]

foreach datarow defaultdata [
parsed-block: parse datarow "#"
foreach [text size] [parsed-block] [
    append lay compose [btn (text) (size)]
]
]

view layout lay

my file default.txt contains:
Code:
"buttonname1"#100
"buttonname2"#300
"buttonname3"#200

it makes 3 buttons i'm assuming them to be the rows in my txt, but how do i split the rows up for use in the building of the buttons. lol, this is all very confuddling. but fun, nonetheless.
« Last Edit: August 08, 2006, 06:38:25 AM by gabrielcrowe » Logged
gabrielcrowe
Newbie
*
Offline Offline

Posts: 4


View Profile
Re: building layout/view dynamically
« Reply #4 on: August 08, 2006, 07:03:43 AM »

i also tried this:
Code:
REBOL []
   defaultdata: read %default.txt

lay: copy [

]

foreach [text size] [defaultdata] [
    append lay compose [btn (text) (size)]
]

view layout lay

with my txt as this:
Code:
"One" 100 "Two" 200 "Three" 110

no dice. i think perhaps i dont understand how to use blocks. lol.
Logged
Graham
Full Member
***
Offline Offline

Posts: 113


View Profile
Re: building layout/view dynamically
« Reply #5 on: August 08, 2006, 07:00:14 PM »

defaultdata: to-block read %default.txt

otherwise it's a string ...
Logged

gabrielcrowe
Newbie
*
Offline Offline

Posts: 4


View Profile
Re: building layout/view dynamically
« Reply #6 on: August 09, 2006, 07:13:32 AM »

nope, i tried that, and i get an error about it being 'none'

Unrecognized parameter: none

it draws a single button, thats all.
Logged
Philippe
Newbie
*
Offline Offline

Posts: 34


View Profile WWW
Re: building layout/view dynamically
« Reply #7 on: August 09, 2006, 02:59:18 PM »

Hello,

The problem comes from your code : you use a foreach loop with [defaultdata] (block!), no defaultdata.
Try this, it works, with default.txt like this :
"buttonname1" 100
"buttonname2" 300
"buttonname3" 200


Code:
defaultdata: load %default.txt

lay: copy []

foreach [text size] defaultdata [
    append lay compose [btn (text) (size)]
]

view layout lay

===Philippe

Logged

===Philippe
Pages: [1] Print 
Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: building layout/view dynamically
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
September 05, 2008, 11:48:10 PM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2233 Posts in 581 Topics by 1855 Members
Latest Member: SmartCho

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc