Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: Panels and pains
Pages: [1] Print
Author Topic: Panels and pains  (Read 458 times)
AllRebbedUp
Newbie
*
Offline Offline

Posts: 12


View Profile
Panels and pains
« on: April 01, 2007, 12:56:17 PM »

Hi Rebolers

Its me again and i have a question for you all

After having played with rebol for the past 6 weeks or so,
and having a bit of fun trying whatever scripts and/or tutorials i can find .

I still find myself at a complete loss on how to achieve certain things.  Sad Sad

For example lets take the following 3 scripts (included below)

A.   sub-panels.r
B.   rebodex.r
C.   icon-browse.r   

How would i go about having script B displayed on panel1 of script A
and script C on panel2 of script A. ?

Is it even possible ?

I have tried various ways, non of which work
(no surprise there,as i dont really know what i am doing)

So i ask the help of the enlightened.

Please could someone give an idiot proof example of what it entails to achieve the above.

sub-panels.r
Code:
REBOL []

   main: layout [
       vh2 "Subpanel Examples"
       guide
       pad 20
       button "Panel 1" [panels/pane: panel1  show panels]
       button "Panel 2" [panels/pane: panel2  show panels]
       button "Quit" [quit]
       return
       box 2x140 maroon
       return
       panels: box 220x140
   ]

   panel1: layout [
       origin 8x8
       h2 "Panel 1"
       field "Field 1"
       field "Field 2"
       button "The Answer" [alert "I know nothing."]
   ]

   panel2: layout [
       origin 8x8
       h2 "Panel 2"
       across
       txt "X:"
       slider 150x16
       return
       txt "Y:"
       slider 150x16
       return
       check [panel2/color: maroon  show panel2]
       txt "Don't click this"
       return
       check [panel2/color: silver  show panel2]
       txt "Click this"
       return
   ]

   panel1/offset: 0x0
   panel2/offset: 0x0

   panels/pane: panel1

   view main

rebodex.r
Code:
REBOL [
    Title: "Rebodex"
    Date: 2-Apr-2001
    Version: 2.1.0
    File: %rebodex.r
    Author: "Carl Sassenrath"
    Purpose: "A simple but useful address book contact database."
    Email: %carl--rebol--com
    library: [
        level: 'intermediate
        platform: none
        type: 'tool
        domain: [file-handling DB GUI]
        tested-under: none
        support: none
        license: none
        see-also: none
    ]
]

names-path: %names.r ;data file
name-list: none
fields: [name company title work cell home car fax web email smail notes updat]

names: either exists? names-path [load names-path][
    [[name "Carl Sassenrath" title "Founder" company "REBOL Technologies"
    email "%carl--rebol--com" web "http://www.rebol.com"]]
]

brws: [
    if not empty? web/text [
        if not find web/text "http://" [insert web/text "http://"]
        error? try [browse web/text]
    ]
]
dial: [request [rejoin ["Dial number for " name/text "?  (Not implemented.)"] "Dial" "Cancel"]]

dex-styles: stylize [
    lab: label  60x20 right bold middle font-size 11
    btn: button 64x20 font-size 11 edge [size: 1x1]
    fld: field  200x20 font-size 11 middle edge [size: 1x1]
    inf: info   font-size 11 middle edge [size: 1x1]
    ari: field wrap font-size 11 edge [size: 1x1] with [flags: [field tabbed]]
]

dex-pane1: layout/offset [
    origin 0 space 2x0 across
    styles dex-styles
    lab "Name"    name: fld bold return
    lab "Title"   title: fld return
    lab "Company" company: fld return
    lab "Email"   email: fld return
    lab "Web"     brws web: fld return
    lab "Address" smail: ari 200x72 return
    lab "Updated" updat: inf 200x20 return
] 0x0
updat/flags: none

dex-pane2: layout/offset [
    origin 0 space 2x0 across
    styles dex-styles
    lab "Work #"  dial work: fld 140 return
    lab "Home #"  dial home: fld 140 return
    lab "Cell #"  dial cell: fld 140 return
    lab "Alt #"   dial car:  fld 140 return
    lab "Fax #"   fax: fld 140 return
    lab "Notes"   notes: ari 140x72 return
    pad 136x1 btn "Close" #"^q" [store-entry save-file quit]
] 0x0

