This Question is Answered

13 "helpful" answers available (3 pts)
4 Replies Last post: Jul 3, 2008 6:26 PM by markecho

Is it possible that change the return value of add-stretch procedure's to a distance type variable?

Jul 2, 2008 11:25 PM

Click to view markecho's profile Level 2 markecho 35 posts since
Oct 17, 2007

Hi,

I set a control' s width = {add-stretch}, then I want to use the width to calculate some value.

For example,

let v:VBox = {VBox width = {add-stretch} ....}

let h:HBox = {HBox width= v.width / 2}

How to implement the function above.

Thanks a lot.

Click to view tdeng's profile Level 3 tdeng 35 posts since
Oct 17, 2007
1. Re: Is it possible that change the return value of add-stretch procedure's to a distance type variable? Jul 3, 2008 1:14 AM
If you use stretchiness in a Graphic, the actuall size of this Graphic won't be determined until it's being actually valued in a layout context, shown in a screen.
so your code won't meet your requirement.

But if you accept setting the width of HBox after VBox is shown, the following code may help you as a sample:

{let v:VBox = {VBox width = {add-stretch}, "Something here"}}
{let h:HBox={HBox background="green",height=0.5cm}}

{value
{VBox
v,
h
}
}
{after 0s do
let gr:GRect = {GRect.empty}
{v.get-visible-bounds-into gr}
set h.width= gr.width / 2
}
Click to view fukuta's profile BlackBelt 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
}
Click to view Kamal's profile Curl Kamal 139 posts since
Oct 17, 2007
3. Re: Is it possible that change the return value of add-stretch procedure's to a distance type variable? Jul 3, 2008 9:35 AM
Note that the gui-toolkit system will call the "proc", if any, associated with a Graphic width and or height after it has determined its dimension. I am using this to set the width of the HBox.

If you need to set the width of the VBox, then you may wrap a frame around the VBox and use its width setter set the width of the HBox.


{curl 6.0 applet}
{curl-file-attributes character-encoding = "windows-latin-1"}
 
 
{def h =
    {HBox
        background = "pink",            
        height = 1cm
    }
}
 
{def v =
    {VBox
        background = "lime",
        "Value 1",
        {bold Value 2},
        {italic Hello how are you?},
        width =
            {proc {g:Graphic, e:OriginElastic}:OriginElastic
                set h.width = {e.set-total e.preferred-size / 2}
 
                {return e}
            }
    }
}
 
 
 
 
{value v}
 
{value h}
 
Click to view markecho's profile Level 2 markecho 35 posts since
Oct 17, 2007
4. Re: Is it possible that change the return value of add-stretch procedure's to a distance type variable? Jul 3, 2008 6:26 PM

tdeng , fukuta, Kamal , thank you very much,

From your answers , I learned a lot of knowledge about Graphic's feature.