The OpenD Programming Language

Padding

Convenience mixin for overriding all four sides of margin or padding in a Widget with the same code. It mixes in the given string as the return value of the four overridden methods.

class MyWidget : Widget {
	this(Widget parent) { super(parent); }

	// set paddingLeft, paddingRight, paddingTop, and paddingBottom all to `return 4;` in one go:
	mixin Padding!q{4};

	// set marginLeft, marginRight, marginTop, and marginBottom all to `return 8;` in one go:
	mixin Margin!q{8};

	// but if I specify one outside, it overrides the override, so now marginLeft is 2,
	// while Top/Bottom/Right remain 8 from the mixin above.
	override int marginLeft() { return 2; }
}
More...
mixin template Padding (
string code
) {}

Detailed Description

The minigui layout model is based on the web's CSS box model. The layout engine* arranges widgets based on their margin for separation and assigns them a size based on thier preferences (e.g. Widget.minHeight) and the available space. Widgets are assigned a size by the layout engine. Inside this size, they have a border (see Widget.Style.borderWidth), then padding space, and then their content. Their content box may also have an outline drawn on top of it (see Widget.Style.outlineStyle).

Padding is the area inside a widget where its background is drawn, but the content avoids.

Margin is the area between widgets. The algorithm is the spacing between any two widgets is the max of their adjacent margins (not the sum!).

* Some widgets do not participate in placement, e.g. StaticPosition, and some layout systems do their own separate thing too; ultimately, these properties are just hints to the layout function and you can always implement your own to do whatever you want. But this statement is still mostly true.

Meta