1 module widgets.controls; 2 3 import dlangui; 4 5 class BasicControls : LinearLayout 6 { 7 this(string ID) 8 { 9 super(ID); 10 layoutHeight(FILL_PARENT); 11 padding = Rect(12.pointsToPixels,12.pointsToPixels,12.pointsToPixels,12.pointsToPixels); 12 13 HorizontalLayout line1 = new HorizontalLayout(); 14 addChild(line1); 15 16 GroupBox gb = new GroupBox("checkboxes", "CheckBox"d); 17 gb.addChild(new CheckBox("cb1", "CheckBox 1"d)); 18 gb.addChild(new CheckBox("cb2", "CheckBox 2"d).checked(true)); 19 gb.addChild(new CheckBox("cb3", "CheckBox disabled"d).enabled(false)); 20 gb.addChild(new CheckBox("cb4", "CheckBox disabled"d).checked(true).enabled(false)); 21 line1.addChild(gb); 22 23 GroupBox gb2 = new GroupBox("radiobuttons", "RadioButton"d); 24 gb2.addChild(new RadioButton("rb1", "RadioButton 1"d).checked(true)); 25 gb2.addChild(new RadioButton("rb2", "RadioButton 2"d)); 26 gb2.addChild(new RadioButton("rb3", "RadioButton disabled"d).enabled(false)); 27 line1.addChild(gb2); 28 29 VerticalLayout col1 = new VerticalLayout(); 30 GroupBox gb3 = new GroupBox("textbuttons", "Button"d, Orientation.Horizontal); 31 gb3.addChild(new Button("tb1", "Button"d)); 32 gb3.addChild(new Button("tb2", "Button disabled"d).enabled(false)); 33 col1.addChild(gb3); 34 GroupBox gb4 = new GroupBox("imagetextbuttons", "ImageTextButton"d, Orientation.Horizontal); 35 gb4.addChild(new ImageTextButton("itb1", "document-open", "Enabled"d)); 36 gb4.addChild(new ImageTextButton("itb2", "document-save", "Disabled"d).enabled(false)); 37 col1.addChild(gb4); 38 GroupBox gbtext = new GroupBox("text", "TextWidget"d, Orientation.Horizontal); 39 gbtext.addChild(new TextWidget("t1", "Red text"d).fontSize(12.pointsToPixels).textColor(0xFF0000)); 40 gbtext.addChild(new TextWidget("t2", "Italic text"d).fontSize(12.pointsToPixels).fontItalic(true)); 41 col1.addChild(gbtext); 42 line1.addChild(col1); 43 44 VerticalLayout col2 = new VerticalLayout(); 45 GroupBox gb31 = new GroupBox("switches", "SwitchButton"d, Orientation.Vertical); 46 gb31.addChild(new SwitchButton("sb1")); 47 gb31.addChild(new SwitchButton("sb2").checked(true)); 48 gb31.addChild(new SwitchButton("sb3").enabled(false)); 49 gb31.addChild(new SwitchButton("sb4").enabled(false).checked(true)); 50 col2.addChild(gb31); 51 line1.addChild(col2); 52 53 VerticalLayout col3 = new VerticalLayout(); 54 GroupBox gb32 = new GroupBox("switches", "ImageButton"d, Orientation.Vertical); 55 gb32.addChild(new ImageButton("ib1", "edit-copy")); 56 gb32.addChild(new ImageButton("ib3", "edit-paste").enabled(false)); 57 col3.addChild(gb32); 58 GroupBox gb33 = new GroupBox("images", "ImageWidget"d, Orientation.Vertical); 59 gb33.addChild(new ImageWidget("cr3_logo", "cr3_logo")); 60 col3.addChild(gb33); 61 line1.addChild(col3); 62 63 64 HorizontalLayout line2 = new HorizontalLayout(); 65 addChild(line2); 66 67 GroupBox gb5 = new GroupBox("scrollbar", "horizontal ScrollBar"d); 68 gb5.addChild(new ScrollBar("sb1", Orientation.Horizontal)); 69 line2.addChild(gb5); 70 GroupBox gb6 = new GroupBox("slider", "horizontal SliderWidget"d); 71 gb6.addChild(new SliderWidget("sb2", Orientation.Horizontal)); 72 line2.addChild(gb6); 73 GroupBox gb7 = new GroupBox("editline1", "EditLine"d); 74 gb7.addChild(new EditLine("ed1", "Some text"d).minWidth(120.pointsToPixels)); 75 line2.addChild(gb7); 76 GroupBox gb8 = new GroupBox("editline2", "EditLine disabled"d); 77 gb8.addChild(new EditLine("ed2", "Some text"d).enabled(false).minWidth(120.pointsToPixels)); 78 line2.addChild(gb8); 79 80 HorizontalLayout line3 = new HorizontalLayout(); 81 line3.layoutWidth(FILL_PARENT); 82 GroupBox gbeditbox = new GroupBox("editbox", "EditBox"d, Orientation.Horizontal); 83 gbeditbox.layoutWidth(FILL_PARENT); 84 EditBox ed1 = new EditBox("ed1", "Some text in EditBox\nOne more line\nYet another text line"); 85 ed1.layoutHeight(FILL_PARENT); 86 gbeditbox.addChild(ed1); 87 line3.addChild(gbeditbox); 88 GroupBox gbtabs = new GroupBox(null, "TabWidget"d); 89 gbtabs.layoutWidth(FILL_PARENT); 90 TabWidget tabs1 = new TabWidget("tabs1"); 91 tabs1.addTab(new TextWidget("tab1", "TextWidget on tab page\nTextWidgets can be\nMultiline"d).maxLines(3), "Tab 1"d); 92 tabs1.addTab(new ImageWidget("tab2", "dlangui-logo1"), "Tab 2"d); 93 tabs1.tabHost.backgroundColor = 0xE0E0E0; 94 tabs1.tabHost.padding = Rect(10.pointsToPixels, 10.pointsToPixels, 10.pointsToPixels, 10.pointsToPixels); 95 gbtabs.addChild(tabs1); 96 line3.addChild(gbtabs); 97 addChild(line3); 98 99 HorizontalLayout line4 = new HorizontalLayout(); 100 line4.layoutWidth(FILL_PARENT); 101 line4.layoutHeight(FILL_PARENT); 102 GroupBox gbgrid = new GroupBox("grid", "StringGridWidget"d, Orientation.Horizontal); 103 StringGridWidget grid = new StringGridWidget("stringgrid"); 104 grid.resize(12, 10); 105 gbgrid.layoutWidth(FILL_PARENT); 106 gbgrid.layoutHeight(FILL_PARENT); 107 grid.layoutWidth(FILL_PARENT); 108 grid.layoutHeight(FILL_PARENT); 109 foreach (index, month; ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]) 110 grid.setColTitle(cast(int)index, UIString.fromRaw(month)); 111 for (int y = 0; y < 10; y++) 112 grid.setRowTitle(y, UIString.fromRaw(to!string(y+1))); 113 114 grid.setColWidth(0, 30.pointsToPixels); 115 grid.autoFit(); 116 import std.random; 117 import std.string; 118 for (int x = 0; x < 12; x++) { 119 for (int y = 0; y < 10; y++) { 120 int n = uniform(0, 10000); 121 grid.setCellText(x, y, UIString.fromRaw(to!string("%.2f".format(n / 100.0)))); 122 } 123 } 124 125 gbgrid.addChild(grid); 126 line4.addChild(gbgrid); 127 128 GroupBox gbtree = new GroupBox("tree", "TreeWidget"d, Orientation.Vertical); 129 auto tree = new TreeWidget("gbtree"); 130 tree.maxHeight(200.pointsToPixels); 131 TreeItem tree1 = tree.items.newChild("group1", "Group 1"d, "document-open"); 132 tree1.newChild("g1_1", "Group 1 item 1"d); 133 tree1.newChild("g1_2", "Group 1 item 2"d); 134 tree1.newChild("g1_3", "Group 1 item 3"d); 135 TreeItem tree2 = tree.items.newChild("group2", "Group 2"d, "document-save"); 136 tree2.newChild("g2_1", "Group 2 item 1"d, "edit-copy"); 137 tree2.newChild("g2_2", "Group 2 item 2"d, "edit-cut"); 138 tree2.newChild("g2_3", "Group 2 item 3"d, "edit-paste"); 139 tree2.newChild("g2_4", "Group 2 item 4"d); 140 TreeItem tree3 = tree.items.newChild("group3", "Group 3"d); 141 tree3.newChild("g3_1", "Group 3 item 1"d); 142 tree3.newChild("g3_2", "Group 3 item 2"d); 143 TreeItem tree32 = tree3.newChild("g3_3", "Group 3 item 3"d); 144 tree3.newChild("g3_4", "Group 3 item 4"d); 145 tree32.newChild("group3_2_1", "Group 3 item 2 subitem 1"d); 146 tree32.newChild("group3_2_2", "Group 3 item 2 subitem 2"d); 147 tree32.newChild("group3_2_3", "Group 3 item 2 subitem 3"d); 148 tree32.newChild("group3_2_4", "Group 3 item 2 subitem 4"d); 149 tree32.newChild("group3_2_5", "Group 3 item 2 subitem 5"d); 150 tree3.newChild("g3_5", "Group 3 item 5"d); 151 tree3.newChild("g3_6", "Group 3 item 6"d); 152 gbtree.addChild(tree); 153 tree.items.selectItem(tree1); 154 // test adding new tree items 155 HorizontalLayout newTreeItem = new HorizontalLayout(); 156 newTreeItem.layoutWidth = FILL_PARENT; 157 EditLine edNewTreeItem = new EditLine("newTreeItem", "new item"d); 158 edNewTreeItem.layoutWidth = FILL_PARENT; 159 Button btnAddItem = new Button("btnAddTreeItem", "Add"d); 160 Button btnRemoveItem = new Button("btnRemoveTreeItem", "Remove"d); 161 newTreeItem.addChild(edNewTreeItem); 162 newTreeItem.addChild(btnAddItem); 163 newTreeItem.addChild(btnRemoveItem); 164 btnAddItem.click = delegate(Widget source) { 165 import std.random; 166 dstring label = edNewTreeItem.text; 167 string id = "item%d".format(uniform(1000000, 9999999, rndGen)); 168 TreeItem item = tree.items.selectedItem; 169 if (item) { 170 Log.d("Creating new tree item ", id, " ", label); 171 TreeItem newItem = new TreeItem(id, label); 172 item.addChild(newItem); 173 } 174 return true; 175 }; 176 btnRemoveItem.click = delegate(Widget source) { 177 TreeItem item = tree.items.selectedItem; 178 if (item) { 179 Log.d("Removing tree item ", item.id, " ", item.text); 180 item.parent.removeChild(item); 181 } 182 return true; 183 }; 184 gbtree.addChild(newTreeItem); 185 line4.addChild(gbtree); 186 187 addChild(line4); 188 } 189 }