1 /**
2 Control to show a tree of items.
3 
4 Copyright:
5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.  
6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)  
7 Copyright (c) 2017-2018 Godot-D contributors  
8 
9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License)
10 
11 
12 */
13 module godot.tree;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.meta;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.object;
22 import godot.classdb;
23 import godot.control;
24 import godot.inputevent;
25 import godot.treeitem;
26 import godot.canvasitem;
27 import godot.node;
28 /**
29 Control to show a tree of items.
30 
31 This shows a tree of items that can be selected, expanded and collapsed. The tree can have multiple columns with custom controls like text editing, buttons and popups. It can be useful for structured displays and interactions.
32 Trees are built via code, using $(D TreeItem) objects to create the structure. They have a single root but multiple roots can be simulated if a dummy hidden root is added.
33 
34 
35 func _ready():
36     var tree = Tree.new()
37     var root = tree.create_item()
38     tree.set_hide_root(true)
39     var child1 = tree.create_item(root)
40     var child2 = tree.create_item(root)
41     var subchild1 = tree.create_item(child1)
42     subchild1.set_text(0, "Subchild1")
43 
44 
45 */
46 @GodotBaseClass struct Tree
47 {
48 	enum string _GODOT_internal_name = "Tree";
49 public:
50 @nogc nothrow:
51 	union { godot_object _godot_object; Control _GODOT_base; }
52 	alias _GODOT_base this;
53 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
54 	package(godot) __gshared bool _classBindingInitialized = false;
55 	package(godot) static struct _classBinding
56 	{
57 		__gshared:
58 		@GodotName("_range_click_timeout") GodotMethod!(void) _rangeClickTimeout;
59 		@GodotName("_gui_input") GodotMethod!(void, InputEvent) _guiInput;
60 		@GodotName("_popup_select") GodotMethod!(void, long) _popupSelect;
61 		@GodotName("_text_editor_enter") GodotMethod!(void, String) _textEditorEnter;
62 		@GodotName("_text_editor_modal_close") GodotMethod!(void) _textEditorModalClose;
63 		@GodotName("_value_editor_changed") GodotMethod!(void, double) _valueEditorChanged;
64 		@GodotName("_scroll_moved") GodotMethod!(void, double) _scrollMoved;
65 		@GodotName("clear") GodotMethod!(void) clear;
66 		@GodotName("create_item") GodotMethod!(TreeItem, GodotObject, long) createItem;
67 		@GodotName("get_root") GodotMethod!(TreeItem) getRoot;
68 		@GodotName("set_column_min_width") GodotMethod!(void, long, long) setColumnMinWidth;
69 		@GodotName("set_column_expand") GodotMethod!(void, long, bool) setColumnExpand;
70 		@GodotName("get_column_width") GodotMethod!(long, long) getColumnWidth;
71 		@GodotName("set_hide_root") GodotMethod!(void, bool) setHideRoot;
72 		@GodotName("is_root_hidden") GodotMethod!(bool) isRootHidden;
73 		@GodotName("get_next_selected") GodotMethod!(TreeItem, GodotObject) getNextSelected;
74 		@GodotName("get_selected") GodotMethod!(TreeItem) getSelected;
75 		@GodotName("get_selected_column") GodotMethod!(long) getSelectedColumn;
76 		@GodotName("get_pressed_button") GodotMethod!(long) getPressedButton;
77 		@GodotName("set_select_mode") GodotMethod!(void, long) setSelectMode;
78 		@GodotName("get_select_mode") GodotMethod!(Tree.SelectMode) getSelectMode;
79 		@GodotName("set_columns") GodotMethod!(void, long) setColumns;
80 		@GodotName("get_columns") GodotMethod!(long) getColumns;
81 		@GodotName("get_edited") GodotMethod!(TreeItem) getEdited;
82 		@GodotName("get_edited_column") GodotMethod!(long) getEditedColumn;
83 		@GodotName("get_custom_popup_rect") GodotMethod!(Rect2) getCustomPopupRect;
84 		@GodotName("get_item_area_rect") GodotMethod!(Rect2, GodotObject, long) getItemAreaRect;
85 		@GodotName("get_item_at_position") GodotMethod!(TreeItem, Vector2) getItemAtPosition;
86 		@GodotName("get_column_at_position") GodotMethod!(long, Vector2) getColumnAtPosition;
87 		@GodotName("get_drop_section_at_position") GodotMethod!(long, Vector2) getDropSectionAtPosition;
88 		@GodotName("ensure_cursor_is_visible") GodotMethod!(void) ensureCursorIsVisible;
89 		@GodotName("set_column_titles_visible") GodotMethod!(void, bool) setColumnTitlesVisible;
90 		@GodotName("are_column_titles_visible") GodotMethod!(bool) areColumnTitlesVisible;
91 		@GodotName("set_column_title") GodotMethod!(void, long, String) setColumnTitle;
92 		@GodotName("get_column_title") GodotMethod!(String, long) getColumnTitle;
93 		@GodotName("get_scroll") GodotMethod!(Vector2) getScroll;
94 		@GodotName("set_hide_folding") GodotMethod!(void, bool) setHideFolding;
95 		@GodotName("is_folding_hidden") GodotMethod!(bool) isFoldingHidden;
96 		@GodotName("set_drop_mode_flags") GodotMethod!(void, long) setDropModeFlags;
97 		@GodotName("get_drop_mode_flags") GodotMethod!(long) getDropModeFlags;
98 		@GodotName("set_allow_rmb_select") GodotMethod!(void, bool) setAllowRmbSelect;
99 		@GodotName("get_allow_rmb_select") GodotMethod!(bool) getAllowRmbSelect;
100 		@GodotName("set_allow_reselect") GodotMethod!(void, bool) setAllowReselect;
101 		@GodotName("get_allow_reselect") GodotMethod!(bool) getAllowReselect;
102 	}
103 	bool opEquals(in Tree other) const { return _godot_object.ptr is other._godot_object.ptr; }
104 	Tree opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; }
105 	bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; }
106 	mixin baseCasts;
107 	static Tree _new()
108 	{
109 		static godot_class_constructor constructor;
110 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Tree");
111 		if(constructor is null) return typeof(this).init;
112 		return cast(Tree)(constructor());
113 	}
114 	@disable new(size_t s);
115 	/// 
116 	enum SelectMode : int
117 	{
118 		/**
119 		Allow selection of a single item at a time.
120 		*/
121 		selectSingle = 0,
122 		/**
123 		
124 		*/
125 		selectRow = 1,
126 		/**
127 		Allow selection of multiple items at the same time.
128 		*/
129 		selectMulti = 2,
130 	}
131 	/// 
132 	enum DropModeFlags : int
133 	{
134 		/**
135 		
136 		*/
137 		dropModeDisabled = 0,
138 		/**
139 		
140 		*/
141 		dropModeOnItem = 1,
142 		/**
143 		
144 		*/
145 		dropModeInbetween = 2,
146 	}
147 	/// 
148 	enum Constants : int
149 	{
150 		dropModeDisabled = 0,
151 		selectSingle = 0,
152 		selectRow = 1,
153 		dropModeOnItem = 1,
154 		dropModeInbetween = 2,
155 		selectMulti = 2,
156 	}
157 	/**
158 	
159 	*/
160 	void _rangeClickTimeout()
161 	{
162 		Array _GODOT_args = Array.empty_array;
163 		String _GODOT_method_name = String("_range_click_timeout");
164 		this.callv(_GODOT_method_name, _GODOT_args);
165 	}
166 	/**
167 	
168 	*/
169 	void _guiInput(InputEvent arg0)
170 	{
171 		Array _GODOT_args = Array.empty_array;
172 		_GODOT_args.append(arg0);
173 		String _GODOT_method_name = String("_gui_input");
174 		this.callv(_GODOT_method_name, _GODOT_args);
175 	}
176 	/**
177 	
178 	*/
179 	void _popupSelect(in long arg0)
180 	{
181 		Array _GODOT_args = Array.empty_array;
182 		_GODOT_args.append(arg0);
183 		String _GODOT_method_name = String("_popup_select");
184 		this.callv(_GODOT_method_name, _GODOT_args);
185 	}
186 	/**
187 	
188 	*/
189 	void _textEditorEnter(StringArg0)(in StringArg0 arg0)
190 	{
191 		Array _GODOT_args = Array.empty_array;
192 		_GODOT_args.append(arg0);
193 		String _GODOT_method_name = String("_text_editor_enter");
194 		this.callv(_GODOT_method_name, _GODOT_args);
195 	}
196 	/**
197 	
198 	*/
199 	void _textEditorModalClose()
200 	{
201 		Array _GODOT_args = Array.empty_array;
202 		String _GODOT_method_name = String("_text_editor_modal_close");
203 		this.callv(_GODOT_method_name, _GODOT_args);
204 	}
205 	/**
206 	
207 	*/
208 	void _valueEditorChanged(in double arg0)
209 	{
210 		Array _GODOT_args = Array.empty_array;
211 		_GODOT_args.append(arg0);
212 		String _GODOT_method_name = String("_value_editor_changed");
213 		this.callv(_GODOT_method_name, _GODOT_args);
214 	}
215 	/**
216 	
217 	*/
218 	void _scrollMoved(in double arg0)
219 	{
220 		Array _GODOT_args = Array.empty_array;
221 		_GODOT_args.append(arg0);
222 		String _GODOT_method_name = String("_scroll_moved");
223 		this.callv(_GODOT_method_name, _GODOT_args);
224 	}
225 	/**
226 	Clears the tree. This removes all items.
227 	*/
228 	void clear()
229 	{
230 		checkClassBinding!(typeof(this))();
231 		ptrcall!(void)(_classBinding.clear, _godot_object);
232 	}
233 	/**
234 	Create an item in the tree and add it as the last child of `parent`. If parent is not given, it will be added as the root's last child, or it'll the be the root itself if the tree is empty.
235 	*/
236 	TreeItem createItem(GodotObject parent = GodotObject.init, in long idx = -1)
237 	{
238 		checkClassBinding!(typeof(this))();
239 		return ptrcall!(TreeItem)(_classBinding.createItem, _godot_object, parent, idx);
240 	}
241 	/**
242 	Returns the tree's root item.
243 	*/
244 	TreeItem getRoot()
245 	{
246 		checkClassBinding!(typeof(this))();
247 		return ptrcall!(TreeItem)(_classBinding.getRoot, _godot_object);
248 	}
249 	/**
250 	Set the minimum width of a column.
251 	*/
252 	void setColumnMinWidth(in long column, in long min_width)
253 	{
254 		checkClassBinding!(typeof(this))();
255 		ptrcall!(void)(_classBinding.setColumnMinWidth, _godot_object, column, min_width);
256 	}
257 	/**
258 	If `true` the column will have the "Expand" flag of $(D Control).
259 	*/
260 	void setColumnExpand(in long column, in bool expand)
261 	{
262 		checkClassBinding!(typeof(this))();
263 		ptrcall!(void)(_classBinding.setColumnExpand, _godot_object, column, expand);
264 	}
265 	/**
266 	Returns the column's width in pixels.
267 	*/
268 	long getColumnWidth(in long column) const
269 	{
270 		checkClassBinding!(typeof(this))();
271 		return ptrcall!(long)(_classBinding.getColumnWidth, _godot_object, column);
272 	}
273 	/**
274 	
275 	*/
276 	void setHideRoot(in bool enable)
277 	{
278 		checkClassBinding!(typeof(this))();
279 		ptrcall!(void)(_classBinding.setHideRoot, _godot_object, enable);
280 	}
281 	/**
282 	
283 	*/
284 	bool isRootHidden() const
285 	{
286 		checkClassBinding!(typeof(this))();
287 		return ptrcall!(bool)(_classBinding.isRootHidden, _godot_object);
288 	}
289 	/**
290 	Returns the next selected item after the given one.
291 	*/
292 	TreeItem getNextSelected(GodotObject from)
293 	{
294 		checkClassBinding!(typeof(this))();
295 		return ptrcall!(TreeItem)(_classBinding.getNextSelected, _godot_object, from);
296 	}
297 	/**
298 	Returns the currently selected item.
299 	*/
300 	TreeItem getSelected() const
301 	{
302 		checkClassBinding!(typeof(this))();
303 		return ptrcall!(TreeItem)(_classBinding.getSelected, _godot_object);
304 	}
305 	/**
306 	Returns the current selection's column.
307 	*/
308 	long getSelectedColumn() const
309 	{
310 		checkClassBinding!(typeof(this))();
311 		return ptrcall!(long)(_classBinding.getSelectedColumn, _godot_object);
312 	}
313 	/**
314 	Returns the last pressed button's index.
315 	*/
316 	long getPressedButton() const
317 	{
318 		checkClassBinding!(typeof(this))();
319 		return ptrcall!(long)(_classBinding.getPressedButton, _godot_object);
320 	}
321 	/**
322 	
323 	*/
324 	void setSelectMode(in long mode)
325 	{
326 		checkClassBinding!(typeof(this))();
327 		ptrcall!(void)(_classBinding.setSelectMode, _godot_object, mode);
328 	}
329 	/**
330 	
331 	*/
332 	Tree.SelectMode getSelectMode() const
333 	{
334 		checkClassBinding!(typeof(this))();
335 		return ptrcall!(Tree.SelectMode)(_classBinding.getSelectMode, _godot_object);
336 	}
337 	/**
338 	
339 	*/
340 	void setColumns(in long amount)
341 	{
342 		checkClassBinding!(typeof(this))();
343 		ptrcall!(void)(_classBinding.setColumns, _godot_object, amount);
344 	}
345 	/**
346 	
347 	*/
348 	long getColumns() const
349 	{
350 		checkClassBinding!(typeof(this))();
351 		return ptrcall!(long)(_classBinding.getColumns, _godot_object);
352 	}
353 	/**
354 	Returns the currently edited item. This is only available for custom cell mode.
355 	*/
356 	TreeItem getEdited() const
357 	{
358 		checkClassBinding!(typeof(this))();
359 		return ptrcall!(TreeItem)(_classBinding.getEdited, _godot_object);
360 	}
361 	/**
362 	Returns the column for the currently edited item. This is only available for custom cell mode.
363 	*/
364 	long getEditedColumn() const
365 	{
366 		checkClassBinding!(typeof(this))();
367 		return ptrcall!(long)(_classBinding.getEditedColumn, _godot_object);
368 	}
369 	/**
370 	Returns the rectangle for custom popups. Helper to create custom cell controls that display a popup. See $(D TreeItem.setCellMode).
371 	*/
372 	Rect2 getCustomPopupRect() const
373 	{
374 		checkClassBinding!(typeof(this))();
375 		return ptrcall!(Rect2)(_classBinding.getCustomPopupRect, _godot_object);
376 	}
377 	/**
378 	Returns the rectangle area for the specified item. If column is specified, only get the position and size of that column, otherwise get the rectangle containing all columns.
379 	*/
380 	Rect2 getItemAreaRect(GodotObject item, in long column = -1) const
381 	{
382 		checkClassBinding!(typeof(this))();
383 		return ptrcall!(Rect2)(_classBinding.getItemAreaRect, _godot_object, item, column);
384 	}
385 	/**
386 	Returns the tree item at the specified position (relative to the tree origin position).
387 	*/
388 	TreeItem getItemAtPosition(in Vector2 position) const
389 	{
390 		checkClassBinding!(typeof(this))();
391 		return ptrcall!(TreeItem)(_classBinding.getItemAtPosition, _godot_object, position);
392 	}
393 	/**
394 	Returns the column index under the given point.
395 	*/
396 	long getColumnAtPosition(in Vector2 position) const
397 	{
398 		checkClassBinding!(typeof(this))();
399 		return ptrcall!(long)(_classBinding.getColumnAtPosition, _godot_object, position);
400 	}
401 	/**
402 	If $(D dropModeFlags) includes `DROP_MODE_INBETWEEN`, returns -1 if `position` is the upper part of a tree item at that position, 1 for the lower part, and additionally 0 for the middle part if $(D dropModeFlags) includes `DROP_MODE_ON_ITEM`.
403 	Otherwise, returns 0. If there are no tree item at `position`, returns -100.
404 	*/
405 	long getDropSectionAtPosition(in Vector2 position) const
406 	{
407 		checkClassBinding!(typeof(this))();
408 		return ptrcall!(long)(_classBinding.getDropSectionAtPosition, _godot_object, position);
409 	}
410 	/**
411 	Makes the currently selected item visible. This will scroll the tree to make sure the selected item is visible.
412 	*/
413 	void ensureCursorIsVisible()
414 	{
415 		checkClassBinding!(typeof(this))();
416 		ptrcall!(void)(_classBinding.ensureCursorIsVisible, _godot_object);
417 	}
418 	/**
419 	If `true` column titles are visible.
420 	*/
421 	void setColumnTitlesVisible(in bool visible)
422 	{
423 		checkClassBinding!(typeof(this))();
424 		ptrcall!(void)(_classBinding.setColumnTitlesVisible, _godot_object, visible);
425 	}
426 	/**
427 	Returns `true` if the column titles are being shown.
428 	*/
429 	bool areColumnTitlesVisible() const
430 	{
431 		checkClassBinding!(typeof(this))();
432 		return ptrcall!(bool)(_classBinding.areColumnTitlesVisible, _godot_object);
433 	}
434 	/**
435 	Set the title of a column.
436 	*/
437 	void setColumnTitle(StringArg1)(in long column, in StringArg1 title)
438 	{
439 		checkClassBinding!(typeof(this))();
440 		ptrcall!(void)(_classBinding.setColumnTitle, _godot_object, column, title);
441 	}
442 	/**
443 	Returns the column's title.
444 	*/
445 	String getColumnTitle(in long column) const
446 	{
447 		checkClassBinding!(typeof(this))();
448 		return ptrcall!(String)(_classBinding.getColumnTitle, _godot_object, column);
449 	}
450 	/**
451 	Returns the current scrolling position.
452 	*/
453 	Vector2 getScroll() const
454 	{
455 		checkClassBinding!(typeof(this))();
456 		return ptrcall!(Vector2)(_classBinding.getScroll, _godot_object);
457 	}
458 	/**
459 	
460 	*/
461 	void setHideFolding(in bool hide)
462 	{
463 		checkClassBinding!(typeof(this))();
464 		ptrcall!(void)(_classBinding.setHideFolding, _godot_object, hide);
465 	}
466 	/**
467 	
468 	*/
469 	bool isFoldingHidden() const
470 	{
471 		checkClassBinding!(typeof(this))();
472 		return ptrcall!(bool)(_classBinding.isFoldingHidden, _godot_object);
473 	}
474 	/**
475 	
476 	*/
477 	void setDropModeFlags(in long flags)
478 	{
479 		checkClassBinding!(typeof(this))();
480 		ptrcall!(void)(_classBinding.setDropModeFlags, _godot_object, flags);
481 	}
482 	/**
483 	
484 	*/
485 	long getDropModeFlags() const
486 	{
487 		checkClassBinding!(typeof(this))();
488 		return ptrcall!(long)(_classBinding.getDropModeFlags, _godot_object);
489 	}
490 	/**
491 	
492 	*/
493 	void setAllowRmbSelect(in bool allow)
494 	{
495 		checkClassBinding!(typeof(this))();
496 		ptrcall!(void)(_classBinding.setAllowRmbSelect, _godot_object, allow);
497 	}
498 	/**
499 	
500 	*/
501 	bool getAllowRmbSelect() const
502 	{
503 		checkClassBinding!(typeof(this))();
504 		return ptrcall!(bool)(_classBinding.getAllowRmbSelect, _godot_object);
505 	}
506 	/**
507 	
508 	*/
509 	void setAllowReselect(in bool allow)
510 	{
511 		checkClassBinding!(typeof(this))();
512 		ptrcall!(void)(_classBinding.setAllowReselect, _godot_object, allow);
513 	}
514 	/**
515 	
516 	*/
517 	bool getAllowReselect() const
518 	{
519 		checkClassBinding!(typeof(this))();
520 		return ptrcall!(bool)(_classBinding.getAllowReselect, _godot_object);
521 	}
522 	/**
523 	The amount of columns.
524 	*/
525 	@property long columns()
526 	{
527 		return getColumns();
528 	}
529 	/// ditto
530 	@property void columns(long v)
531 	{
532 		setColumns(v);
533 	}
534 	/**
535 	If `true` the currently selected cell may be selected again.
536 	*/
537 	@property bool allowReselect()
538 	{
539 		return getAllowReselect();
540 	}
541 	/// ditto
542 	@property void allowReselect(bool v)
543 	{
544 		setAllowReselect(v);
545 	}
546 	/**
547 	If `true` a right mouse button click can select items.
548 	*/
549 	@property bool allowRmbSelect()
550 	{
551 		return getAllowRmbSelect();
552 	}
553 	/// ditto
554 	@property void allowRmbSelect(bool v)
555 	{
556 		setAllowRmbSelect(v);
557 	}
558 	/**
559 	If `true` the folding arrow is hidden.
560 	*/
561 	@property bool hideFolding()
562 	{
563 		return isFoldingHidden();
564 	}
565 	/// ditto
566 	@property void hideFolding(bool v)
567 	{
568 		setHideFolding(v);
569 	}
570 	/**
571 	If `true` the tree's root is hidden.
572 	*/
573 	@property bool hideRoot()
574 	{
575 		return isRootHidden();
576 	}
577 	/// ditto
578 	@property void hideRoot(bool v)
579 	{
580 		setHideRoot(v);
581 	}
582 	/**
583 	The drop mode as an OR combination of flags. See `DROP_MODE_*` constants. Once dropping is done, reverts to `DROP_MODE_DISABLED`. Setting this during $(D Control.canDropData) is recommended.
584 	*/
585 	@property long dropModeFlags()
586 	{
587 		return getDropModeFlags();
588 	}
589 	/// ditto
590 	@property void dropModeFlags(long v)
591 	{
592 		setDropModeFlags(v);
593 	}
594 	/**
595 	Allow single or multiple selection. See the `SELECT_*` constants.
596 	*/
597 	@property Tree.SelectMode selectMode()
598 	{
599 		return getSelectMode();
600 	}
601 	/// ditto
602 	@property void selectMode(long v)
603 	{
604 		setSelectMode(v);
605 	}
606 }