1 module widgets.tree;
2 
3 import dlangui;
4 
5 class TreeExample : HorizontalLayout
6 {
7     this(string ID)
8     {
9         super(ID);
10 
11         TreeWidget tree = new TreeWidget("TREE1");
12         tree.layoutWidth(WRAP_CONTENT).layoutHeight(FILL_PARENT);
13         TreeItem tree1 = tree.items.newChild("group1", "Group 1"d, "document-open");
14         tree1.newChild("g1_1", "Group 1 item 1"d);
15         tree1.newChild("g1_2", "Group 1 item 2"d);
16         tree1.newChild("g1_3", "Group 1 item 3"d);
17         TreeItem tree2 = tree.items.newChild("group2", "Group 2"d, "document-save");
18         tree2.newChild("g2_1", "Group 2 item 1"d, "edit-copy");
19         tree2.newChild("g2_2", "Group 2 item 2"d, "edit-cut");
20         tree2.newChild("g2_3", "Group 2 item 3"d, "edit-paste");
21         tree2.newChild("g2_4", "Group 2 item 4"d);
22         TreeItem tree3 = tree.items.newChild("group3", "Group 3"d);
23         tree3.newChild("g3_1", "Group 3 item 1"d);
24         tree3.newChild("g3_2", "Group 3 item 2"d);
25         TreeItem tree32 = tree3.newChild("g3_3", "Group 3 item 3"d);
26         tree3.newChild("g3_4", "Group 3 item 4"d);
27         tree32.newChild("group3_2_1", "Group 3 item 2 subitem 1"d);
28         tree32.newChild("group3_2_2", "Group 3 item 2 subitem 2"d);
29         tree32.newChild("group3_2_3", "Group 3 item 2 subitem 3"d);
30         tree32.newChild("group3_2_4", "Group 3 item 2 subitem 4"d);
31         tree32.newChild("group3_2_5", "Group 3 item 2 subitem 5"d);
32         tree3.newChild("g3_5", "Group 3 item 5"d);
33         tree3.newChild("g3_6", "Group 3 item 6"d);
34 
35         LinearLayout treeControlledPanel = new VerticalLayout();
36         layoutWidth = FILL_PARENT;
37         treeControlledPanel.layoutWidth = FILL_PARENT;
38         treeControlledPanel.layoutHeight = FILL_PARENT;
39         TextWidget treeItemLabel = new TextWidget("TREE_ITEM_DESC");
40         treeItemLabel.layoutWidth = FILL_PARENT;
41         treeItemLabel.layoutHeight = FILL_PARENT;
42         treeItemLabel.alignment = Align.Center;
43         treeItemLabel.text = "Sample text"d;
44         treeControlledPanel.addChild(treeItemLabel);
45         addChild(tree);
46         addChild(new ResizerWidget());
47         addChild(treeControlledPanel);
48 
49         tree.selectionChange = delegate(TreeItems source, TreeItem selectedItem, bool activated) {
50             dstring label = "Selected item: "d ~ toUTF32(selectedItem.id) ~ (activated ? " selected + activated"d : " selected"d);
51             treeItemLabel.text = label;
52         };
53 
54         tree.items.selectItem(tree.items.child(0));
55     }
56 }