|
YCP UI Widget Reference
Back to the widget index
HWeight VWeight
|
Control relative size of layouts
|
|
Description
This widget is used to control the layout. When a HBox or
VBox widget decides how to devide remaining space amount two
stretchable widgets, their weights are taken into account. This
widget is used to change the weight of the child widget. Each widget has a
vertical and a horizontal weight. You can change on or both of them. If you
use HVWeight, the weight in both dimensions is set to the same
value.
Note: No real widget is created ( any more ), just the weight value is
passed to the child widget.
See the Layout HOWTO for details.
Arguments
integer
|
weight
|
the new weight of the child widget
|
term
|
child
|
the child widget
|
Special Properties
None
Sample Usage
`HWeight( 2, `SelectionBox( "Language" ) )
Examples
{
UI::OpenDialog(
`HBox(
`HWeight(1, `PushButton("First Button (W: 50)")),
`PushButton("Small Button"),
`HWeight(1, `PushButton("Second Button (Weight 50 - this one determines the total width"))
)
);
UI::UserInput();
UI::CloseDialog();
}
|
{
// Layout example:
//
// Build a dialog with three equal sized buttons.
//
// The equal `HWeight()s will make the buttons equal sized.
// When resized larger, all buttons will retain their size.
// Excess space will go to the HStretch() widgets between the
// buttons, i.e. there will be empty space between the buttons.
UI::OpenDialog(
`HBox(
`HWeight(1, `PushButton( `opt(`default), "&OK" ) ),
`HStretch(),
`HWeight(1, `PushButton( "&Cancel everything" ) ),
`HStretch(),
`HWeight(1, `PushButton( "&Help" ) )
)
);
UI::UserInput();
UI::CloseDialog();
}
|
|
{
// Layout example:
//
// Build a dialog with three equal sized buttons,
// this time with some spacing in between.
//
// The equal `HWeight()s will make the buttons even sized.
// When resized larger, all buttons will retain their size.
// Excess space will go to the HSpacing() widgets between the
// buttons, i.e. there will be empty space between the buttons.
//
// Notice the importance of `opt(`hstretch) for the `HSpacing()s
// here: This is what makes the HSpacing()s grow. Otherwise, they
// would retain a constant size, and the buttons would grow.
UI::OpenDialog(
`HBox(
`HWeight(1, `PushButton( `opt(`default), "&OK" ) ),
`HSpacing(`opt(`hstretch), 3),
`HWeight(1, `PushButton( "&Cancel everything" ) ),
`HSpacing(`opt(`hstretch), 3),
`HWeight(1, `PushButton( "&Help" ) )
)
);
UI::UserInput();
UI::CloseDialog();
}
|
|
{
// Layout example:
//
// Build a dialog with three equal sized buttons.
//
// The equal `HWeight()s will make the buttons equal sized.
// When resized, all buttons will resize equally in order to
// maintain the equal layout weights.
UI::OpenDialog(
`HBox(
`HWeight(1, `PushButton( `opt(`default), "&OK" ) ),
`HWeight(1, `PushButton( "&Cancel everything" ) ),
`HWeight(1, `PushButton( "&Help" ) )
)
);
UI::UserInput();
UI::CloseDialog();
}
|
|
{
// Layout example:
//
// Build a dialog with three widgets with different weights and
// two widgets without any weight.
//
// All widgets will get at least their "nice size". The weighted
// ones may get even more to maintain their share of the overall
// weight.
//
// Upon resize all widgets will resize to maintain their
// respective weights at all times. The non-weighted widgets will
// retain their "nice size" regardless whether or not they are
// stretchable.
//
UI::OpenDialog(
`HBox(
`HWeight( 33, `PushButton( `opt(`default), "OK\n33%" ) ),
`PushButton( `opt(`hstretch), "Apply\nNo Weight" ),
`HWeight( 33, `PushButton( "Cancel\n33%" ) ),
`PushButton( "Reset to defaults\nNo Weight" ),
`HWeight( 66, `PushButton( "Help\n66%" ) )
)
);
UI::UserInput();
UI::CloseDialog();
}
|
|
{
// Layout example:
//
// Build a dialog with three widgets with different weights.
//
// Weights do not need to add up to 100 or any other special
// number, but it helps the application programmer to keep track
// of the percentage of each part of the layout.
//
// Notice how the second button commands the overall size of the
// dialog since it has the largest "nice size" to "weight" ratio.
//
// Upon resize all widgets will resize to maintain their
// respective weights at all times.
//
UI::OpenDialog(
`HBox(
`HWeight( 25, `PushButton( `opt(`default), "OK\n25%" ) ),
`HWeight( 25, `PushButton( "Cancel everything\n25%" ) ),
`HWeight( 50, `PushButton( "Help\n50%" ) )
)
);
UI::UserInput();
UI::CloseDialog();
}
|
|
{
// Layout example:
//
// Build a dialog with three widgets with different weights.
//
// Weights do not need to add up to 100 or any other special
// number, but it helps the application programmer to keep track
// of the percentage of each part of the layout.
//
// Notice how the second button commands the overall size of the
// dialog since it has the largest "nice size" to "weight" ratio.
//
// Upon resize all widgets will resize to maintain their
// respective weights at all times.
//
UI::OpenDialog(
`HBox(
`HWeight( 1, `PushButton( `opt(`default), "OK\n25%" ) ),
`HWeight( 1, `PushButton( "Cancel everything\n25%" ) ),
`HWeight( 2, `PushButton( "Help\n50%" ) )
)
);
UI::UserInput();
UI::CloseDialog();
}
|
Back to the widget index
|