dex: layout [
    origin 8x8
    space 0x1
    styles dex-styles
    srch: fld 196x20 bold
    across
    rslt: list 180x150 [
        nt: txt 178x15 middle font-size 11 [
            store-entry curr: cnt find-name nt/text update-entry unfocus show dex
        ]
    ]
    supply [
        cnt: count + scroll-off
        face/text: ""
        face/color: snow
        if not n: pick name-list cnt [exit]
        face/text: select n 'name  face/font/color: black
        if curr = cnt [face/color: system/view/vid/vid-colors/field-select]
    ]
    sl: slider 16x150 [scroll-list] return

    return
    btn "New" #"^n" [new-name]
    btn "Del" #"^d" [delete-name unfocus update-entry search-all show dex]
    btn "Sort" [sort names sort name-list show rslt]
    return
   
    at srch/offset + (srch/size * 1x0)
    bx1: box dex-pane1/size
    bx2: box dex-pane2/size

    return
]

bx1/pane: dex-pane1/pane
bx2/pane: dex-pane2/pane
rslt/data: []
this-name: first names
name-list: copy names
curr: none
search-text: ""
scroll-off: 0

srch/feel: make srch/feel [
    redraw: func [face act pos][
        face/color: pick face/colors face <> system/view/focal-face
        if all [face = system/view/focal-face face/text <> search-text] [
            search-text: copy face/text search-all
            if 1 = length? name-list [this-name: first name-list update-entry show dex]
        ]
    ]
]

update-file: func [data] [
    set [path file] split-path names-path
    if not exists? path [make-dir/deep path]
    write names-path data
]

save-file: has [buf] [
    buf: reform [{REBOL [Title: "Name Database" Date:} now "]^/[^/"]
    foreach n names [repend buf [mold n newline]]
    update-file append buf "]"
]

delete-name: does [
    remove find/only names this-name
    if empty? names [append-empty]
    save-file
    new-name
]

clean-names: function [][n][
    forall names [
        if any [empty? first names none? n: select first names 'name empty? n][
            remove names
        ]
    ]
    names: head names
]

search-all: function [] [ent flds] [
    clean-names
    clear name-list
    flds: [name]
    either empty? search-text [insert name-list names][
        foreach nam names [
            foreach word flds [
                if all [ent: select nam word  find ent search-text][
                    append/only name-list nam
                    break
                ]
            ]
        ]
    ]
    scroll-off: 0
    sl/data: 0
    resize-drag
    scroll-list
    curr: none
    show [rslt sl]
]

new-name: does [
    store-entry
    clear-entry
    search-all
    append-empty
    focus name
;   update-entry
]

append-empty: does [append/only names this-name: copy []]

find-name: function [str][] [
    foreach nam names [
        if str = select nam 'name [
            this-name: nam
            break
        ]
    ]
]

store-entry: has [val ent flag] [
    flag: 0
    if not empty? trim name/text [
        foreach word fields [
            val: trim get in get word 'text
            either ent: select this-name word [
                if ent <> val [insert clear ent val  flag: flag + 1]
            ][
                if not empty? val [repend this-name [word copy val] flag: flag + 1]
            ]
            if flag = 1 [flag: 2  updat/text: form now]
        ]
        if not zero? flag [save-file]
    ]
]

update-entry: does [
    foreach word fields [
        insert clear get in get word 'text any [select this-name word ""]
    ]
    show rslt
]

clear-entry: does [
    clear-fields bx1
    clear-fields bx2
    updat/text: form now
    unfocus
    show dex
]

show-names: does [
    clear rslt/data
    foreach n name-list [
        if n/name [append rslt/data n/name]
    ]
    show rslt
]

scroll-list: does [
    scroll-off: max 0 to-integer 1 + (length? name-list) - (100 / 16) * sl/data
    show rslt
]

do resize-drag: does [sl/redrag 100 / max 1 (16 * length? name-list)]

center-face dex
new-name
focus srch
show-names
view/new/title dex reform [system/script/header/title system/script/header/version]
insert-event-func [
    either all [event/type = 'close event/face = dex][
        store-entry
        quit
    ][event]
]
do-events

