File: FlowLayout.sc

package info (click to toggle)
supercollider 1%3A3.13.0%2Brepack-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 80,296 kB
  • sloc: cpp: 476,363; lisp: 84,680; ansic: 77,685; sh: 25,509; python: 7,909; makefile: 3,440; perl: 1,964; javascript: 974; xml: 826; java: 677; yacc: 314; lex: 175; objc: 152; ruby: 136
file content (95 lines) | stat: -rw-r--r-- 2,362 bytes parent folder | download | duplicates (7)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
Decorator {
	place { arg view; this.subclassResponsibility(\place); }

	remove { arg view; this.subclassResponsibility(\remove); }

	clear { this.subclassResponsibility(\clear); }

	bounds { this.subclassResponsibility(\bounds); }

	bounds_ { arg bounds; this.subclassResponsibility(\bounds_); }

	gap { this.subclassResponsibility(\gap); }
	gap_ { arg gap; this.subclassResponsibility(\gap_); }

	margin { this.subclassResponsibility(\margin); }
	margin_ { arg margin; this.subclassResponsibility(\margin_); }
}

FlowLayout : Decorator {
	var <bounds, <>margin, <>gap;
	var <>left, <>top, <>maxHeight,<>maxRight;
	var <>owner;

	*new { arg bounds, margin, gap;
		^super.newCopyArgs(bounds, margin, gap).init
	}
	init {
		gap = gap ? Point(4,4);
		margin = margin ? Point(4,4);
		this.reset;
	}
	clear { this.reset; }
	reset {
		maxRight = left = bounds.left + margin.x;
		top = bounds.top + margin.y;
		maxHeight  = 0;
	}
	place { arg view;
		var height, width,vbounds;
		vbounds = view.bounds;
		width = vbounds.width;
		height = vbounds.height;
		if ((left + width) > (bounds.right - margin.x), { this.nextLine; });

		view.bounds = Rect(left, top, width, height);

		maxRight = max(maxRight,left + width);
		left = left + width + gap.x;
		maxHeight = max(maxHeight, height);
	}
	remove { }
	nextLine {
		left = bounds.left + margin.x;
		top = top + maxHeight + gap.y;
		maxHeight = 0;
	}
	shift { arg x=0, y=0;
		left = left + x;
		top = top + y;
	}
	innerBounds {
		^bounds.insetBy(margin.x * 2,margin.y * 2)
	}
	bounds_ { arg b;
		var d;
		left = left + ( d = (b.left - bounds.left));
		maxRight = maxRight + (d);
		top = top + (d = (b.top - bounds.top));
		maxHeight = maxHeight + (d);
		bounds = b;
		// and then you need to re-place all views
		// but nextLine will be broken, see FlowView
	}
	currentBounds {
		var currentBounds;
		currentBounds = bounds;
		currentBounds.height = top + maxHeight;
		^currentBounds
	}
	// rounded out to the nearest rect + margin
	used {
		^Rect(bounds.left,bounds.top,
			maxRight + margin.x - bounds.left,
			(top + maxHeight + margin.y ) - bounds.top)
	}
	// largest allocatable rect starting in the current row
	// going down as far as possible
	indentedRemaining {
		var inb;
		inb = this.innerBounds;
		^Rect(left,top,
			inb.width - (left - inb.left - margin.x),
			inb.height - (top - inb.top - margin.y))
	}
}