1 module widgets.buttons;
2 
3 import dlangui;
4 
5 enum : int {
6     ACTION_FILE_OPEN = 5500,
7     ACTION_FILE_SAVE,
8     ACTION_FILE_CLOSE,
9     ACTION_FILE_EXIT,
10 }
11 
12 class ButtonsExample : VerticalLayout
13 {
14     this(string ID)
15     {
16         super(ID);
17         // 3 types of buttons: Button, ImageButton, ImageTextButton
18         addChild(new TextWidget(null, "Buttons in HorizontalLayout"d));
19         WidgetGroup buttons1 = new HorizontalLayout();
20         buttons1.addChild(new TextWidget(null, "Button widgets: "d));
21         buttons1.addChild((new Button("btn1", "Button"d)).tooltipText("Tooltip text for button"d));
22         buttons1.addChild((new Button("btn2", "Disabled Button"d)).enabled(false));
23         buttons1.addChild(new TextWidget(null, "ImageButton widgets: "d));
24         buttons1.addChild(new ImageButton("btn3", "text-plain"));
25         buttons1.addChild(new TextWidget(null, "disabled: "d));
26         buttons1.addChild((new ImageButton("btn4", "folder")).enabled(false));
27         addChild(buttons1);
28 
29         WidgetGroup buttons10 = new HorizontalLayout();
30         buttons10.addChild(new TextWidget(null, "ImageTextButton widgets: "d));
31         buttons10.addChild(new ImageTextButton("btn5", "text-plain", "Enabled"d));
32         buttons10.addChild((new ImageTextButton("btn6", "folder", "Disabled"d)).enabled(false));
33         buttons10.addChild(new TextWidget(null, "SwitchButton widgets: "d));
34         buttons10.addChild((new SwitchButton("SW1")).checked(true));
35         buttons10.addChild((new SwitchButton("SW2")).checked(false));
36         buttons10.addChild((new SwitchButton("SW3")).checked(true).enabled(false));
37         buttons10.addChild((new SwitchButton("SW4")).checked(false).enabled(false));
38         addChild(buttons10);
39 
40         WidgetGroup buttons11 = new HorizontalLayout();
41         buttons11.addChild(new TextWidget(null, "Construct buttons by action (Button, ImageButton, ImageTextButton): "d));
42         Action FILE_OPEN_ACTION = new Action(ACTION_FILE_OPEN, "MENU_FILE_OPEN"c, "document-open", KeyCode.KEY_O, KeyFlag.Control);
43         buttons11.addChild(new Button(FILE_OPEN_ACTION));
44         buttons11.addChild(new ImageButton(FILE_OPEN_ACTION));
45         buttons11.addChild(new ImageTextButton(FILE_OPEN_ACTION));
46         addChild(buttons11);
47 
48         WidgetGroup buttons12 = new HorizontalLayout();
49         buttons12.addChild(new TextWidget(null, "The same in disabled state: "d));
50         buttons12.addChild((new Button(FILE_OPEN_ACTION)).enabled(false));
51         buttons12.addChild((new ImageButton(FILE_OPEN_ACTION)).enabled(false));
52         buttons12.addChild((new ImageTextButton(FILE_OPEN_ACTION)).enabled(false));
53         addChild(buttons12);
54 
55         addChild(new VSpacer());
56         addChild(new TextWidget(null, "CheckBoxes in HorizontalLayout"d));
57         WidgetGroup buttons2 = new HorizontalLayout();
58         buttons2.addChild(new CheckBox("btn1", "CheckBox 1"d));
59         buttons2.addChild(new CheckBox("btn2", "CheckBox 2"d));
60         //buttons2.addChild(new ResizerWidget());
61         buttons2.addChild(new CheckBox("btn3", "CheckBox 3"d));
62         buttons2.addChild(new CheckBox("btn4", "CheckBox 4"d));
63         addChild(buttons2);
64 
65         addChild(new VSpacer());
66         addChild(new TextWidget(null, "RadioButtons in HorizontalLayout"d));
67         WidgetGroup buttons3 = new HorizontalLayout();
68         buttons3.addChild(new RadioButton("btn1", "RadioButton 1"d));
69         buttons3.addChild(new RadioButton("btn2", "RadioButton 2"d));
70         buttons3.addChild(new RadioButton("btn3", "RadioButton 3"d));
71         buttons3.addChild(new RadioButton("btn4", "RadioButton 4"d));
72         addChild(buttons3);
73 
74         addChild(new VSpacer());
75         addChild(new TextWidget(null, "ImageButtons HorizontalLayout"d));
76         WidgetGroup buttons4 = new HorizontalLayout();
77         buttons4.addChild(new ImageButton("btn1", "fileclose"));
78         buttons4.addChild(new ImageButton("btn2", "fileopen"));
79         buttons4.addChild(new ImageButton("btn3", "exit"));
80         addChild(buttons4);
81 
82         addChild(new VSpacer());
83         addChild(new TextWidget(null, "In vertical layouts:"d));
84         HorizontalLayout hlayout2 = new HorizontalLayout();
85         hlayout2.layoutHeight(FILL_PARENT); //layoutWidth(FILL_PARENT).
86 
87         buttons1 = new VerticalLayout();
88         buttons1.addChild(new TextWidget(null, "Buttons"d));
89         buttons1.addChild(new Button("btn1", "Button 1"d));
90         buttons1.addChild(new Button("btn2", "Button 2"d));
91         buttons1.addChild((new Button("btn3", "Button 3 - disabled"d)).enabled(false));
92         buttons1.addChild(new Button("btn4", "Button 4"d));
93         hlayout2.addChild(buttons1);
94         hlayout2.addChild(new HSpacer());
95 
96         buttons2 = new VerticalLayout();
97         buttons2.addChild(new TextWidget(null, "CheckBoxes"d));
98         buttons2.addChild(new CheckBox("btn1", "CheckBox 1"d));
99         buttons2.addChild(new CheckBox("btn2", "CheckBox 2"d));
100         buttons2.addChild(new CheckBox("btn3", "CheckBox 3"d));
101         buttons2.addChild(new CheckBox("btn4", "CheckBox 4"d));
102         hlayout2.addChild(buttons2);
103         hlayout2.addChild(new HSpacer());
104 
105         buttons3 = new VerticalLayout();
106         buttons3.addChild(new TextWidget(null, "RadioButtons"d));
107         buttons3.addChild(new RadioButton("btn1", "RadioButton 1"d));
108         buttons3.addChild(new RadioButton("btn2", "RadioButton 2"d));
109         //buttons3.addChild(new ResizerWidget());
110         buttons3.addChild(new RadioButton("btn3", "RadioButton 3"d));
111         buttons3.addChild(new RadioButton("btn4", "RadioButton 4"d));
112         hlayout2.addChild(buttons3);
113         hlayout2.addChild(new HSpacer());
114 
115         buttons4 = new VerticalLayout();
116         buttons4.addChild(new TextWidget(null, "ImageButtons"d));
117         buttons4.addChild(new ImageButton("btn1", "fileclose"));
118         buttons4.addChild(new ImageButton("btn2", "fileopen"));
119         buttons4.addChild(new ImageButton("btn3", "exit"));
120         hlayout2.addChild(buttons4);
121         hlayout2.addChild(new HSpacer());
122 
123         WidgetGroup buttons5 = new VerticalLayout();
124         buttons5.addChild(new TextWidget(null, "ImageTextButtons"d));
125         buttons5.addChild(new ImageTextButton("btn1", "fileclose", "Close"d));
126         buttons5.addChild(new ImageTextButton("btn2", "fileopen", "Open"d));
127         buttons5.addChild(new ImageTextButton("btn3", "exit", "Exit"d));
128         hlayout2.addChild(buttons5);
129 
130 
131         addChild(hlayout2);
132 
133         addChild(new VSpacer());
134         layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
135     }
136 }