summaryrefslogtreecommitdiff
path: root/reference
diff options
context:
space:
mode:
authorXavi Artigas <xavierartigas@yahoo.es>2019-01-18 16:53:55 +0100
committerXavi Artigas <xavierartigas@yahoo.es>2019-01-23 14:49:38 +0100
commit500049f1eb376dbd0b07a3688546c4f11a567d6b (patch)
treeac687fb0badf8c5c3aefe45e816bf1735e44a0af /reference
parente674ff0d9754586e7f0c2413327c3383ab3ad7ae (diff)
mono-examples: Adapt to latest syntax
Summary: Removed initializer methods as much as possible to prepare for when they are removed from the C# bindings. No functional changes in the examples. Tutorial text needs to be adapted now. Test Plan: All examples work as before (the containers one is currently broken, FML). Reviewers: lauromoura, felipealmeida, vitor.sousa Reviewed By: lauromoura Maniphest Tasks: T7508 Differential Revision: https://phab.enlightenment.org/D7695
Diffstat (limited to 'reference')
-rw-r--r--reference/csharp/core/src/core_event.cs48
-rw-r--r--reference/csharp/core/src/core_idler.cs10
-rw-r--r--reference/csharp/core/src/core_poll.cs10
-rw-r--r--reference/csharp/ui/src/focus_main.cs69
-rw-r--r--reference/csharp/ui/src/ui_container.cs90
-rw-r--r--reference/csharp/ui/src/ui_sizing.cs47
6 files changed, 128 insertions, 146 deletions
diff --git a/reference/csharp/core/src/core_event.cs b/reference/csharp/core/src/core_event.cs
index 20f38b7b..2cb6d8e0 100644
--- a/reference/csharp/core/src/core_event.cs
+++ b/reference/csharp/core/src/core_event.cs
@@ -31,33 +31,33 @@ public class Example
31 mainloop.PollHighEvt += PollCb; 31 mainloop.PollHighEvt += PollCb;
32 32
33 // This timer will control events fired by the main loop 33 // This timer will control events fired by the main loop
34 new Efl.LoopTimer(mainloop, (Efl.LoopTimer etimer) => { 34 var timer = new Efl.LoopTimer(mainloop, (Efl.LoopTimer etimer) => {
35 etimer.SetName("Timer");
36 // Trigger every 100ms 35 // Trigger every 100ms
37 etimer.SetInterval(0.1); 36 etimer.SetInterval(0.1);
38 // To count number of timer triggers
39 int tick_count = 0;
40 etimer.TickEvt += (object sender, EventArgs e) => {
41 string message = "Tick {0} from {1}: ";
42 // Depending on the number of timer ticks, it does a different thing
43 switch (tick_count) {
44 case 0:
45 message += "Freezing Mainloop events";
46 mainloop.FreezeEvent();
47 break;
48 case 1:
49 message += "Thawing Mainloop events";
50 mainloop.ThawEvent();
51 break;
52 default:
53 message += "Quitting";
54 mainloop.Quit(new Eina.Value(0));
55 break;
56 }
57 Console.WriteLine(message, tick_count, ((Efl.Object)sender).GetName());
58 tick_count++;
59 };
60 }); 37 });
38 timer.SetName("Timer");
39 // To count number of timer triggers
40 int tick_count = 0;
41 timer.TickEvt += (object sender, EventArgs e) => {
42 string message = "Tick {0} from {1}: ";
43 // Depending on the number of timer ticks, it does a different thing
44 switch (tick_count) {
45 case 0:
46 message += "Freezing Mainloop events";
47 mainloop.FreezeEvent();
48 break;
49 case 1:
50 message += "Thawing Mainloop events";
51 mainloop.ThawEvent();
52 break;
53 default:
54 message += "Quitting";
55 mainloop.Quit(new Eina.Value(0));
56 break;
57 }
58 Console.WriteLine(message, tick_count, ((Efl.Object)sender).GetName());
59 tick_count++;
60 };
61 61
62 Console.WriteLine("Waiting for Timer to call back..."); 62 Console.WriteLine("Waiting for Timer to call back...");
63 63
diff --git a/reference/csharp/core/src/core_idler.cs b/reference/csharp/core/src/core_idler.cs
index 85c5f456..e8853e51 100644
--- a/reference/csharp/core/src/core_idler.cs
+++ b/reference/csharp/core/src/core_idler.cs
@@ -34,14 +34,14 @@ public class Example
34 }; 34 };
35 35
36 // Use a timer to exit the application 36 // Use a timer to exit the application
37 new Efl.LoopTimer(mainloop, (Efl.LoopTimer etimer) => { 37 var timer = new Efl.LoopTimer(mainloop, (Efl.LoopTimer etimer) => {
38 // Trigger after 10ms 38 // Trigger after 10ms
39 etimer.SetInterval(0.01); 39 etimer.SetInterval(0.01);
40 etimer.TickEvt += (object sender, EventArgs e) => {
41 Console.WriteLine("TIMER: timer callback called, exiting.");
42 mainloop.Quit(new Eina.Value(0));
43 };
44 }); 40 });
41 timer.TickEvt += (object sender, EventArgs e) => {
42 Console.WriteLine("TIMER: timer callback called, exiting.");
43 mainloop.Quit(new Eina.Value(0));
44 };
45 45
46 // Start the EFL main loop (and the experiment) 46 // Start the EFL main loop (and the experiment)
47 mainloop.Begin(); 47 mainloop.Begin();
diff --git a/reference/csharp/core/src/core_poll.cs b/reference/csharp/core/src/core_poll.cs
index 6c7c16ab..3ecf7bc1 100644
--- a/reference/csharp/core/src/core_poll.cs
+++ b/reference/csharp/core/src/core_poll.cs
@@ -33,14 +33,14 @@ public class Example
33 }; 33 };
34 34
35 // Use a timer to exit the application 35 // Use a timer to exit the application
36 new Efl.LoopTimer(mainloop, (Efl.LoopTimer etimer) => { 36 var timer = new Efl.LoopTimer(mainloop, (Efl.LoopTimer etimer) => {
37 // Trigger after 30s 37 // Trigger after 30s
38 etimer.SetInterval(30); 38 etimer.SetInterval(30);
39 etimer.TickEvt += (object sender, EventArgs e) => {
40 Console.WriteLine("\nTIMER: timer callback called, exiting.");
41 mainloop.Quit(new Eina.Value(0));
42 };
43 }); 39 });
40 timer.TickEvt += (object sender, EventArgs e) => {
41 Console.WriteLine("\nTIMER: timer callback called, exiting.");
42 mainloop.Quit(new Eina.Value(0));
43 };
44 44
45 // Start the EFL main loop (and the experiment) 45 // Start the EFL main loop (and the experiment)
46 mainloop.Begin(); 46 mainloop.Begin();
diff --git a/reference/csharp/ui/src/focus_main.cs b/reference/csharp/ui/src/focus_main.cs
index 5cf64638..700172f0 100644
--- a/reference/csharp/ui/src/focus_main.cs
+++ b/reference/csharp/ui/src/focus_main.cs
@@ -16,62 +16,57 @@ public class Example
16 Efl.All.Init(Efl.Components.Ui); 16 Efl.All.Init(Efl.Components.Ui);
17 17
18 // Create a window and initialize it 18 // Create a window and initialize it
19 var win = new Efl.Ui.Win(null, (Efl.Ui.Win ewin) => { 19 var win = new Efl.Ui.Win(null);
20 ewin.SetWinType(Efl.Ui.WinType.Basic); 20 win.SetWinType(Efl.Ui.WinType.Basic);
21 ewin.SetText("Focus example"); 21 win.SetText("Focus example");
22 ewin.SetAutohide(true); 22 win.SetAutohide(true);
23 ewin.HideEvt += (object sender, EventArgs e) => { 23 win.HideEvt += (object sender, EventArgs e) => {
24 // Exit the EFL main loop 24 // Exit the EFL main loop
25 Efl.Ui.Config.Exit(); 25 Efl.Ui.Config.Exit();
26 }; 26 };
27 }); 27
28 28
29 // Create the main box container 29 // Create the main box container
30 var vbox = new Efl.Ui.Box(win, (Efl.Ui.Box ebox) => { 30 var vbox = new Efl.Ui.Box(win);
31 ebox.SetHintMin(new Eina.Size2D(360, 240)); 31 vbox.SetHintMin(new Eina.Size2D(360, 240));
32 win.SetContent(ebox); 32 win.SetContent(vbox);
33 });
34 33
35 // Create some check boxes 34 // Create some check boxes
36 Efl.Ui.Check first_checkbox = null; 35 Efl.Ui.Check first_checkbox = null;
37 for (int i = 0; i< 5; i++) { 36 for (int i = 0; i< 5; i++) {
38 var checkbox = new Efl.Ui.Check(vbox, (Efl.Ui.Check echeck) => { 37 var checkbox = new Efl.Ui.Check(vbox);
39 echeck.SetText("Check " + i); 38 checkbox.SetText("Check " + i);
40 echeck.SetHintAlign(0.5, 0.5); 39 checkbox.SetHintAlign(0.5, 0.5);
41 echeck.FocusChangedEvt += FocusChangedCb; 40 checkbox.FocusChangedEvt += FocusChangedCb;
42 vbox.DoPack(echeck); 41 vbox.DoPack(checkbox);
43 });
44 if (i == 0) first_checkbox = checkbox; 42 if (i == 0) first_checkbox = checkbox;
45 }; 43 };
46 44
47 // Create an horizontal box to contain the two buttons 45 // Create an horizontal box to contain the two buttons
48 var hbox = new Efl.Ui.Box(vbox, (Efl.Ui.Box ebox) => { 46 var hbox = new Efl.Ui.Box(vbox);
49 ebox.SetDirection(Efl.Ui.Dir.Horizontal); 47 hbox.SetDirection(Efl.Ui.Dir.Horizontal);
50 vbox.DoPack(ebox); 48 vbox.DoPack(hbox);
51 });
52 49
53 // Create a "Focus Mover" button 50 // Create a "Focus Mover" button
54 new Efl.Ui.Button(hbox, (Efl.Ui.Button ebutton) => { 51 var button = new Efl.Ui.Button(hbox);
55 ebutton.SetText("Focus mover"); 52 button.SetText("Focus mover");
56 ebutton.FocusChangedEvt += FocusChangedCb; 53 button.FocusChangedEvt += FocusChangedCb;
57 ebutton.ClickedEvt += (object sender, EventArgs e) => { 54 button.ClickedEvt += (object sender, EventArgs e) => {
58 Console.WriteLine("Clicked Focus Mover"); 55 Console.WriteLine("Clicked Focus Mover");
59 // Manually transfer focus to the first check box 56 // Manually transfer focus to the first check box
60 Efl.Ui.Focus.Util.Focus(first_checkbox); 57 Efl.Ui.Focus.Util.Focus(first_checkbox);
61 }; 58 };
62 hbox.DoPack(ebutton); 59 hbox.DoPack(button);
63 });
64 60
65 // Create a Quit button 61 // Create a Quit button
66 new Efl.Ui.Button(hbox, (Efl.Ui.Button ebutton) => { 62 button = new Efl.Ui.Button(hbox);
67 ebutton.SetText("Quit"); 63 button.SetText("Quit");
68 ebutton.FocusChangedEvt += FocusChangedCb; 64 button.FocusChangedEvt += FocusChangedCb;
69 ebutton.ClickedEvt += (object sender, EventArgs e) => { 65 button.ClickedEvt += (object sender, EventArgs e) => {
70 Console.WriteLine("Clicked Quit"); 66 Console.WriteLine("Clicked Quit");
71 Efl.Ui.Config.Exit(); 67 Efl.Ui.Config.Exit();
72 }; 68 };
73 hbox.DoPack(ebutton); 69 hbox.DoPack(button);
74 });
75 70
76 // Show the focus highlight 71 // Show the focus highlight
77 win.SetFocusHighlightEnabled(true); 72 win.SetFocusHighlightEnabled(true);
diff --git a/reference/csharp/ui/src/ui_container.cs b/reference/csharp/ui/src/ui_container.cs
index 81e883b0..88dc3d03 100644
--- a/reference/csharp/ui/src/ui_container.cs
+++ b/reference/csharp/ui/src/ui_container.cs
@@ -12,23 +12,21 @@ public class Example
12 // Create a box container full of buttons 12 // Create a box container full of buttons
13 static Efl.Ui.Box CreateBox(Efl.Ui.Win win) 13 static Efl.Ui.Box CreateBox(Efl.Ui.Win win)
14 { 14 {
15 Efl.Ui.Box box = new Efl.Ui.Box(win, (Efl.Ui.Box ebox) => { 15 Efl.Ui.Box box = new Efl.Ui.Box(win);
16 // Set distance between contained elements 16 // Set distance between contained elements
17 ebox.SetPackPadding(5, 0, true); 17 box.SetPackPadding(5, 0, true);
18 });
19 18
20 for (int i = 1; i <= 4; ++i) 19 for (int i = 1; i <= 4; ++i)
21 { 20 {
22 // Add 4 buttons, one below the other 21 // Add 4 buttons, one below the other
23 new Efl.Ui.Button(win, (Efl.Ui.Button ebutton) => { 22 var button = new Efl.Ui.Button(win);
24 ebutton.SetText($"Boxed {i}"); 23 button.SetText($"Boxed {i}");
25 if (i == 2) 24 if (i == 2)
26 { 25 {
27 // Button 2 has its maximum size limited, so it will be smaller 26 // Button 2 has its maximum size limited, so it will be smaller
28 ebutton.SetHintMax(new Eina.Size2D(100,50)); 27 button.SetHintMax(new Eina.Size2D(100,50));
29 } 28 }
30 box.DoPack(ebutton); 29 box.DoPack(button);
31 });
32 } 30 }
33 31
34 return box; 32 return box;
@@ -37,26 +35,24 @@ public class Example
37 // Create a simple table layout 35 // Create a simple table layout
38 static Efl.Ui.Table CreateTable(Efl.Ui.Win win) 36 static Efl.Ui.Table CreateTable(Efl.Ui.Win win)
39 { 37 {
40 Efl.Ui.Table table = new Efl.Ui.Table(win, (Efl.Ui.Table etable) => { 38 Efl.Ui.Table table = new Efl.Ui.Table(win);
41 // Table with two columns, that get filled left to right, and then top to bottom 39 // Table with two columns, that get filled left to right, and then top to bottom
42 etable.SetTableColumns(2); 40 table.SetTableColumns(2);
43 etable.SetTableDirection(Efl.Ui.Dir.Right, Efl.Ui.Dir.Down); 41 table.SetTableDirection(Efl.Ui.Dir.Right, Efl.Ui.Dir.Down);
44 }); 42 Efl.Ui.Button button;
45 43
46 for (int i = 1; i <= 4; ++i) 44 for (int i = 1; i <= 4; ++i)
47 { 45 {
48 // Add 4 buttons, following the defined table flow 46 // Add 4 buttons, following the defined table flow
49 new Efl.Ui.Button(win, (Efl.Ui.Button ebutton) => { 47 button = new Efl.Ui.Button(win);
50 ebutton.SetText($"Table {i}"); 48 button.SetText($"Table {i}");
51 table.DoPack(ebutton); 49 table.DoPack(button);
52 });
53 } 50 }
54 51
55 // Last button spans two table cells 52 // Last button spans two table cells
56 new Efl.Ui.Button(win, (Efl.Ui.Button ebutton) => { 53 button = new Efl.Ui.Button(win);
57 ebutton.SetText("Long Button"); 54 button.SetText("Long Button");
58 table.PackTable(ebutton, 0, 2, 2, 1); 55 table.PackTable(button, 0, 2, 2, 1);
59 });
60 56
61 return table; 57 return table;
62 } 58 }
@@ -70,24 +66,22 @@ public class Example
70 Efl.All.Init(Efl.Components.Ui); 66 Efl.All.Init(Efl.Components.Ui);
71 67
72 // Create a window and initialize it 68 // Create a window and initialize it
73 Efl.Ui.Win win = new Efl.Ui.Win(null, (Efl.Ui.Win ewin) => { 69 Efl.Ui.Win win = new Efl.Ui.Win(null);
74 ewin.SetWinType(Efl.Ui.WinType.Basic); 70 win.SetWinType(Efl.Ui.WinType.Basic);
75 ewin.SetText("Container demo"); 71 win.SetText("Container demo");
76 ewin.SetAutohide(true); 72 win.SetAutohide(true);
77 ewin.HideEvt += (object sender, EventArgs e) => { 73 win.HideEvt += (object sender, EventArgs e) => {
78 // Exit the EFL main loop 74 // Exit the EFL main loop
79 Efl.Ui.Config.Exit(); 75 Efl.Ui.Config.Exit();
80 }; 76 };
81 });
82 // Give the window an initial size so there is room to resize the panes. 77 // Give the window an initial size so there is room to resize the panes.
83 // Otherwise, all widgets are tightly packed 78 // Otherwise, all widgets are tightly packed
84 win.SetSize(new Eina.Size2D(350,250)); 79 win.SetSize(new Eina.Size2D(350,250));
85 80
86 // Create a vertically-split panes container 81 // Create a vertically-split panes container
87 Efl.Ui.Panes vsplit = new Efl.Ui.Panes(win, (Efl.Ui.Panes epanes) => { 82 Efl.Ui.Panes vsplit = new Efl.Ui.Panes(win);
88 epanes.SetSplitRatio(0.75); 83 vsplit.SetSplitRatio(0.75);
89 win.SetContent(epanes); 84 win.SetContent(vsplit);
90 });
91 85
92 // Create some boxes and set them as the content of the first pane of the container 86 // Create some boxes and set them as the content of the first pane of the container
93 var box = CreateBox(win); 87 var box = CreateBox(win);
@@ -95,10 +89,9 @@ public class Example
95 89
96 // Create a second, horizontally-split panes container and set it as the content of 90 // Create a second, horizontally-split panes container and set it as the content of
97 // the second pane of the first container 91 // the second pane of the first container
98 Efl.Ui.Panes hsplit = new Efl.Ui.Panes(win, (Efl.Ui.Panes epanes) => { 92 Efl.Ui.Panes hsplit = new Efl.Ui.Panes(win);
99 epanes.SetDirection(Efl.Ui.Dir.Horizontal); 93 hsplit.SetDirection(Efl.Ui.Dir.Horizontal);
100 epanes.SetSplitRatio(0.85); 94 hsplit.SetSplitRatio(0.85);
101 });
102 Efl.ContentConcrete.static_cast(vsplit.GetPart("second")).SetContent(hsplit); 95 Efl.ContentConcrete.static_cast(vsplit.GetPart("second")).SetContent(hsplit);
103 96
104 // Create a table and set it as the content of the first pane of the horizontal 97 // Create a table and set it as the content of the first pane of the horizontal
@@ -108,14 +101,13 @@ public class Example
108 101
109 // Create a button and set it as the content of the second pane of the horizontal 102 // Create a button and set it as the content of the second pane of the horizontal
110 // container 103 // container
111 Efl.Ui.Button quit_btn = new Efl.Ui.Button(win, (Efl.Ui.Button ebutton) => { 104 Efl.Ui.Button quit_btn = new Efl.Ui.Button(win);
112 ebutton.SetText("Quit"); 105 quit_btn.SetText("Quit");
113 ebutton.SetHintMax(new Eina.Size2D(150, 30)); 106 quit_btn.SetHintMax(new Eina.Size2D(150, 30));
114 ebutton.ClickedEvt += (object sender, EventArgs e) => { 107 quit_btn.ClickedEvt += (object sender, EventArgs e) => {
115 // Exit the EFL main loop 108 // Exit the EFL main loop
116 Efl.Ui.Config.Exit(); 109 Efl.Ui.Config.Exit();
117 }; 110 };
118 });
119 Efl.ContentConcrete.static_cast(hsplit.GetPart("second")).SetContent(quit_btn); 111 Efl.ContentConcrete.static_cast(hsplit.GetPart("second")).SetContent(quit_btn);
120 112
121 // Start the EFL main loop 113 // Start the EFL main loop
diff --git a/reference/csharp/ui/src/ui_sizing.cs b/reference/csharp/ui/src/ui_sizing.cs
index dd6e5ffb..ac25283e 100644
--- a/reference/csharp/ui/src/ui_sizing.cs
+++ b/reference/csharp/ui/src/ui_sizing.cs
@@ -19,40 +19,35 @@ public class Example
19 Efl.All.Init(Efl.Components.Ui); 19 Efl.All.Init(Efl.Components.Ui);
20 20
21 // Create a window and initialize it 21 // Create a window and initialize it
22 Efl.Ui.Win win = new Efl.Ui.Win(null, (Efl.Ui.Win ewin) => { 22 Efl.Ui.Win win = new Efl.Ui.Win(null);
23 ewin.SetWinType(Efl.Ui.WinType.Basic); 23 win.SetWinType(Efl.Ui.WinType.Basic);
24 ewin.SetText("Size Control"); 24 win.SetText("Size Control");
25 ewin.SetAutohide(true); 25 win.SetAutohide(true);
26 ewin.HideEvt += (object sender, EventArgs e) => { 26 win.HideEvt += (object sender, EventArgs e) => {
27 // Exit the EFL main loop 27 // Exit the EFL main loop
28 Efl.Ui.Config.Exit(); 28 Efl.Ui.Config.Exit();
29 }; 29 };
30 });
31 30
32 // Create a box container 31 // Create a box container
33 Efl.Ui.Box box = new Efl.Ui.Box(win, (Efl.Ui.Box ebox) => { 32 Efl.Ui.Box box = new Efl.Ui.Box(win);
34 win.SetContent(ebox); 33 win.SetContent(box);
35 });
36 34
37 // Create a regular button (without size hints) 35 // Create a regular button (without size hints)
38 new Efl.Ui.Button(win, (Efl.Ui.Button ebutton) => { 36 var button = new Efl.Ui.Button(win);
39 ebutton.SetText("Button"); 37 button.SetText("Button");
40 box.DoPack(ebutton); 38 box.DoPack(button);
41 });
42 39
43 // Create a small button (max size is limited) 40 // Create a small button (max size is limited)
44 new Efl.Ui.Button(win, (Efl.Ui.Button ebutton) => { 41 button = new Efl.Ui.Button(win);
45 ebutton.SetText("Small"); 42 button.SetText("Small");
46 ebutton.SetHintMax(new Eina.Size2D(50,50)); 43 button.SetHintMax(new Eina.Size2D(50,50));
47 box.DoPack(ebutton); 44 box.DoPack(button);
48 });
49 45
50 // Create a big button (min size is limited) 46 // Create a big button (min size is limited)
51 new Efl.Ui.Button(win, (Efl.Ui.Button ebutton) => { 47 button = new Efl.Ui.Button(win);
52 ebutton.SetText("Big button"); 48 button.SetText("Big button");
53 ebutton.SetHintMin(new Eina.Size2D(100,100)); 49 button.SetHintMin(new Eina.Size2D(100,100));
54 box.DoPack(ebutton); 50 box.DoPack(button);
55 });
56 51
57 // Start the EFL main loop 52 // Start the EFL main loop
58 Efl.Ui.Config.Run(); 53 Efl.Ui.Config.Run();