vitorsousa pushed a commit to branch master.

http://git.enlightenment.org/tools/examples.git/commit/?id=4c35b0f8c1a47aa7a0cdfca8d0f684f0c0730d14

commit 4c35b0f8c1a47aa7a0cdfca8d0f684f0c0730d14
Author: Xavi Artigas <[email protected]>
Date:   Tue Sep 18 12:48:36 2018 -0300

    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
---
 reference/csharp/ui/src/focus_main.cs | 98 ++++++++++++++++++++---------------
 1 file changed, 57 insertions(+), 41 deletions(-)

diff --git a/reference/csharp/ui/src/focus_main.cs 
b/reference/csharp/ui/src/focus_main.cs
index 741acb45..354f7959 100644
--- a/reference/csharp/ui/src/focus_main.cs
+++ b/reference/csharp/ui/src/focus_main.cs
@@ -2,67 +2,83 @@ using System;
 
 public class Example
 {
-    public static void QuitCb(object sender, EventArgs e)
-    {
-        Console.WriteLine("Clicked Quit");
-        efl.ui.Config.Exit();
-    }
-
-    public static void AboutCb(object sender, EventArgs e)
-    {
-        Console.WriteLine("Clicked About");
-    }
-
     public static void FocusChangedCb(object sender, EventArgs e)
     {
         Console.WriteLine($"Focus for object {((efl.IText)sender).GetText()} 
changed to {((efl.ui.IWidget)sender).GetFocus()}");
     }
 
+#if WIN32
+    [STAThreadAttribute()]
+#endif
     public static void Main()
     {
+        // Initialize EFL and all UI components
         efl.All.Init(efl.Components.Ui);
 
-        efl.ui.IWin win = new efl.ui.Win(null, (efl.ui.IWin ewin) => {
+        // Create a window and initialize it
+        var win = new efl.ui.Win(null, (efl.ui.IWin ewin) => {
             ewin.SetWinType(efl.ui.Win_Type.Basic);
-            ewin.SetText("Hello World");
+            ewin.SetText("Focus example");
             ewin.SetAutohide(true);
+            ewin.HideEvt += (object sender, EventArgs e) => {
+                // Exit the EFL main loop
+                efl.ui.Config.Exit();
+            };
         });
-        win.HideEvt += QuitCb;
 
-        efl.ui.IBox box = new efl.ui.Box(win);
-        eina.Size2D sz;
-        sz.W = 360;
-        sz.H = 240;
-        box.SetHintMin(sz);
-        win.SetContent(box);
-
-        efl.ui.IText text = new efl.ui.Text(box);
-        text.SetText("Label");
-        text.SetEditable(false);
-        text.FocusChangedEvt += FocusChangedCb;
-        box.DoPack(text);
+        // Create the main box container
+        var vbox = new efl.ui.Box(win, (efl.ui.IBox ebox) => {
+          ebox.SetHintMin(new eina.Size2D(360, 240));
+          win.SetContent(ebox);
+        });
 
-        efl.ui.IBox hbox = new efl.ui.Box(box);
-        hbox.SetDirection(efl.ui.Dir.Horizontal);
-        hbox.SetHintWeight(1.0, 0.1);
-        box.DoPack(hbox);
+        // Create some check boxes
+        efl.ui.ICheck first_checkbox = null;
+        for (int i = 0; i< 5; i++) {
+          var checkbox = new efl.ui.Check(vbox, (efl.ui.ICheck echeck) => {
+            echeck.SetText("Check " + i);
+            echeck.SetHintAlign(0.5, 0.5);
+            echeck.FocusChangedEvt += FocusChangedCb;
+            vbox.DoPack(echeck);
+          });
+          if (i == 0) first_checkbox = checkbox;
+        };
 
-        efl.ui.IButton about = new efl.ui.Button(hbox);
-        about.SetText("About");
-        about.FocusChangedEvt += FocusChangedCb;
-        about.ClickedEvt += AboutCb;
-        hbox.DoPack(about);
+        // Create an horizontal box to contain the two buttons
+        var hbox = new efl.ui.Box(vbox, (efl.ui.IBox ebox) => {
+          ebox.SetDirection(efl.ui.Dir.Horizontal);
+          vbox.DoPack(ebox);
+        });
 
-        efl.ui.IButton quit = new efl.ui.Button(hbox);
-        quit.SetText("Quit");
-        quit.FocusChangedEvt += FocusChangedCb;
-        quit.ClickedEvt += QuitCb;
-        hbox.DoPack(quit);
+        // Create a "Focus Mover" button
+        new efl.ui.Button(hbox, (efl.ui.IButton ebutton) => {
+          ebutton.SetText("Focus mover");
+          ebutton.FocusChangedEvt += FocusChangedCb;
+          ebutton.ClickedEvt += (object sender, EventArgs e) => {
+            Console.WriteLine("Clicked Focus Mover");
+            // Manually transfer focus to the first check box
+            efl.ui.focus.Util.Focus(first_checkbox);
+          };
+          hbox.DoPack(ebutton);
+        });
 
-        efl.ui.focus.Util.Focus(about);
+        // Create a Quit button
+        new efl.ui.Button(hbox, (efl.ui.IButton ebutton) => {
+          ebutton.SetText("Quit");
+          ebutton.FocusChangedEvt += FocusChangedCb;
+          ebutton.ClickedEvt += (object sender, EventArgs e) => {
+            Console.WriteLine("Clicked Quit");
+            efl.ui.Config.Exit();
+          };
+          hbox.DoPack(ebutton);
+          // Set focus on this widget and show the focus highlight
+          ebutton.SetFocusHighlightEnabled(true);
+        });
 
+        // Start the EFL main loop
         efl.ui.Config.Run();
 
+        // Shutdown EFL
         efl.All.Shutdown();
     }
 }

-- 


Reply via email to