To create your own classes that will be able to work with the layout-library, your classes
must derive from both MView and BView. You must implement the layoutprefs and layout members of the MView class.
If your classes require any special handling with regard to colors, you should also implement the setcolor() function. Similarly, if your class does anything special with fonts, you should implement the reloadfont() function. Both these functions are explained in the Fonts & Colors chapter.
Through the layoutprefs-function, you tell the system about the minimum and maximum size
of your class.
The grouping classes guarantee that your object will not be asked to become smaller
than the size you give as the minimum size. Note that this guarantee is currently enforced
by making the minimum window-size equal to the minimum size of the root-MView. If you do not respect
the minimum size of a grouping class, then the grouping class will not respect the minimum size
of the MViews it contains.
The grouping classes also guarantee that your object will not be asked to become larger than the maximum
size. If the available space is larger, your object will be centered in the available space.
If you want to have all the available space, even if it is bigger than the "maximum" size, you
should set the M_USE_FULL_SIZE bit in the flags member of MView. This feature is mostly intended
for grouping classes, but other classes may benefit from it as well.
The layoutprefs-function is defined as:
minimax layoutprefs(void)and the minimax class is defined as:
class minimax { struct xypair { float x,y;}; public: xypair mini; xypair maxi; float weight; minimax(int minx=0,int miny=0, int maxx=1E5,int maxy=1E5, float wght=1); };where the mini and maxi members are used to store the minimum and maximum size of the object.
NOTE: the minimum and maximum sizes are specified as the number of pixels that the object is wide or high. An object where mpm.mini.x=mpm.maxi.x=mpm.mini.y=mpm.maxi.y=10 will be 10 pixels wide and 10 pixels high. Its Bounds() rectangle will therefore be (0,0,9,9).
Through the layout function, your class is asked to layout itself. Again, if you have correctly setup the window-limits to be the limits of the root-MView, then it is guaranteed that your object will not be asked to resize to a size that's smaller than its minimum size, or bigger than its maximum size.
The layout-function is defined as:
BRect layout(BRect size)The size parameter determines where the object should be placed in its parent. A simple implementation of the layout function will simply do
BRect MyClass::layout(BRect rect) { ResizeTo(rect.Width(),rect.Height()); MoveTo(rect.LeftTop()); return rect; }The layout function returns the amount of space actually used by the object.
To create your own grouping classes, you must take a little more responsibility.
Some things to remember, to prevent some common mistakes:
Copyright © 1997 Marco Nelissen (marcone@xs4all.nl) All rights reserved.
Be, BeOS, BeBox, BeWare, GeekPort, the Be logo, the BeOS logo, roColour, Beatware and Beatware painter are trademarks or registered trademarks of their respective owners.