summaryrefslogtreecommitdiff
path: root/reference/csharp/ui
diff options
context:
space:
mode:
authorXavi Artigas <xavierartigas@yahoo.es>2018-09-18 12:48:36 -0300
committerVitor Sousa <vitorsousa@expertisesolutions.com.br>2018-09-18 13:29:31 -0300
commit4c35b0f8c1a47aa7a0cdfca8d0f684f0c0730d14 (patch)
tree492f97e69d6ef7898f99557488ada66c9d2d085a /reference/csharp/ui
parentd1e530d25604d59a2e3f86ef59a5ecd47564800c (diff)
csharp: revamp focus example
Summary: It was a very poor example, the focus highlight did not show on startup, and the Text widget has a weird management of the focus. Replaced it by some check boxes, and the About button now moves the focus. Reviewers: lauromoura, vitor.sousa, felipealmeida, bu5hm4n Reviewed By: vitor.sousa Differential Revision: https://phab.enlightenment.org/D7056
Diffstat (limited to 'reference/csharp/ui')
-rw-r--r--reference/csharp/ui/src/focus_main.cs98
1 files changed, 57 insertions, 41 deletions
diff --git a/reference/csharp/ui/src/focus_main.cs b/reference/csharp/ui/src/focus_main.cs
index 741acb4..354f795 100644
--- a/reference/csharp/ui/src/focus_main.cs
+++ b/reference/csharp/ui/src/focus_main.cs
@@ -2,67 +2,83 @@ using System;
2 2
3public class Example 3public class Example
4{ 4{
5 public static void QuitCb(object sender, EventArgs e)
6 {
7 Console.WriteLine("Clicked Quit");
8 efl.ui.Config.Exit();
9 }
10
11 public static void AboutCb(object sender, EventArgs e)
12 {
13 Console.WriteLine("Clicked About");
14 }
15
16 public static void FocusChangedCb(object sender, EventArgs e) 5 public static void FocusChangedCb(object sender, EventArgs e)
17 { 6 {
18 Console.WriteLine($"Focus for object {((efl.IText)sender).GetText()} changed to {((efl.ui.IWidget)sender).GetFocus()}"); 7 Console.WriteLine($"Focus for object {((efl.IText)sender).GetText()} changed to {((efl.ui.IWidget)sender).GetFocus()}");
19 } 8 }
20 9
10#if WIN32
11 [STAThreadAttribute()]
12#endif
21 public static void Main() 13 public static void Main()
22 { 14 {
15 // Initialize EFL and all UI components
23 efl.All.Init(efl.Components.Ui); 16 efl.All.Init(efl.Components.Ui);
24 17
25 efl.ui.IWin win = new efl.ui.Win(null, (efl.ui.IWin ewin) => { 18 // Create a window and initialize it
19 var win = new efl.ui.Win(null, (efl.ui.IWin ewin) => {
26 ewin.SetWinType(efl.ui.Win_Type.Basic); 20 ewin.SetWinType(efl.ui.Win_Type.Basic);
27 ewin.SetText("Hello World"); 21 ewin.SetText("Focus example");
28 ewin.SetAutohide(true); 22 ewin.SetAutohide(true);
23 ewin.HideEvt += (object sender, EventArgs e) => {
24 // Exit the EFL main loop
25 efl.ui.Config.Exit();
26 };
29 }); 27 });
30 win.HideEvt += QuitCb;
31 28
32 efl.ui.IBox box = new efl.ui.Box(win); 29 // Create the main box container
33 eina.Size2D sz; 30 var vbox = new efl.ui.Box(win, (efl.ui.IBox ebox) => {
34 sz.W = 360; 31 ebox.SetHintMin(new eina.Size2D(360, 240));
35 sz.H = 240; 32 win.SetContent(ebox);
36 box.SetHintMin(sz); 33 });
37 win.SetContent(box);
38
39 efl.ui.IText text = new efl.ui.Text(box);
40 text.SetText("Label");
41 text.SetEditable(false);
42 text.FocusChangedEvt += FocusChangedCb;
43 box.DoPack(text);
44 34
45 efl.ui.IBox hbox = new efl.ui.Box(box); 35 // Create some check boxes
46 hbox.SetDirection(efl.ui.Dir.Horizontal); 36 efl.ui.ICheck first_checkbox = null;
47 hbox.SetHintWeight(1.0, 0.1); 37 for (int i = 0; i< 5; i++) {
48 box.DoPack(hbox); 38 var checkbox = new efl.ui.Check(vbox, (efl.ui.ICheck echeck) => {
39 echeck.SetText("Check " + i);
40 echeck.SetHintAlign(0.5, 0.5);
41 echeck.FocusChangedEvt += FocusChangedCb;
42 vbox.DoPack(echeck);
43 });
44 if (i == 0) first_checkbox = checkbox;
45 };
49 46
50 efl.ui.IButton about = new efl.ui.Button(hbox); 47 // Create an horizontal box to contain the two buttons
51 about.SetText("About"); 48 var hbox = new efl.ui.Box(vbox, (efl.ui.IBox ebox) => {
52 about.FocusChangedEvt += FocusChangedCb; 49 ebox.SetDirection(efl.ui.Dir.Horizontal);
53 about.ClickedEvt += AboutCb; 50 vbox.DoPack(ebox);
54 hbox.DoPack(about); 51 });
55 52
56 efl.ui.IButton quit = new efl.ui.Button(hbox); 53 // Create a "Focus Mover" button
57 quit.SetText("Quit"); 54 new efl.ui.Button(hbox, (efl.ui.IButton ebutton) => {
58 quit.FocusChangedEvt += FocusChangedCb; 55 ebutton.SetText("Focus mover");
59 quit.ClickedEvt += QuitCb; 56 ebutton.FocusChangedEvt += FocusChangedCb;
60 hbox.DoPack(quit); 57 ebutton.ClickedEvt += (object sender, EventArgs e) => {
58 Console.WriteLine("Clicked Focus Mover");
59 // Manually transfer focus to the first check box
60 efl.ui.focus.Util.Focus(first_checkbox);
61 };
62 hbox.DoPack(ebutton);
63 });
61 64
62 efl.ui.focus.Util.Focus(about); 65 // Create a Quit button
66 new efl.ui.Button(hbox, (efl.ui.IButton ebutton) => {
67 ebutton.SetText("Quit");
68 ebutton.FocusChangedEvt += FocusChangedCb;
69 ebutton.ClickedEvt += (object sender, EventArgs e) => {
70 Console.WriteLine("Clicked Quit");
71 efl.ui.Config.Exit();
72 };
73 hbox.DoPack(ebutton);
74 // Set focus on this widget and show the focus highlight
75 ebutton.SetFocusHighlightEnabled(true);
76 });
63 77
78 // Start the EFL main loop
64 efl.ui.Config.Run(); 79 efl.ui.Config.Run();
65 80
81 // Shutdown EFL
66 efl.All.Shutdown(); 82 efl.All.Shutdown();
67 } 83 }
68} 84}