| |
FIT can be used if you need to place a control between two other controls. Its usage is a bit more complex than the other ones available (FILL, PREFERRED, SAME), because FIT requires that you specify two controls instead of one. However, there are no positioning methods that accepts two controls! In order to make it work, you must follow a few steps, which are described below. Note that it is possible to use FIT only in the width or height, never in both at the same time.
The general rule is: first, you add and position the control that gões before, then the one that gões after, finally the control that you want to FIT between these two, passing the first control as parameter. This way, TotalCross will use the last but one control and the control you pass as parameter.
The methods available to add a control and specify its bounds are:
- add(c, x,y)
- add(c, x,y, relativeTo)
- add(c); c.setRect(x,y,width,height)
- add(c); c.setRect(x,y,width,height, relativeTo)
- add(c, x,y,width,height)
- add(c, x,y,width,height, relativeTo)
The only method that can be used with FIT is number 4. Lets go for a sample. Imagine that you want to place a Label at left, a Button at right and an Edit that takes the space between both:
add(label, LEFT,TOP); // or any other position
add(button, RIGHT, SAME);
add(edit, AFTER, SAME, FIT, PREFERRED, label);
Another example: a Button at top, a Label at bottom, and a ListBox between them:
add(button, LEFT,TOP);
add(label, LEFT,BOTTOM);
add(listbox, LEFT,AFTER+2, FILL, FIT-2, button);
You can also use a small adjustment, like in the sample above, but only remembering that the positioning is always relative to the control you passed as parameter in the setRect method (in this case, button). Therefore, the ListBox´s y position is AFTER+2 the button.
A last sample: you want to position a Button in the footer, and a ListBox taking the space between the Window´s title and the Button:
add(button, RIGHT, BOTTOM);
add(listbox, LEFT, TOP, FILL, FIT, button);
In this example, since no other control was added, TotalCross will use the parent container as the second control.
|
|