File: component.bs

package info (click to toggle)
storm-lang 0.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 52,004 kB
  • sloc: ansic: 261,462; cpp: 140,405; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (62 lines) | stat: -rw-r--r-- 1,698 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use core:geometry;

/**
 * Describes a component in the layout hierarchy.
 *
 * A component is a rectangle that will be laid out according to the rules of the active Layout. The
 * Component class also stores information about the underlying component, such as minimum size and
 * other component-specific information.
 *
 * Provide a function called `component` to wrap custom types inside the `Component` class. The
 * system will try to call that function automatically when possible.
 *
 * Generally, all information inside a particular component is assumed to be read-only.
 */
class Component {
	// Optional reference to the root of a hierarchy of components. The layout syntax examines this
	// member whenever a component is added to the hierarchy and if it is set adds that component
	// instead. This can be used to bundle layouts together inside a function, and still have the
	// layout syntax add the proper root component.
	Component? bundleRoot;

	// Get either `bundleRoot` if it is set, or `this`.
	Component toAdd() {
		if (bundleRoot)
			bundleRoot;
		else
			this;
	}

	// Get the position of this component.
	Rect pos() {
		Rect();
	}

	// Set the position of this component.
	assign pos(Rect p) {}

	// Get the minimum size of this component.
	Size minSize() {
		Size(0, 0);
	}

	// Traverse the hierarchy to find all components.
	void findAll(fn(Component)->void fn) {
		fn.call(this);
	}
}


/**
 * A component that just takes up space in the layout.
 */
class FillBox extends Component {
	Size size;

	init(Size size) { init() { size = size; } }
	init(Float w, Float h) { init() { size(w, h); } }

	// Minimum size of the component.
	Size minSize() : override { size; }
}