summaryrefslogtreecommitdiff
path: root/reference/csharp/ui/src/focus_main.cs
blob: 8c69ccafce47a7a323d70bbf562066c4d14f62f6 (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
using System;

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

    protected override void OnInitialize(Eina.Array<System.String> args)
    {
        // Create a window and initialize it
        var win = new Efl.Ui.Win(null, winType: Efl.Ui.WinType.Basic);
        win.SetText("Focus example");
        win.SetAutohide(true);
        win.VisibilityChangedEvt += (object sender, Efl.Gfx.IEntityVisibilityChangedEvt_Args e) => {
            // Exit the EFL main loop
            if (e.arg == false)
                Efl.Ui.Config.Exit();
        };
        

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

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

        // Create an horizontal box to contain the two buttons
        var hbox = new Efl.Ui.Box(vbox);
        hbox.SetOrientation(Efl.Ui.LayoutOrientation.Horizontal);
        vbox.Pack(hbox);

        // Create a "Focus Mover" button
        var button = new Efl.Ui.Button(hbox);
        button.SetText("Focus mover");
        button.FocusChangedEvt += FocusChangedCb;
        button.ClickedEvt += (object sender, Efl.Ui.IClickableClickedEvt_Args e) => {
            Console.WriteLine("Clicked Focus Mover");
            // Manually transfer focus to the first check box
            Efl.Ui.Focus.Util.Focus(first_checkbox);
        };
        hbox.Pack(button);

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

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

#if WIN32
    [STAThreadAttribute()]
#endif
    public static void Main()
    {
        var example = new Example();
        example.Launch();
    }
}