icon-browse.r   
Code:
REBOL [
    Title: "Iconic Image Browser"
    Date: 29-May-2004
    Version: 1.1.1
    File: %icon-browse.r
    Author: "Carl Sassenrath"
    Purpose: {
        Browse a directory of images using a scrolling list of icons.
        Displays a progress bar while icons are being created.
    }
    Notes: {
       4-June-2000 - 1.1.0 script orginally written by Carl.
       29-May-2004 - 1.1.1
    This script broke under later versions of View as it used the 'frame
    face which was dropped.  Replaced by 'box.
    Also referenced a missing jpg file, and so replaced that by embedding
    the image into the script.
   
    Graham Chiu
    }
    library: [
        level: 'intermediate
        platform: [all]
        type: [tool]
        domain: [GUI]
        tested-under: none
        support: none
        license: none
        see-also: none
    ]
]

files: []
icons: []
num: 0
selection: none

carlwaves: load #{     
89504E470D0A1A0A0000000D49484452000000670000003808020000006FFB71
8C0000001374455874536F667477617265005245424F4C2F566965778FD91678
0000039B49444154789CCD9BD14E2B310C44F3FFFF521E2AC1C395E00589EF02
5DD8D226713C339EECBD928510A4893D3EF67AB76D7B7E79FEB2D73FAFBDBD1D
36FEEBAF7DBF70FEDABABD0D56F0E1B6E0B6FED7AE81050B2E4F97AF9FED6185
45022048CA2C6920361F1336580B35A63C4E4F12808D378124CE9C81880B186C
14175A1DE9C0C2A2E785B6B64CA62EF6C626330250A932064CB984F3358FA77F
BC7F8CD657685E5FB03415A34B9E3226C1484A1ACA6DB6974597699EFB6C2F4E
C44B92E17454A309F14F348DDD4D5B98195BB2AF6B7E4E545B57FEBAE0415DA0
43EFE62C70B196362285D74C35F0782ECF26A0FC8492E20EAAED6CC35ACE13FC
61646467C69D5715EA4F9D3725B1703BF45AB2768A9D5F59CA6E716E5A747CBF
23D6A7E418C2C53C6EB440FCE803B106E6D94C8AAF4B42694871B9FB237035C8
70E5A0200D4A7E4553E952A6F435BA247DD4B83A5DB18D26AA4D5E39E0CA4107
7B0F86C7F19EC685B5EFE57D28E02E411CC2238C0304B5065D26DCC1DA9A02FC
CE4EBD19A0C58D9BE039179086B6DB20519A1F5C8194071DBB115703B996FF37
4BE0F5AA269B18CFC9C6CC1FC3D5A0D6B62C6AEA112236F38195B88DF12F9C9B
B45B1C6C637B161E1D5BCF6D8807A0437366CB21D90462F2BD3E827C96CB0483
D67B99916407E99E69FD12F46A50C973856268A5DC345259837D8827E00FF890
452D0B5D0D38932F3C65B9614B4F720901B96565DCCBD7236B7C66B650868D08
9BFA26EBB36DCAA5E3B120339E5EBE3B468E6B68FB3041E79229047367ADDC14
F7B376F26B2722024A41998813A04CB91A475C11C9054536473CA3F7365C0D30
9E65A0BA6D5977CFEE030BD626B9E2E5DFE76E51AFF9CADA6308F899C76E756A
03D4796E80532E986D273B71CEA8D81672739E0F1B329F8E999D0D9D04080769
CABC1D21260C2BB8E43D2A9D70BE3A2207D66EA09E5BCAFFB742F9F0A0C37677
222CFE9B7C2865192B3FAC5988E0385747334BD8288041E0DFBF4F2AD44804B4
6DADAF2BE98C5D02458059B3571CA91481B09580A9D6E827B184DD3756D6BF7E
7376F81ED59E46633384296A9A4BA7D4E3B8CBD3E566F1948B754731E0EBC41B
246774BD7BBBCA612D8CA7CC85A7C1ED093B75721DCED1D7E279871668830AE7
B782F5E9FDE4918360C9F666A6F61647F2EDB342A2FA3F6E9B0C8AC2699B9B3F
53847BB992B5707FDE5B6D721EA3EB55E3D8190D8BD998923A68917BE3FEDD32
EE1BDCA216275C1CCFBD0A07F35A40A6CC05A1357E6BF512D26DC470BAC927A3
B0078A42DD22E10000000049454E44AE426082
}


