CHAPTER 3 Layout

Dynamic Extensibility


We sometimes need to change the behavior of a glyph (a good example is changing a glyph's default alignment) and we need to do it without the burden of implementing and compiling a subclass. We often use the term monoglyph to refer to glyphs that change the behavior of other glyphs. Such glyphs redefine certain behavior (such as how alignment is requested) and then delegate other behaviors to their "body" (the glyph they are "wrapping".)

As an example, lets wrap the vbox of figure 3-3 inside a monoglyph that prints debug information to standard output.

GlyphVar debugged_vbox = new DebugGlyph(
	vbox, "vbox", DebugGlyph::trace_request
);
The wrapped vbox can still be placed into the hbox:

hbox->append(debugged_vbox);
because the drawing and other behavior is delegated to the body vbox. The constant DebugGlyph::trace_request tells the DebugGlyph how much of its body's behavior to redefine. "Trace_request" means just print the debug information when the Glyph::Request() operation is called.

When the program is run, the component displays and interacts exactly as before, except now a message is print to standard output each time the hbox calls request on its child vbox:

   vbox(0x3abb8) request  225.00, 170.00 @ 1.0, undef
This shows that the vbox requests a "natural size" of 225.00 in the X dimension (with alignment = 0.0) and a natural size of 170.00 in the Y dimension with an alignment of 1.0. The Z dimension is undefined. Note that this verifies our hypothesis that vboxes request vertical alignments of 1.0.

As a second example of dynamically modifying behavior, let's wrap the buttons of figure 3-1 with monoglyphs that change their horizontal alignment so that we get a "stairstep" effect. As shown in the following code, we get these monoglyphs from the layout kit. This code results in the layout shown in figure 3-8.

Glyph_var vbox = layouts->vbox();
vbox->append(Glyph_var(layouts->halign(button1, 1.0)));
vbox->append(Glyph_var(layouts->halign(button2, 0.5)));
vbox->append(button3); 
Glyph_var margin = layouts->margin(vbox, 15.0);
FrescoLib::run(nil, margin);

Fresco's layout kit provides various type of monoglyphs which override their bodys as follows:

We'll explore natural size, stretchability, and shrinkability in the next section.


Copyright (c) 1994 by Steve Churchill
Comments or questions? Contact Steve Churchill (stevec@faslab.com)

Generated with CERN WebMaker