summaryrefslogtreecommitdiff
path: root/reference/csharp/ui/src/focus_main.cs
blob: 5cf64638178592c1c03af70301bc163781ddd23d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;

public class Example
{
    public static void FocusChangedCb(object sender, EventArgs e)
    {
        Console.WriteLine($"Focus for object {((Efl.Text)sender).GetText()} changed to {((Efl.Ui.Widget)sender).GetFocus()}");
    }

#if WIN32
    [STAThreadAttribute()]
#endif
    public static void Main()
    {
        // Initialize EFL and all UI components
        Efl.All.Init(Efl.Components.Ui);

        // Create a window and initialize it
        var win = new Efl.Ui.Win(null, (Efl.Ui.Win ewin) => {
            ewin.SetWinType(Efl.Ui.WinType.Basic);
            ewin.SetText("Focus example");
            ewin.SetAutohide(true);
            ewin.HideEvt += (object sender, EventArgs e) => {
                // Exit the EFL main loop
                Efl.Ui.Config.Exit();
            };
        });

        // Create the main box container
        var vbox = new Efl.Ui.Box(win, (Efl.Ui.Box ebox) => {
          ebox.SetHintMin(new Eina.Size2D(360, 240));
          win.SetContent(ebox);
        });

        // Create some check boxes
        Efl.Ui.Check first_checkbox = null;
        for (int i = 0; i< 5; i++) {
          var checkbox = new Efl.Ui.Check(vbox, (Efl.Ui.Check echeck) => {
            echeck.SetText("Check " + i);
            echeck.SetHintAlign(0.5, 0.5);
            echeck.FocusChangedEvt += FocusChangedCb;
            vbox.DoPack(echeck);
          });
          if (i == 0) first_checkbox = checkbox;
        };

        // Create an horizontal box to contain the two buttons
        var hbox = new Efl.Ui.Box(vbox, (Efl.Ui.Box ebox) => {
          ebox.SetDirection(Efl.Ui.Dir.Horizontal);
          vbox.DoPack(ebox);
        });

        // Create a "Focus Mover" button
        new Efl.Ui.Button(hbox, (Efl.Ui.Button 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);
        });

        // Create a Quit button
        new Efl.Ui.Button(hbox, (Efl.Ui.Button ebutton) => {
          ebutton.SetText("Quit");
          ebutton.FocusChangedEvt += FocusChangedCb;
          ebutton.ClickedEvt += (object sender, EventArgs e) => {
            Console.WriteLine("Clicked Quit");
            Efl.Ui.Config.Exit();
          };
          hbox.DoPack(ebutton);
        });

        // Show the focus highlight
        win.SetFocusHighlightEnabled(true);

        // Start the EFL main loop
        Efl.Ui.Config.Run();

        // Shutdown EFL
        Efl.All.Shutdown();
    }
}