The layout-library is a library of classes, which together allow you to easily make fully resizable and font-sensitive GUI's. It does this by giving standard Be-classes a little more knowledge about themselves, and adding some custom classes that do the actual layout-work.
At the base of the library are two classes: minimax and MView.
The MView class is an abstract class that declares the layout and layoutprefs methods. Through these methods, an MView-derived class is able to tell the world about its preferred sizes, and the world is able to tell the MView-derived class to go resize itself to a certain size and position.
The minimax class is a class that is used to store an MViews minimum and maximum size (hence the name). It also stores the relative weight of the MView. Each MView has a minimax-member called mpm
All classes that participate in the layout-system must derive from MView, and implement the layout and layoutprefs members. Depending on the function of the class, these implementations can be very complex, or very simple, like so:
minimax MyClass::layoutprefs() { return mpm; } BRect MyClass::layout(BRect rect) { ResizeTo(rect.Width(),rect.Height()); MoveTo(rect.LeftTop()); return rect; }The above would be used to implement the layout and layoutprefs members of a class with no constraints as to its minimum and maximum sizes. Note that the class also derives from BView, from where it obtains the ResizeTo() and MoveTo() members.
Some of the classes in the library have as their only purpose in life to group other classes together. The ones you'll use most frequently are the HGroup and VGroup classes, but there are also grouping classes that group together MViews using tabviews, or merely add a border around MViews.
Other classes are the controls that you interact with, like buttons, checkboxes and sliders.
To build a fully resizable GUI, you create a tree of objects. At the root of the tree is a grouping class, the nodes in the tree also consist of grouping classes, and the leaves of the tree are the controls you interact with.
A simple example is:
MView *topview=new VGroup ( new HGroup ( new MButton("upper left corner"), new MButton("upper right corner"), 0 ), new MButton("along the bottom"), 0 );The above defines a group of three buttons. Two of those buttons are aranged in a row along the top, with each button getting half of the available space. The third button is placed at the bottom, below the other two buttons.
Some things to keep in mind:
Once you have built the tree, you call the layoutprefs member of the root-MView. This causes the internal states of all the MViews to be initialised.
When you are ready to display the GUI on screen, you call the layout member of the root-MView. This will cause all grouping classes to determine how much space they have, and layout themselves and their children accordingly.
Note that you only need to call layoutprefs once (unless you add items to the tree later on, in which case you have to call it again), but that you have to call layout everytime the window gets resized.
Typically, you'll do this from BWindow::FrameResized()
Copyright © 1997 Marco Nelissen (marcone@xs4all.nl) All rights reserved.
Be is a registered trademark; BeOS, BeBox, BeWare, GeekPort, the Be logo, and the BeOS logo are trademarks of Be, Inc.