Place Class Reference
[Layout of widgets in windows]

A class to position objects in a rectangular area. More...

List of all members.

Public Member Functions

void newCol ()
 Move to next column of objects.
void newRow ()
 Move to next row of objects.
 Place ()
 Constructor without parameters.
void positionBelow (struct Rectangle &obj)
 Sets obj.pos to the current position, and updates the position by obj.size.
void positionToRight (struct Rectangle &obj)
 Sets obj.pos to the current position, and updates the position by obj.size.
void setBoundsBorders (const SmartWin::Point &upleft, const SmartWin::Point &lowright, const int borderX=0, const int borderY=0)
 Set an area to place things between upleft and lowright corners.
void setBoundsBorders (const SmartWin::Point &sizefromZenith, const int borderX=0, const int borderY=0)
 Set the bounds and borders from a size. (implied 0,0 position).
void setBoundsBorders (const SmartWin::Rectangle &rect, const int borderX=0, const int borderY=0)
 and borders.
void sizeForRemainingSpace (struct Rectangle &obj)
 Set obj.pos and obj.size to fill the rest of the bounds.
void sizeOfCell (int rows, int cols, Point &size)
 calculate the size of one cell.
void tabTo (double xfract)
 bounding rectangle.


Detailed Description

A class to position objects in a rectangular area.

You start by using one of the setBoundsBorders calls to establish the rectangular area. This call gives you the option of setting x and y borders around the objects.

The size of the objects are assumed to be known, but you can use sizeOfCell to calculate what the size of an object should be to fit perfectly into a grid arrangement in the area.

Then you use positionToRight( struct Rectangle & obj ), passing only the obj.size, and receiving the calculated obj.pos. This gives a rectangle suitable for the AspectSizable functions.

positionToRight's layout approach is left to right until the next line of objects starts just below the previous line.

These optional functions let you customize the placement operation:
void newRow()
void tabTo( double xfract )
void sizeForRemainingSpace( struct Rectangle &obj )

positionBelow() and newCol() are similar functions in case you want to layout a column of objects


Constructor & Destructor Documentation

Place (  ) 

Constructor without parameters.

In this constructor you can place Widgets without constraints. The parent window may not show them though. You add constraints with the SetBoundsBorders functions.


Member Function Documentation

void newCol (  ) 

Move to next column of objects.

Allows the caller to decide when to move to the next column. or used internally when a object would go past the Y bound.

void newRow (  ) 

Move to next row of objects.

Allows the caller to decide when to move to the next row. or used internally when a object would go past the X bound.

void positionBelow ( struct Rectangle obj  ) 

Sets obj.pos to the current position, and updates the position by obj.size.

Sets the obj.pos to the current position, and calculates the next position based upon obj.size.
The next object will be placed under the previous object, or in the next column if needed.

void positionToRight ( struct Rectangle obj  ) 

Sets obj.pos to the current position, and updates the position by obj.size.

Sets the obj.pos to the current position, and calculates the next position based upon obj.size.
The next object will be placed to the right of the current object, or in the next row if needed.

void setBoundsBorders ( const SmartWin::Point upleft,
const SmartWin::Point lowright,
const int  borderX = 0,
const int  borderY = 0 
)

Set an area to place things between upleft and lowright corners.

Given two coordinates, prepare the bounds for subsequent placement. upleft does not have to be 0,0, but it usually is. Set the inter-object gap for x and y

void setBoundsBorders ( const SmartWin::Point sizefromZenith,
const int  borderX = 0,
const int  borderY = 0 
)

Set the bounds and borders from a size. (implied 0,0 position).

Set an area to place things between an uppper left corner of (0,0) and the lowright corner.
Set the inter-object gap for x and y.
Use this for those cases in which you want to discard the current position and start over again at 0,0. An example is using WidgetChildWindow. Putting widgets inside WidgetChildWindow requires positioning at 0,0 since the coordinates are now relative to the WindowChildWindow.

void setBoundsBorders ( const SmartWin::Rectangle rect,
const int  borderX = 0,
const int  borderY = 0 
)

and borders.

This is suitable for cases in which you want place objects inside a rect that does NOT have to start at 0,0.

void sizeForRemainingSpace ( struct Rectangle obj  ) 

Set obj.pos and obj.size to fill the rest of the bounds.

Set obj.pos and obj.size to fill the rest of the bounds. The object need to be positioned at the current position, and sized to take all the remaining space in the area.

void sizeOfCell ( int  rows,
int  cols,
Point size 
)

calculate the size of one cell.

Calculate the size of one cell of the bounds.
It considers the borders between the cells.
OUTPUT: size

void tabTo ( double  xfract  ) 

bounding rectangle.

Allows the caller to control how Widgets are placed in the bounding rectangle. For example, if the bounding rectangle was ( pos(100, 0), size(100, 300) ),
and the curent position was (120, 200), then tabTo(0.5)
would result in the current position becoming (150, 200)

Back to SmartWin website
SourceForge.net Logo