summaryrefslogtreecommitdiff
path: root/src/examples/elementary/efl_ui_unit_converter.cs
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2017-12-13 01:51:48 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2017-12-19 17:51:51 -0200
commit8f14f1610eb28ae961d453b8efdb91035c8d4777 (patch)
treedfae0d29a2571e19a80fc54f4155872d352b7c3e /src/examples/elementary/efl_ui_unit_converter.cs
parent98aa1a4eb129278fb1fb23f8db4145a40e5b3abf (diff)
examples: Add C# buttons/popup example.
Diffstat (limited to 'src/examples/elementary/efl_ui_unit_converter.cs')
-rw-r--r--src/examples/elementary/efl_ui_unit_converter.cs152
1 files changed, 152 insertions, 0 deletions
diff --git a/src/examples/elementary/efl_ui_unit_converter.cs b/src/examples/elementary/efl_ui_unit_converter.cs
new file mode 100644
index 0000000000..f167e68ca2
--- /dev/null
+++ b/src/examples/elementary/efl_ui_unit_converter.cs
@@ -0,0 +1,152 @@
1using System;
2
3public class Example
4{
5
6 private static double KMS_PER_MILE = 1.609344;
7
8 private static double KmsToMiles(double kms)
9 {
10 return kms / KMS_PER_MILE;
11 }
12 private static double MilesToKms(double miles)
13 {
14 return miles * KMS_PER_MILE;
15 }
16
17 private static void ShowErrorPopup(efl.ui.Win win, string message)
18 {
19 efl.ui.Popup_Alert popup = new efl.ui.Popup_AlertConcrete(win);
20 efl.ui.Text popup_text = new efl.ui.TextConcrete(popup);
21 popup_text.SetText($"Error: {message}");
22 popup.SetContent(popup_text);
23 popup.SetVisible(true);
24 popup.SetButton(efl.ui.popup_alert.Button.Positive, "Ok");
25 popup.SetSize(150, 30);
26 popup.CLICKED += (object sender, efl.ui.CLICKED_Args e) => {
27 popup.SetParent(null);
28 popup.Del();
29 };
30 }
31
32#if WIN32 // Passed to the C# compiler with -define:WIN32
33 // Mono on Windows by default uses multi-thread apartments for COM stuff while
34 // OLE - used by ecore win32 DnD requires single threading for COM.
35 [STAThreadAttribute()]
36#endif
37 public static void Main() {
38 efl.All.Init(efl.Components.Ui);
39
40 efl.ui.Win win = new efl.ui.WinConcrete(null);
41 win.SetText("C# Unit Converter");
42 win.SetAutohide(true);
43
44 efl.ui.Box_Flow box = new efl.ui.Box_FlowConcrete(win);
45 box.SetDirection(efl.ui.Dir.Horizontal);
46
47 efl.ui.Box_Flow miles_box = new efl.ui.Box_FlowConcrete(box);
48 miles_box.SetDirection(efl.ui.Dir.Down);
49
50 box.Pack(miles_box);
51
52 efl.ui.Text miles_label = new efl.ui.TextConcrete(miles_box);
53 miles_label.SetText("Miles:");
54 miles_label.SetSize(120, 30);
55 miles_label.SetVisible(true);
56
57 efl.ui.text.Editable miles_input = new efl.ui.text.EditableConcrete(miles_box);
58 miles_input.SetText("");
59 miles_input.SetScrollable(true);
60 miles_input.SetSize(120, 30);
61 miles_input.SetVisible(true);
62
63 efl.ui.Button miles_button = new efl.ui.ButtonConcrete(miles_box);
64 miles_button.SetText("To Km");
65 miles_button.SetSize(120, 30);
66 miles_button.SetVisible(true);
67
68 miles_box.Pack(miles_label);
69 miles_box.Pack(miles_input);
70 miles_box.Pack(miles_button);
71
72
73 efl.ui.Box_Flow kms_box = new efl.ui.Box_FlowConcrete(box);
74 kms_box.SetDirection(efl.ui.Dir.Down);
75
76 box.Pack(kms_box);
77
78 efl.ui.Text kms_label = new efl.ui.TextConcrete(kms_box);
79 kms_label.SetText("Kilometers:");
80 kms_label.SetSize(120, 30);
81 kms_label.SetVisible(true);
82
83 efl.ui.text.Editable kms_input = new efl.ui.text.EditableConcrete(kms_box);
84 kms_input.SetText("");
85 kms_input.SetScrollable(true);
86 kms_input.SetSize(120, 30);
87 kms_input.SetVisible(true);
88
89 efl.ui.Button kms_button = new efl.ui.ButtonConcrete(kms_box);
90 kms_button.SetText("To Miles");
91 kms_button.SetSize(120, 30);
92 kms_button.SetVisible(true);
93
94 kms_box.Pack(kms_label);
95 kms_box.Pack(kms_input);
96 kms_box.Pack(kms_button);
97
98 kms_button.CLICKED += (object sender, EventArgs e) => {
99 try
100 {
101 string text = kms_input.GetText();
102 Console.WriteLine("Text is [{0}]", text);
103 double val = double.Parse(text);
104 miles_input.SetText(String.Format("{0:f3}", KmsToMiles(val)));
105 kms_input.SetFocus(true);
106 }
107 catch (FormatException ex)
108 {
109 Console.WriteLine("Exception {0} caught", ex);
110 ShowErrorPopup(win, "Invalid number");
111 }
112 };
113
114 miles_button.CLICKED += (object sender, EventArgs e) => {
115 try
116 {
117 string text = miles_input.GetText();
118 Console.WriteLine("Text is [{0}]", text);
119 double val = double.Parse(text);
120 kms_input.SetText(String.Format("{0:f3}", MilesToKms(val)));
121 miles_input.SetFocus(true);
122 }
123 catch (FormatException ex)
124 {
125 Console.WriteLine("Exception {0} cautght", ex);
126 ShowErrorPopup(win, "Invalid number");
127 }
128 };
129
130 kms_box.SetVisible(true);
131 miles_box.SetVisible(true);
132
133 eina.Position2D pos;
134
135 pos.X = 20;
136 pos.Y = 30;
137 box.SetPosition(pos);
138 box.SetVisible(true);
139
140 pos.X = 200;
141 pos.Y = 200;
142 win.SetPosition(pos);
143
144 win.SetSize(400,120);
145 win.SetVisible(true);
146
147 efl.ui.Config.Run();
148
149 efl.All.Shutdown();
150 }
151
152}