TOPIC: Center/align scrollable controls
#12
Center/align scrollable controls 4 Years, 6 Months ago
My main object is to center a form that can be scrolled if its window becomes too small. Under the form there should be some buttons.

So:
Code:

Window(#(Scroll(
Center, (Vert
(Form
( name1 group: 0 ) (name2 group: 1 ) nl
( name3 group: 0 ) (name4 group: 1 ) nl)
(Skip 10)
(Horz (Button "Button1") (Button "Button2")))
)))



Looks OK, but I want the buttons always to remain in sight, even if the window gets too small. So some adjustment to place them outside the scrollable area:
Code:

Window(#(Center, (Vert
(Scroll (Form
( name1 group: 0 ) (name2 group: 1 ) nl
( name3 group: 0 ) (name4 group: 1 ) nl))
(Skip 10)
(Horz (Button "Button1") (Button "Button2")))
))



Now the form is always sized to the minimal dimensions Xmin, Ymin of the ScrollControl (actually Xmin to the HorzControl of the buttons).

What do I miss, any way to get around this?

Thanks,

Jos
 
 
#17
Re:Center/align scrollable controls 4 Years, 6 Months ago
The problem seems to be the Center. This is maybe closer to what you want:

Code:

Window(#(Vert
        (Scroll (Center (Form
            ( name1 group: 0 ) (name2 group: 1 ) nl
            ( name3 group: 0 ) (name4 group: 1 ) nl
            )))
        (Skip 10)
        (Horz (Button "Button1") (Button "Button2")))
)

 
 
andrew
 
#19
Re:Center/align scrollable controls 4 Years, 6 Months ago
Thanks Andrew,

It works, but now the buttons are positioned at the bottom and I wanted them to "float" under the form.
I added two Fills to get this effect somehow, also two EtchedLines to see what's going on when resizing:
Code:

Window(#(Vert
Fill
EtchedLine
        (Scroll (Center (Form
            ( name1 group: 0 ) (name2 group: 1 ) nl
            ( name3 group: 0 ) (name4 group: 1 ) nl
            )))
EtchedLine
        (Horz Fill (Button "Button1") (Button "Button2") Fill)
        Fill)
)



Looks OK at first, but with taller forms it gets a mess, due to the Xmin: 50 of ScrollControl. Nothing to do about that, extending it wouldn't be a solution. So I have to settle for the buttons at the bottom, a workaround would be too complicated.

Jos:blink:
 
 
#20
Re:Center/align scrollable controls 4 Years, 6 Months ago
So I settled with the buttons located at the bottom. Didn't find the result that pleasing and also decided to center the Form only vertically. So added a Vert before the Center for as the manual states:
Centers the specified control, horizontally within a HorzControl, vertically within a VertControl, or otherwise both horizontally and vertically.


To my supprise, the Form remained centered horizontally. Looking at the library code of the CenterControl, I noticed the Resize() method always centers both ways, disregarding the parent.

Changing this probably wouldn't be the best solution, existing code relies on this (mis?)behavior. I would prefer to add extra parameters to the CenterControl:
New(control, border = 0, horz = true, vert = true)
Adjust the Resize() method regarding these parameters and change the documentation accordingly.

You could even consider to extend this by allowing numeric values for the horz/vert parameters, 0.5 being the default (centering), 0 (left/up most), 1 (right/down most).

Jos ;)