summaryrefslogtreecommitdiff
path: root/tutorial/csharp/hello-gui/src/gui_main.cs
blob: cc6eaa90b69909d3e62082fc9ffc3284283ff1fa (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
using System;

public class Example : Efl.Csharp.Application
{
    // Callback to quit the application
    public static void QuitCb(object sender, Efl.Gfx.IEntityVisibilityChangedEvt_Args e)
    {
        // Exit the EFL main loop
        if (e.arg == false)
          Efl.App.AppMain.Quit(0);
    }

    protected override void OnInitialize(Eina.Array<System.String> args)
    {
        // Create a window and initialize it
        Efl.Ui.Win win = new Efl.Ui.Win(Efl.App.AppMain);
        // Set the window's title
        win.SetText("Hello World");
        // Request that the window is automatically hidden when the "close"
        // button is pressed
        win.SetAutohide(true);
        // Hook to the Hide event
        win.VisibilityChangedEvt += QuitCb;

        // Create a box container
        var box = new Efl.Ui.Box(win);
        // Set its minimum size
        box.SetHintSizeMin(new Eina.Size2D(360, 240));
        // Set the box as the content for the window
        // The window size will adapt to the box size
        win.SetContent(box);

        // Create a text label widget
        var label = new Efl.Ui.Text(box);
        // Set its content and customize it
        label.SetText("Hello World. This is an Efl.Ui application!");
        label.SetSelectionAllowed(false);
        label.SetHintWeight(1.0, 0.9);
        label.SetHintAlign(0.5, 0.5);
        // Add the text to the box container
        box.Pack(label);

        // Create a button widget
        var button = new Efl.Ui.Button(box);
        // Customize it
        button.SetText("Quit");
        button.SetHintWeight(1.0, 0.1);
        // Set the method to be called when the button is pressed
        button.ClickedEvt += (object sender, EventArgs e) => { Efl.App.AppMain.Quit(0); };
        // Add the button to the box container
        box.Pack(button);
    }

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