;-- Progress box:
view/new layout [
    ; backtile carlwaves effect [ tile gradcol 1x1 0.0.160 200.0.0]
    text "Iconifying Images..." bold
    filn: text 120x20
    prog: progress 200x14
]

 
;-- Read directory, find image files:
files: read %.
while [not tail? files] [
    either find [%.bmp %.jpg %.gif] find/last first files "." [
        files: next files][remove files]
]
files: head files

;-- Create icons from images:
icons: []
incr: 200 / max 1 length? files
total: 0
foreach f files [
    filn/text: f  show filn
    prog/data: to-integer total: total + incr show prog
    append icons to-image make face [
        size: 40x40
        color: 40.40.80
        image: load-image f
        effect: [aspect]
    ]
]
unview/all

;-- Main display:
view layout [
    ; backtile carlwaves effect [tile gradcol 1x1 0.0.160 200.0.0]
    backtile carlwaves effect [tile]
   
    title reform ["REBOL" system/script/header/title
        system/script/header/version] font [size: 16]
    across space 0
    vx: list 84x600 200.200.200 [
        size 80x74 space 0
        at 20x4 i: image 40x40 [
            img/image: load selection: i/data show vx show img]
        at 1x44 text 78x32 center font [
            size: 10 color: black shadow: none]
    ] supply [
        face/show?: true
        count: count + num
        if count > length? files [face/show?: false exit]
        either index = 2 [face/text: files/:count][
            face/effect: if selection = files/:count [[invert]]
            face/image: icons/:count
            face/data: files/:count
        ]
    ]
    vv: slider vx/size * 0x1 + 16x0 length? files [
        num: vv/data - 1 show vx]
    pad 20
    img: box 600x600 40.40.80 effect none
    at 638x20
    tgl: toggle 50x24 #"s" "Fit" [
        img/effect: either tgl/state ['aspect][none] show img
    ]
    button "Quit" 50x24 #"^(ESC)" [quit]
]

I look forward to any suggestions

TIA   ARU



Logged
henrikmk
Newbie
*
Offline Offline

Posts: 49


View Profile
Re: Panels and pains
« Reply #1 on: April 02, 2007, 09:07:33 AM »

Perhaps it's better to start with something simpler, so you can understand how to do face juggling:

A face is an object with certain properties, like size, offset, font, color, etc. One of the properties is the pane, which can contain another face or a block of faces. The main strength of VID (some will say weakness!) is that the face object is the only object ever used for creating user interface elements in VID.

To see the basic face:

