fukuta 105 posts since
Oct 17, 2007
2.
Re: Is it possible that change the return value of add-stretch procedure's to a distance type variable? Jul 3, 2008 1:15 AM
Every Graphic has its Layout object (Graphic.layout), and the object seems to have its actual size.
The size is determined through layout negotiation processes. So it cannot be retrieved until the graphic is drawn.
{curl 6.0, 7.0 applet}
{document-style PlainDocument}
{value
let h:HBox = {HBox height = 1cm, background = "blue"}
let v:VBox = {VBox width = {add-stretch}, background = "red", h}
{after 0s do
{if-non-null layout = v.layout then
set h.width = {layout.get-bounds}.width / 2
}
}
v
}
In above example, the hbox has half width of its parent vbox.
But I think you had better not set height or width according to this Layout because it (GRect) may vary on next layout negotiation. You may have to recalculate the size every time layout negotiation processed.
If you just want a graphic to be the half width of its parent, you can make your layout like below
{value
let h:HBox = {HBox height = 1cm, width = {make-elastic}, background = "blue"}
let v:VBox = {VBox width = {add-stretch}, background = "red",
{HBox h, {Fill width = {make-elastic}}}
}
v
}