user2020783
user2020783

Reputation: 41

Is there a way to center gui buttons and fields in Rebol?

Spent hours trying to figure this out and still haven't got it. None of the documentation mentions anything about it. Is this something rebol just can't do without manually having to rearrange everything with origin?

Perhaps I'm just expecting too much?

edit: well I've discovered a hack: indent num, then indent -num on the next line . Out of all the spectacular features of this language why couldn't they have just added a simple command like center?

Upvotes: 3

Views: 190

Answers (3)

DocKimbel
DocKimbel

Reputation: 3199

There is a CENTER-FACE function you can reuse to align faces, but unfortunately it doesn't work very well from my experience. Here is a simpler replacement version that should do the trick:

center-face: func [face [object!] parent [object!]][
    face/offset: parent/size - face/size / 2 
]

Here is a usage example:

lay: layout [
    size 300x300
    b: button "Hello World"
]
center-face b lay
view lay

Upvotes: 5

moliad
moliad

Reputation: 1503

We can't center or align stuff based on the window itself because controls do not have any way to refer to their parent face until AFTER the parent has had 'SHOW called on it.

face/parent-face isn't set until the parent has been shown. So in normal VID you need to tweak the gui just after the initial layout & view has been done.

here is a little script which shows how to center any face, after its been shown at least once.

view/new is used to delay event handling, in order to modify the layout.

rebol []

center: func [face][
    face/offset/x: (face/parent-face/size/x / 2) - (face/size/x / 2)
    show face
]

view/new layout [
    across
    t: h1  "This is a centered title!" 
    return
    button "1"
    button "2"
    button "3"
    button "4"
]

center t

do-events

Upvotes: 3

Graham Chiu
Graham Chiu

Reputation: 4886

First off, VID is not Rebol, but a demonstration dialect written by the author, Carl Sassenrath, to demonstrate how interfaces could be dialected in Rebol. There are others including RebGUI ( http://www.dobeash.com/rebgui.html ) though I suspect there isn't a way to center buttons there either as neither author considered it important.

You can also use PAD to align the cursor close to the center of the layout.

Upvotes: 3

Related Questions