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

public class Example
{
    // Callback to quit the application
    public static void QuitCb(object sender, EventArgs e)
    {
        // Exit the EFL main loop
        Efl.Ui.Config.Exit();
    }

#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
        Efl.Ui.Win win = new Efl.Ui.Win(Efl.App.AppMain, (Efl.Ui.Win ewin) => {
            // Set the window's title
            ewin.SetText("Hello World");
            // Request that the window is automatically hidden when the "close"
            // button is pressed
            ewin.SetAutohide(true);
            // Hook to the Hide event
            ewin.HideEvt += QuitCb;
        });

        // Create a box container
        Efl.Ui.Box box = new Efl.Ui.Box(win, (Efl.Ui.Box ebox) => {
            // Set its minimum size
            ebox.SetHintMin(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(ebox);
        });

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

        // Create a button widget
        new Efl.Ui.Button(box, (Efl.Ui.Button ebutton) => {
            // Customize it
            ebutton.SetText("Quit");
            ebutton.SetHintWeight(1.0, 0.1);
            // Set the method to be called when the button is pressed
            ebutton.ClickedEvt += QuitCb;
            // Add the button to the box container
            box.DoPack(ebutton);
        });

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

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