1 module main;
2 
3 import dlangui.all;
4 import std.stdio;
5 import std.conv;
6 
7 
8 mixin APP_ENTRY_POINT;
9 
10 /// entry point for dlangui based application
11 extern (C) int UIAppMain(string[] args) {
12     // resource directory search paths
13     string[] resourceDirs = [
14         appendPath(exePath, "../../../res/"),   // for Visual D and DUB builds
15         appendPath(exePath, "../../../res/mdpi/"),   // for Visual D and DUB builds
16         appendPath(exePath, "../../../../res/"),// for Mono-D builds
17         appendPath(exePath, "../../../../res/mdpi/"),// for Mono-D builds
18         appendPath(exePath, "res/mdpi/") // when res dir is located at the same directory as executable
19     ];
20     // setup resource directories - will use only existing directories
21     drawableCache.setResourcePaths(resourceDirs);
22     // setup i18n - look for i18n directory inside one of passed directories
23     i18n.findTranslationsDir(resourceDirs);
24     // select translation file - for english language
25     i18n.load("en.ini"); //"ru.ini", "en.ini"
26 
27     // create window
28     Window window = Platform.instance.createWindow("My Window", null);
29 	
30 	static if (true) {
31         VerticalLayout contentLayout = new VerticalLayout();
32         MenuItem mainMenuItems = new MenuItem();
33         MenuItem fileItem = new MenuItem(new Action(1, "File"d));
34         fileItem.add(new Action(10, "Open..."d));
35         fileItem.add(new Action(11, "Save..."d));
36         MenuItem openRecentItem = new MenuItem(new Action(13, "Open recent..."d));
37         openRecentItem.add(new Action(100, "File 1"d));
38         openRecentItem.add(new Action(101, "File 2"d));
39         openRecentItem.add(new Action(102, "File 3"d));
40         openRecentItem.add(new Action(103, "File 4"d));
41         openRecentItem.add(new Action(104, "File 5"d));
42         fileItem.add(openRecentItem);
43         fileItem.add(new Action(12, "Exit"d));
44         MenuItem editItem = new MenuItem(new Action(2, "Edit"d));
45         editItem.add(new Action(20, "Copy"d));
46         editItem.add(new Action(21, "Paste"d));
47         editItem.add(new Action(22, "Cut"d));
48         MenuItem windowItem = new MenuItem(new Action(3, "Window"d));
49         windowItem.add(new Action(30, "Preferences"d));
50         MenuItem helpItem = new MenuItem(new Action(4, "Help"d));
51         helpItem.add(new Action(40, "View Help"d));
52         helpItem.add(new Action(41, "About"d));
53         mainMenuItems.add(fileItem);
54         mainMenuItems.add(editItem);
55         mainMenuItems.add(windowItem);
56         mainMenuItems.add(helpItem);
57         MainMenu mainMenu = new MainMenu(mainMenuItems);
58         contentLayout.addChild(mainMenu);
59 
60         TabWidget tabs = new TabWidget("TABS");
61         tabs.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
62 
63 		LinearLayout layout = new LinearLayout("tab1");
64 
65 		layout.addChild((new TextWidget()).textColor(0x00802000).text("Text widget 0"));
66 		layout.addChild((new TextWidget()).textColor(0x40FF4000).text("Text widget"));
67 		layout.addChild((new Button("BTN1")).textResource("EXIT")); //.textColor(0x40FF4000)
68 		
69 		static if (true) {
70 		
71 
72 	    LinearLayout hlayout = new HorizontalLayout();
73 		//hlayout.addChild((new Button()).text("<<")); //.textColor(0x40FF4000)
74 	    hlayout.addChild((new TextWidget()).text("Several").alignment(Align.Center));
75 		hlayout.addChild((new ImageWidget()).drawableId("btn_radio").padding(Rect(5,5,5,5)).alignment(Align.Center));
76 	    hlayout.addChild((new TextWidget()).text("items").alignment(Align.Center));
77 		hlayout.addChild((new ImageWidget()).drawableId("btn_check").padding(Rect(5,5,5,5)).alignment(Align.Center));
78 	    hlayout.addChild((new TextWidget()).text("in horizontal layout"));
79 		hlayout.addChild((new ImageWidget()).drawableId("exit").padding(Rect(5,5,5,5)).alignment(Align.Center));
80 		//hlayout.addChild((new Button()).text(">>")); //.textColor(0x40FF4000)
81 	    hlayout.backgroundColor = 0x8080C0;
82 	    layout.addChild(hlayout);
83 
84 	    LinearLayout vlayoutgroup = new HorizontalLayout();
85 	    LinearLayout vlayout = new VerticalLayout();
86 		vlayout.addChild((new TextWidget()).text("VLayout line 1").textColor(0x40FF4000)); //
87 	    vlayout.addChild((new TextWidget()).text("VLayout line 2").textColor(0x40FF8000));
88 	    vlayout.addChild((new TextWidget()).text("VLayout line 2").textColor(0x40008000));
89 	    vlayout.addChild(new RadioButton("rb1", "Radio button 1"d));
90 	    vlayout.addChild(new RadioButton("rb2", "Radio button 2"d));
91 	    vlayout.addChild(new RadioButton("rb3", "Radio button 3"d));
92         vlayout.layoutWidth(FILL_PARENT);
93 	    vlayoutgroup.addChild(vlayout);
94         vlayoutgroup.layoutWidth(FILL_PARENT);
95         ScrollBar vsb = new ScrollBar("vscroll", Orientation.Vertical);
96 	    vlayoutgroup.addChild(vsb);
97 	    layout.addChild(vlayoutgroup);
98 
99         ScrollBar sb = new ScrollBar("hscroll", Orientation.Horizontal);
100         layout.addChild(sb.layoutHeight(WRAP_CONTENT).layoutWidth(FILL_PARENT));
101 
102 		layout.addChild((new CheckBox("BTN2", "Some checkbox"d)));
103 		layout.addChild((new TextWidget()).textColor(0x40FF4000).text("Text widget"));
104 		layout.addChild((new ImageWidget()).drawableId("exit").padding(Rect(5,5,5,5)));
105 		layout.addChild((new TextWidget()).textColor(0xFF4000).text("Text widget2").padding(Rect(5,5,5,5)).margins(Rect(5,5,5,5)).backgroundColor(0xA0A0A0));
106 		layout.addChild((new RadioButton("BTN3", "Some radio button"d)));
107 		layout.addChild((new TextWidget(null, "Text widget3 with very long text"d)).textColor(0x004000));
108         layout.addChild(new VSpacer()); // vertical spacer to fill extra space
109 
110 		layout.childById("BTN1").onClickListener = (delegate (Widget w) { Log.d("onClick ", w.id); return true; });
111 		layout.childById("BTN2").onClickListener = (delegate (Widget w) { Log.d("onClick ", w.id); return true; });
112 		layout.childById("BTN3").onClickListener = (delegate (Widget w) { Log.d("onClick ", w.id); return true; });
113 
114         }
115 
116 		layout.layoutHeight(FILL_PARENT).layoutWidth(FILL_PARENT);
117 
118         tabs.addTab(layout, "Tab 1"d);
119 
120         static if (true) {
121             ListWidget list = new ListWidget("tab2", Orientation.Vertical);
122             WidgetListAdapter listAdapter = new WidgetListAdapter();
123             for (int i = 0; i < 1000; i++)
124                 listAdapter.widgets.add((new TextWidget()).text("List item "d ~ to!dstring(i)).styleId("LIST_ITEM"));
125             list.ownAdapter = listAdapter;
126             listAdapter.resetItemState(0, State.Enabled);
127             listAdapter.resetItemState(5, State.Enabled);
128             listAdapter.resetItemState(7, State.Enabled);
129             listAdapter.resetItemState(12, State.Enabled);
130             assert(list.itemEnabled(5) == false);
131             assert(list.itemEnabled(6) == true);
132             list.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
133             list.selectItem(0);
134             tabs.addTab(list, "Long List"d);
135         }
136 
137         tabs.addTab((new TextWidget()).id("tab3").textColor(0x00802000).text("Tab 3 contents"), "Tab 3"d);
138         tabs.addTab((new TextWidget()).id("tab4").textColor(0x00802000).text("Tab 4 contents some long string"), "Tab 4"d);
139         tabs.addTab((new TextWidget()).id("tab5").textColor(0x00802000).text("Tab 5 contents"), "Tab 5"d);
140 
141         tabs.selectTab("tab1");
142 
143         contentLayout.addChild(tabs);
144 	    window.mainWidget = contentLayout;
145 	} else {
146 	    window.mainWidget = (new Button()).text("sample button");
147 	}
148     window.show();
149     //window.windowCaption = "New Window Caption";
150     // run message loop
151     return Platform.instance.enterMessageLoop();
152 }