Monday 14 January 2013

Relative position of windows

You can impose the relative position of multiple windows, so if user move a window, the others will follow up.
Look the following example:
You can move the main window and the sub window will follow the main one, remaining at the relative positions.
Here is the source:

REBOL [
    Title:   "Linked Layout Demo"
    File:     %linked-layouts.r
    Author:   "Gregg Irwin"
    EMail:   greggirwin@acm.org
    Version: 0.0.1
    Date:     11-Oct-2003
    Purpose: {
        Shows how to "link" layouts so when a main window moves, the
        others stay in the same relative position to it.
    }

]
; We need to set title to "" or REBOL will put it on the seconary
; windows--those with no title bar--as text. We need a title in
; the header for the library though.
system/script/title: ""
moved: true
evt-func: func [face event][
    if event/face = main-lay [
        ;if event/type <> 'time [print event/type]
        switch event/type [
            close   [shutdown]
            offset [moved: true]
            resize [moved: true]
            time [
                if moved [
                    ; The -4x4 offset accounts for REBOL *not* accounting for
                    ; border widths.
                    lay-2/offset: -4x4 + main-lay/offset + to pair! reduce [0 main-lay/size/y]
                    lay-3/offset: -4x4 + main-lay/offset + to pair! reduce [main-lay/size/x - lay-3/size/x main-lay/size/y ]
                    lay-2/changes: lay-3/changes: 'offset
                    show [lay-2 lay-3]
                    moved: false
                ]
            ]
        ]
    ]
    event
]
if not find system/view/screen-face/feel/event-funcs :evt-func [insert-event-func :evt-func ]
shutdown: does [unview/all]
main-lay: layout [
    size 400x100
    h1 "main window"
    timer: sensor rate 0:0:1
]
lay-2: layout [size 150x200 h2 "Sub-window 1"]
lay-3: layout [size 200x150 h2 "Sub-winow 2"]
view/new/options/offset main-lay [no-border resize] 100x100
view/new/options/offset lay-2 [no-title no-border resize] 100x200
view/new/options/offset lay-3 [no-title no-border resize] 300x200
do-events
quit

No comments:

Post a Comment