>>probe face
make object! [
    type: 'face
    offset: 0x0
    size: 100x100
....


the basic face object is shown.

The LAYOUT function creates, in fact, a face, which holdes a pane of more faces.

>>probe layout [button "Hello!"]
make object! [
    type: 'face
    offset: 50x50
    size: 140x64
    span: none
...very long blurb...


VIEW displays that face as a window. It's still a face like any other face. So if it's a face, you can display any part of any VID UI as a main window, by just referring to that face as an argument to VIEW.

The other way around (which you are looking for), is that a pane can contain any other block of faces or a single face, except itself.

So... if you want to display the main window of a program in a pane in your own program, you have to alter the part of the script that does the VIEWing, remove that VIEW and take the LAYOUT and put that as the contents of your pane. You can see how assigning a UI to a pane is done in the Panels script.

The optimal thing is for your script to return the layout at the end instead of viewing the window, store it as a variable and use that variable for the pane. Try to avoid loading the layout every time you switch panes, because that can be quite memory intensive. Instead load all layouts at the start of the Panels script, so all layouts are ready for your Panels window.

Remember to set the offsets properly for your layout. It may be appropriate to use LAYOUT/TIGHT for layouts that go in panes to remove offsets.
Logged
Anton
Jr. Member
**
Offline Offline

Posts: 65

Rebol veteran


View Profile WWW
Re: Panels and pains
« Reply #2 on: April 02, 2007, 09:43:08 AM »

Aha.. not so simple, as neither %rebodex.r nor %icon-browse.r were designed to be added, modularly, to a larger program. Each one presumes that it is the sole reason for launching the Rebol/View process this time, and each one opens its window as if it is the only window. Each program also defines words in the global context, which means when the programs are put together into a single program, there arises the potential for unintended side-effects, such as both programs trying to use the same word, and defining it differently at different times (eg. two scripts may both decide to use the word 'main-window to refer to its primary window). As such, an analysis and comparison of all the words set by each script is necessary. Unfortunately, many scripts are written in just this way. It's good for fast prototyping, but not good if trying to be a "good citizen" in a shared environment.

However, there is a fair chance that we can just squash the two scripts together in the above, bug-inviting, way, to see if it can work.

Ok, so what I've done is I've started with the top level, the %sub-panels.r script, and copied it to a new file, %panels-envelope-scripts.r
Looking at that, we can see it has a MAIN layout, which becomes the main window, and two panels, PANEL1 and PANEL2.
Next, I look at each of the other two scripts and identify their main windows.
%rebodex.r has a main window called DEX as I can see from the line near the bottom:

    view/new/title dex ...

(not a great name for a window, but anyway...)
%icon-browse.r does not name its main window layout, it just passes the LAYOUTed face directly to VIEW, as you can see from the last expression:

    view layout [ ...

So what we'll do is strip those two calls to VIEW and just take the LAYOUTs, which will replace the panel1 and panel2 layouts in our new mega-script.

So, ok, what I've done is copy the %icon-browse.r code and inserted it into the top of our new script, removing the VIEW word from the final expression, and setting the layout to a new word 'icon-window:

    icon-window: layout [ ...

Just after that insertion, I copy all the %rebodex.r code, minus the last 8 lines from VIEW/NEW ... through ... DO-EVENTS. (Remember this removed event-func for later, we will have to do something similar, but we're just getting it going for now.)

Next, I've deleted the two layouts:

    panel1: layout [ ... ]
    panel2: layout [ ... ]

and replaced them with:

    panel1: dex
    panel2: icon-window

(What the above two expressions are doing is saying is, set the 'panel1 word to refer to the same value as the 'dex word is referring to, and set the 'panel2 word to refer to the same value as the 'icon-window is referring to. So the situation afterwards is that there are two words referring to one thing. Remember this when you are optimizing and cleaning later, as this is not a necessity, it just makes it easier for this quick hack-job.)

Now you should have a working script, so try it:

    do %panels-envelope-scripts.r

You should be able to change between the two panels, but will notice that the main window is too small to see much. That's because the size of the PANELS box is hard-coded. (And the window can't be resized, yet.) So what we'll do is define the two panels before the MAIN window layout and use the MAX function to ensure the main window is large enough to accomodate both panels at the initial layout time.
So I've rearranged the final lines of our script so it looks like this:

   panel1: dex
   
   panel2: icon-window
   
   main: layout [
      vh2 "Subpanel Examples"
      guide
      pad 20
      button "Panel 1" [panels/pane: panel1  show panels]
      button "Panel 2" [panels/pane: panel2  show panels]
      button "Quit" [quit]
      return
      box 2x140 maroon
      return
      ;panels: box 220x140  ; <-- removed hard-coded size
      panels: box (max panel1/size panel2/size) ; <--
   ]
   
   panel1/offset: 0x0
   panel2/offset: 0x0
   
   panels/pane: panel1
   
   view main

See the full code at bottom.
Ok, that proves the concept. (Full resizability can be the subject of another article.)

Things to pay attention to:

(1)
In a line such as this:

    view layout [ ... ]

the flow of data can be represented like so:

    VIEW <----(face)---- LAYOUT <---(spec block)---- [ ... ]

We can choose when we wish to LAYOUT and when we wish to VIEW.

(2)
The VIEW function blows away any preexisting (first) window, starts handling events, and waits for all windows to be closed before returning. This assumes an "empty" environment. ("The universe exists for me").
Add the /NEW refinement, and VIEW/NEW is a much more well-behaved "citizen", as it leaves existing windows as they are and returns immediately without blocking by waiting for events. (You are able to call DO-EVENTS afterwards if that is necessary.)

(3)
This was fun, but highlights some difficulties with the scripts involved here. I would like to rewrite each script so that it is more modular, in a context (namespace) of its own, with all words accounted for and no words inadvertently set in the global context. Some of the words could be better named, more clearly describing its associated value.

Anyway, here's the final code:

Code:
REBOL []

files: []
icons: []
num: 0
selection: none

carlwaves: load #{     
89504E470D0A1A0A0000000D49484452000000670000003808020000006FFB71
8C0000001374455874536F667477617265005245424F4C2F566965778FD91678
0000039B49444154789CCD9BD14E2B310C44F3FFFF521E2AC1C395E00589EF02
5DD8D226713C339EECBD928510A4893D3EF67AB76D7B7E79FEB2D73FAFBDBD1D
36FEEBAF7DBF70FEDABABD0D56F0E1B6E0B6FED7AE81050B2E4F97AF9FED6185
45022048CA2C6920361F1336580B35A63C4E4F12808D378124CE9C81880B186C
14175A1DE9C0C2A2E785B6B64CA62EF6C626330250A932064CB984F3358FA77F
BC7F8CD657685E5FB03415A34B9E3226C1484A1ACA6DB6974597699EFB6C2F4E
C44B92E17454A309F14F348DDD4D5B98195BB2AF6B7E4E545B57FEBAE0415DA0
43EFE62C70B196362285D74C35F0782ECF26A0FC8492E20EAAED6CC35ACE13FC
61646467C69D5715EA4F9D3725B1703BF45AB2768A9D5F59CA6E716E5A747CBF
23D6A7E418C2C53C6EB440FCE803B106E6D94C8AAF4B42694871B9FB237035C8
70E5A0200D4A7E4553E952A6F435BA247DD4B83A5DB18D26AA4D5E39E0CA4107
7B0F86C7F19EC685B5EFE57D28E02E411CC2238C0304B5065D26DCC1DA9A02FC
CE4EBD19A0C58D9BE039179086B6DB20519A1F5C8194071DBB115703B996FF37
4BE0F5AA269B18CFC9C6CC1FC3D5A0D6B62C6AEA112236F38195B88DF12F9C9B
B45B1C6C637B161E1D5BCF6D8807A0437366CB21D90462F2BD3E827C96CB0483
D67B99916407E99E69FD12F46A50C973856268A5DC345259837D8827E00FF890
452D0B5D0D38932F3C65B9614B4F720901B96565DCCBD7236B7C66B650868D08
9BFA26EBB36DCAA5E3B120339E5EBE3B468E6B68FB3041E79229047367ADDC14
F7B376F26B2722024A41998813A04CB91A475C11C9054536473CA3F7365C0D30
9E65A0BA6D5977CFEE030BD626B9E2E5DFE76E51AFF9CADA6308F899C76E756A
03D4796E80532E986D273B71CEA8D81672739E0F1B329F8E999D0D9D04080769
CABC1D21260C2BB8E43D2A9D70BE3A2207D66EA09E5BCAFFB742F9F0A0C37677
222CFE9B7C2865192B3FAC5988E0385747334BD8288041E0DFBF4F2AD44804B4
6DADAF2BE98C5D02458059B3571CA91481B09580A9D6E827B184DD3756D6BF7E
7376F81ED59E46633384296A9A4BA7D4E3B8CBD3E566F1948B754731E0EBC41B
246774BD7BBBCA612D8CA7CC85A7C1ED093B75721DCED1D7E279871668830AE7
B782F5E9FDE4918360C9F666A6F61647F2EDB342A2FA3F6E9B0C8AC2699B9B3F
53847BB992B5707FDE5B6D721EA3EB55E3D8190D8BD998923A68917BE3FEDD32
EE1BDCA216275C1CCFBD0A07F35A40A6CC05A1357E6BF512D26DC470BAC927A3
B0078A42DD22E10000000049454E44AE426082
}


;-- Progress box:
view/new layout [
    ; backtile carlwaves effect [ tile gradcol 1x1 0.0.160 200.0.0]
    text "Iconifying Images..." bold
    filn: text 120x20
    prog: progress 200x14
]


;-- Read directory, find image files:
files: read %.
while [not tail? files] [
    either find [%.bmp %.jpg %.gif] find/last first files "." [
        files: next files][remove files]
]
files: head files

;-- Create icons from images:
icons: []
incr: 200 / max 1 length? files
total: 0
foreach f files [
    filn/text: f  show filn
    prog/data: to-integer total: total + incr show prog
    append icons to-image make face [
        size: 40x40
        color: 40.40.80
        image: load-image f
        effect: [aspect]
    ]
]
unview/all

;-- Main display:
icon-window: layout [
    ; backtile carlwaves effect [tile gradcol 1x1 0.0.160 200.0.0]
    backtile carlwaves effect [tile]
   
    title reform ["REBOL" system/script/header/title
        system/script/header/version] font [size: 16]
    across space 0
    vx: list 84x600 200.200.200 [
        size 80x74 space 0
        at 20x4 i: image 40x40 [
            img/image: load selection: i/data show vx show img]
        at 1x44 text 78x32 center font [
            size: 10 color: black shadow: none]
    ] supply [
        face/show?: true
        count: count + num
        if count > length? files [face/show?: false exit]
        either index = 2 [face/text: files/:count][
            face/effect: if selection = files/:count [[invert]]
            face/image: icons/:count
            face/data: files/:count
        ]
    ]
    vv: slider vx/size * 0x1 + 16x0 length? files [
        num: vv/data - 1 show vx]
    pad 20
    img: box 600x600 40.40.80 effect none
    at 638x20
    tgl: toggle 50x24 #"s" "Fit" [
        img/effect: either tgl/state ['aspect][none] show img
    ]
    button "Quit" 50x24 #"^(ESC)" [quit]
]

names-path: %names.r ;data file
name-list: none
fields: [name company title work cell home car fax web email smail notes updat]

names: either exists? names-path [load names-path][
    [[name "Carl Sassenrath" title "Founder" company "REBOL Technologies"
    email "%carl--rebol--com" web "http://www.rebol.com"]]
]

brws: [
    if not empty? web/text [
        if not find web/text "http://" [insert web/text "http://"]
        error? try [browse web/text]
    ]
]
dial: [request [rejoin ["Dial number for " name/text "?  (Not implemented.)"] "Dial" "Cancel"]]

dex-styles: stylize [
    lab: label  60x20 right bold middle font-size 11
    btn: button 64x20 font-size 11 edge [size: 1x1]
    fld: field  200x20 font-size 11 middle edge [size: 1x1]
    inf: info   font-size 11 middle edge [size: 1x1]
    ari: field wrap font-size 11 edge [size: 1x1] with [flags: [field tabbed]]
]

dex-pane1: layout/offset [
    origin 0 space 2x0 across
    styles dex-styles
    lab "Name"    name: fld bold return
    lab "Title"   title: fld return
    lab "Company" company: fld return
    lab "Email"   email: fld return
    lab "Web"     brws web: fld return
    lab "Address" smail: ari 200x72 return
    lab "Updated" updat: inf 200x20 return
] 0x0
updat/flags: none

dex-pane2: layout/offset [
    origin 0 space 2x0 across
    styles dex-styles
    lab "Work #"  dial work: fld 140 return
    lab "Home #"  dial home: fld 140 return
    lab "Cell #"  dial cell: fld 140 return
    lab "Alt #"   dial car:  fld 140 return
    lab "Fax #"   fax: fld 140 return
    lab "Notes"   notes: ari 140x72 return
    pad 136x1 btn "Close" #"^q" [store-entry save-file quit]
] 0x0

dex: layout [
    origin 8x8
    space 0x1
    styles dex-styles
    srch: fld 196x20 bold
    across
    rslt: list 180x150 [
        nt: txt 178x15 middle font-size 11 [
            store-entry curr: cnt find-name nt/text update-entry unfocus show dex
        ]
    ]
    supply [
        cnt: count + scroll-off
        face/text: ""
        face/color: snow
        if not n: pick name-list cnt [exit]
        face/text: select n 'name  face/font/color: black
        if curr = cnt [face/color: system/view/vid/vid-colors/field-select]
    ]
    sl: slider 16x150 [scroll-list] return

    return
    btn "New" #"^n" [new-name]
    btn "Del" #"^d" [delete-name unfocus update-entry search-all show dex]
    btn "Sort" [sort names sort name-list show rslt]
    return
   
    at srch/offset + (srch/size * 1x0)
    bx1: box dex-pane1/size
    bx2: box dex-pane2/size

    return
]

bx1/pane: dex-pane1/pane
bx2/pane: dex-pane2/pane
rslt/data: []
this-name: first names
name-list: copy names
curr: none
search-text: ""
scroll-off: 0

srch/feel: make srch/feel [
    redraw: func [face act pos][
        face/color: pick face/colors face <> system/view/focal-face
        if all [face = system/view/focal-face face/text <> search-text] [
            search-text: copy face/text search-all
            if 1 = length? name-list [this-name: first name-list update-entry show dex]
        ]
    ]
]

update-file: func [data] [
    set [path file] split-path names-path
    if not exists? path [make-dir/deep path]
    write names-path data
]

save-file: has [buf] [
    buf: reform [{REBOL [Title: "Name Database" Date:} now "]^/[^/"]
    foreach n names [repend buf [mold n newline]]
    update-file append buf "]"
]

delete-name: does [
    remove find/only names this-name
    if empty? names [append-empty]
    save-file
    new-name
]

clean-names: function [][n][
    forall names [
        if any [empty? first names none? n: select first names 'name empty? n][
            remove names
        ]
    ]
    names: head names
]

search-all: function [] [ent flds] [
    clean-names
    clear name-list
    flds: [name]
    either empty? search-text [insert name-list names][
        foreach nam names [
            foreach word flds [
                if all [ent: select nam word  find ent search-text][
                    append/only name-list nam
                    break
                ]
            ]
        ]
    ]
    scroll-off: 0
    sl/data: 0
    resize-drag
    scroll-list
    curr: none
    show [rslt sl]
]

new-name: does [
    store-entry
    clear-entry
    search-all
    append-empty
    focus name
;   update-entry
]

append-empty: does [append/only names this-name: copy []]

find-name: function [str][] [
    foreach nam names [
        if str = select nam 'name [
            this-name: nam
            break
        ]
    ]
]

store-entry: has [val ent flag] [
    flag: 0
    if not empty? trim name/text [
        foreach word fields [
            val: trim get in get word 'text
            either ent: select this-name word [
                if ent <> val [insert clear ent val  flag: flag + 1]
            ][
                if not empty? val [repend this-name [word copy val] flag: flag + 1]
            ]
            if flag = 1 [flag: 2  updat/text: form now]
        ]
        if not zero? flag [save-file]
    ]
]

update-entry: does [
    foreach word fields [
        insert clear get in get word 'text any [select this-name word ""]
    ]
    show rslt
]

clear-entry: does [
    clear-fields bx1
    clear-fields bx2
    updat/text: form now
    unfocus
    show dex
]

show-names: does [
    clear rslt/data
    foreach n name-list [
        if n/name [append rslt/data n/name]
    ]
    show rslt
]

scroll-list: does [
    scroll-off: max 0 to-integer 1 + (length? name-list) - (100 / 16) * sl/data
    show rslt
]

do resize-drag: does [sl/redrag 100 / max 1 (16 * length? name-list)]

center-face dex
new-name
focus srch
show-names

panel1: dex

panel2: icon-window

main: layout [
vh2 "Subpanel Examples"
guide
pad 20
button "Panel 1" [panels/pane: panel1  show panels]
button "Panel 2" [panels/pane: panel2  show panels]
button "Quit" [quit]
return
box 2x140 maroon
return
;panels: box 220x140  ; <-- removed hard-coded size
panels: box (max panel1/size panel2/size) ; <--
]

panel1/offset: 0x0
panel2/offset: 0x0

panels/pane: panel1

view main
Logged
AllRebbedUp
Newbie
*
Offline Offline

Posts: 12


View Profile
Re: Panels and pains
« Reply #3 on: April 03, 2007, 06:01:56 AM »

Hi
Henrikmk and Anton thankyou both for your replies.

Anton. What can i say mate
That has got to be the best reply i could ever have expected, i mean very very well done indeed sir.

The way you explain what you are doing is first rate (totally idiot proof  Grin)

I think you ought to re-write some of the REBOL Documentaion to make it clearer to us newbs.
It seems that quite often the important bits are skipped over (or assume you know it already).
Maybe if more scripts had alot more commenting in them we would learn quicker.

Thankyou ever so much for the complete code, it helps enormously in making things clear
when combined with your explaination of what you are actually doing.

My hat goes off to you mate  (need a bowing smilie here)

Keep up the good work

ARU


Logged
Anton
Jr. Member
**
Offline Offline

Posts: 65

Rebol veteran


View Profile WWW
Re: Panels and pains
« Reply #4 on: April 13, 2007, 12:32:04 AM »

AllRebbedUp, I appreciate very much your positive feedback. Glad I was able to help.
But it was a very interesting question and it has spawned a few ideas needing investigation...

Regards.
Logged
Pages: [1] Print 
Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: Panels and pains
Jump to:  

  
Quick Search...

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

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2233 Posts in 581 Topics by 1886 Members
Latest Member: antigopit

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

RT design by Defiant Pc