summaryrefslogtreecommitdiff
path: root/reference/csharp/ui/src/ui_container.cs
blob: 714572d3cb8b01f077557d46379ca5890f7f0241 (plain) (blame)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 * Efl.UI container exmaples.
 *
 * Load and pack a selection of containers.
 * Each has it's own unique layout and methods which are demonstrated below.
 */

using System;

public class Example
{
    // quit the app, called if the user clicks the Quit button or the window is hidden
    static void GuiQuitCb(object sender, EventArgs e)
    {
        efl.ui.Config.Exit();
    }

    // Load a simple table layout into the window
    static efl.ui.ITable SetupUiTable(efl.ui.IWin win)
    {
        efl.ui.ITable table = new efl.ui.Table(win);

        table.SetTableColumns(2);
        table.SetTableDirection(efl.ui.Dir.Right, efl.ui.Dir.Down);

        efl.ui.IButton button = new efl.ui.Button(win);
        button.SetText("Long Button");

        table.PackTable(button, 0, 2, 2, 1);

        for (int i = 1; i <= 4; ++i)
        {
            efl.ui.IButton btn = new efl.ui.Button(win);
            btn.SetText($"Table {i}");
            table.DoPack(btn);
        }

        return table;
    }

    // Load some boxes - a horizontal one for the window layout and a vertical
    // one to contain a flow
    static efl.ui.IBox SetupUiBoxes(efl.ui.IWin win)
    {
        efl.ui.IBox box = new efl.ui.Box(win);
        box.SetPackPadding(5, 0, true);

        for (int i = 1; i <= 4; ++i)
        {
            efl.ui.IButton button = new efl.ui.Button(win);
            button.SetText($"Boxed {i}");
            if (i == 2)
            {
                eina.Size2D sz;
                sz.W = 100;
                sz.H = 50;
                button.SetHintMax(sz);
            }
            box.DoPack(button);
        }

        return box;
    }

    public static void Main()
    {
        efl.All.Init(efl.Components.Ui);

        efl.ui.IWin win = new efl.ui.Win(null, (efl.ui.IWin ewin) => {
            ewin.SetWinType(efl.ui.Win_Type.Basic);
            ewin.SetText("Hello World");
            ewin.SetAutohide(true);
        });
        eina.Size2D sz;
        sz.W = 350;
        sz.H = 250;
        win.SetSize(sz);

        // when the user clicks "close" on a window there is a request to hide
        win.HideEvt += GuiQuitCb;

        // Load a vertical and horizontal split into the window

        efl.ui.IPanes split = new efl.ui.Panes(win);
        split.SetSplitRatio(0.75);
        win.SetContent(split);

        var boxes = SetupUiBoxes(win);
        efl.Content.static_cast(split.GetPart("first")).SetContent(boxes);

        efl.ui.IPanes horiz_split = new efl.ui.Panes(win);
        horiz_split.SetDirection(efl.ui.Dir.Horizontal);
        horiz_split.SetSplitRatio(0.85);
        efl.Content.static_cast(split.GetPart("second")).SetContent(horiz_split);

        var table = SetupUiTable(win);
        efl.Content.static_cast(horiz_split.GetPart("first")).SetContent(table);

        efl.ui.IButton quit_btn = new efl.ui.Button(win);
        quit_btn.SetText("Quit");
        sz.W = 150;
        sz.H = 30;
        quit_btn.SetHintMax(sz);
        quit_btn.ClickedEvt += GuiQuitCb;
        efl.Content.static_cast(horiz_split.GetPart("second")).SetContent(quit_btn);

        // Start event loop
        efl.ui.Config.Run();

        efl.All.Shutdown();
    }
}