Is there a way to center Gui buttons and margins in Rebol?

Spent hours trying to figure it out and still haven't got it. None of the documentation mentions this. Is this something that cannot be done, just manually to manually change the entire origin?

Perhaps I am just expecting too much?

edit: well I discovered a hack: indent num and then indent -num on the next line. Of all the impressive features of this language, why couldn't they just add a simple command like center?

+3


source to share


3 answers


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

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

      



Here's a usage example:

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

      

+5


source


First, VID is not Rebol, but a demo dialect written by the author Carl Sassenrath to demonstrate how interfaces can be typed in Rebol. There are others, including RebGUI ( http://www.dobeash.com/rebgui.html ), although I suspect there is no way to center the buttons, as no author thought it was important.



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

+3


source


We cannot center or align material based on the window itself, because the controls have no way of referring to their parent face until AFTER the parent had a "SHOW" prompt.

face / parent-face is not set until the parent is shown . So in normal VID, you need to set up the gui right after the initial layout and presentation has been done.

here's a little script that shows how to center any face, after it has been shown at least once.

view / new is used to delay processing events in order to change 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

      

+3


source







All Articles