File: TreeView.schelp

package info (click to toggle)
supercollider 1%3A3.13.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 80,292 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 (183 lines) | stat: -rw-r--r-- 5,149 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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
CLASS:: TreeView
summary:: A view displaying a tree of items with columns
categories:: GUI>Views

DESCRIPTION::

A view that displays a hierarchy of items. It is divided into rows and column: each row represents an item, and each column represents a different data field of the items.

The items are represented in code by instances of link::Classes/TreeViewItem::, returned by the various TreeView methods. Top level items are added via the TreeView interface, while child items are added via the TreeViewItem interface, which also allows to manipulate items in more detail after their creation.

Items can be visually sorted with link::#-sort::, or by clicking on one of the column headers, if link::#-canSort:: is enabled.

Each item can hold other views in each of its data fields, which allows for rich graphical interaction. See link::Classes/TreeViewItem#-setView::.


CLASSMETHODS::

PRIVATE:: key

INSTANCEMETHODS::

PRIVATE:: prForEachColumnDataPair
PRIVATE:: prValidItem


SUBSECTION:: Data

METHOD:: columns
	Gets or sets the number of columns (data fields) and their names. When setting a smaller number of columns than the current the extra columns will be removed, and hence all the data stored stored in those columns.

	ARGUMENT::
		An array of Strings for column names.

METHOD:: numColumns
	The total number of columns (data fields).

METHOD:: addItem
	Append a new top-level item.

	ARGUMENT:: strings
		An array of Strings (or nil), each for the text of one data field.
	RETURNS::
		An instance of TreeViewItem representing the new item.

METHOD:: insertItem
	Insert a new top-level item at code::index::.

	ARGUMENT:: index
		The position at which to insert the item.
	ARGUMENT:: strings
		An array of Strings (or nil), each for the text of one data field.
	RETURNS::
		An instance of TreeViewItem representing the new item.

METHOD:: removeItem
	Remove the given code::item::. After the item is removed, any usage of the related TreeViewItems will have no effect.

	ARGUMENT::
		An instance of TreeViewItem.

METHOD:: numItems
	The total number of items.

METHOD:: clear
    Removes all items.

METHOD:: currentItem
	Gets or sets the currently selected item.

	ARGUMENT::
		An instance of TreeViewItem.
	RETURNS::
		An instance of TreeViewItem or nil, if no current item.

METHOD:: itemAt
	The item at code::index::.

METHOD:: childAt
	Alias for link::#-itemAt::, provided for compatibility with TreeViewItem.

METHOD:: addChild
	Alias for link::#-addItem::, provided for compatibility with TreeViewItem.

METHOD:: insertChild
	Alias for link::#-addChild::, provided for compatibility with TreeViewItem.

SUBSECTION:: Appearance

METHOD:: sort
	Sort items by data in code::column::. This works regardless of link::#-canSort::.

	NOTE:: Sorting has no effect on the logical order of the items, it only affects how they are displayed. ::

	ARGUMENT:: column
		The integer column index to sort by.
	ARGUMENT:: descending
		Whether to sort in descending or ascending fashion. The default is ascending.

METHOD:: columnWidth

	ARGUMENT:: column
		The integer index of a column
	RETURNS::
		Integer width of column in pixels. If code::column:: is not in the range
		code::0..(numColumns-1)::, returns code::-1::.

METHOD:: setColumnWidth

Sets the width of a column. The rightmost column must extend at least to the right bound of the
TreeView.

	ARGUMENT:: column
		The integer index of the column to modify
	ARGUMENT:: width
		Integer width in pixels

PRIVATE:: background


SUBSECTION:: Interaction

METHOD:: canSort
	Whether the user can sort the items by clicking on a column header.

	When setting to code::true::, the items will be sorted immediately according to the current sorting column. While code::true::, the view will also automatically sort new items.

	The default is code::false::.

	See also: link::#-sort::.




SUBSECTION:: Actions

METHOD:: itemPressedAction
	The object to be evaluated when a mouse button is pressed on an item, passing this view as the argument.

METHOD:: onItemChanged
	The object to be evaluated whenever the current item changes, passing this view as the argument.


EXAMPLES::

CODE::

(
var t = TreeView().front;
t.columns_(["a", "b", "c", "d"]);
t.addItem(["A1", "B1", "C1", "D1"]);
t.addItem(["A2", "B2", "C2"]);
t.addItem(["A3", "B3"]);
t.addItem(["A4"]);
)


//sorting example
(
var names = ["black", "white", "red", "green", "blue", "cyan", "magenta", "yellow"];
var colors = names.collect{|str| Color.perform(str.asSymbol)};
var window, tree, popup;
window = Window.new("TreeView example - RGBA colors").front;
window.view.layout_(VLayout(
	tree = TreeView()
));
tree.columns_(["Index", "Name", "Int", "Hex"]);
tree.font = Font.defaultMonoFace;
tree.setColumnWidth(0, 60);
tree.setColumnWidth(2, 130);
names.do{|str, i|
	var intString = "% % % %".format(*(colors[i].asArray*255).asInteger);
	tree.addItem([i, str, intString, colors[i].hexString]);
};
tree.numItems.do{|i|
	var c = [Color.clear, colors[i], Color.clear, Color.clear];
	tree.itemAt(i).colors_(c).textColors_(Color.grey);
};
tree.onItemChanged_({|view|
	view.currentItem.strings.postln;
});
tree.canSort = true;
)
::