summaryrefslogtreecommitdiff
path: root/reference/csharp/ui/src/ui_container.cs
blob: 97c1fc7127fb5d18faf66f4c72a631276271aef4 (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
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
113
114
115
116
117
/*
 * Efl.UI container examples.
 *
 * Load and pack a selection of containers.
 * Each has its own unique layout and methods which are demonstrated below.
 */

using System;

public class Example : Efl.Csharp.Application
{
    // Create a box container full of buttons
    static Efl.Ui.Box CreateBox(Efl.Ui.Win win)
    {
        Efl.Ui.Box box = new Efl.Ui.Box(win);
        // Set distance between contained elements
        box.SetPackPadding(5, 0, true);

        for (int i = 1; i <= 4; ++i)
        {
            // Add 4 buttons, one below the other
            var button = new Efl.Ui.Button(win);
            button.SetText($"Boxed {i}");
            if (i == 2)
            {
              // Button 2 has its maximum size limited, so it will be smaller
              button.SetHintSizeMax(new Eina.Size2D(100,50));
            }
            box.DoPack(button);
        }

        return box;
    }

    // Create a simple table layout
    static Efl.Ui.Table CreateTable(Efl.Ui.Win win)
    {
        Efl.Ui.Table table = new Efl.Ui.Table(win);
        // Table with two columns, that get filled left to right, and then top to bottom
        table.SetTableColumns(2);
        table.SetTableDirection(Efl.Ui.Dir.Right, Efl.Ui.Dir.Down);
        Efl.Ui.Button button;

        for (int i = 1; i <= 4; ++i)
        {
            // Add 4 buttons, following the defined table flow
            button = new Efl.Ui.Button(win);
            button.SetText($"Table {i}");
            table.DoPack(button);
        }

        // Last button spans two table cells
        button = new Efl.Ui.Button(win);
        button.SetText("Long Button");
        table.PackTable(button, 0, 2, 2, 1);

        return table;
    }

    protected override void OnInitialize(Eina.Array<System.String> args)
    {
        // Create a window and initialize it
        Efl.Ui.Win win = new Efl.Ui.Win(null, winType: Efl.Ui.WinType.Basic);
        win.SetText("Container demo");
        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();
        };
        // Give the window an initial size so there is room to resize the panes.
        // Otherwise, all widgets are tightly packed
        win.SetSize(new Eina.Size2D(350,250));

        // Create a vertically-split panes container
        Efl.Ui.Panes vsplit = new Efl.Ui.Panes(win);
        vsplit.SetSplitRatio(0.75);
        win.SetContent(vsplit);

        // Create some boxes and set them as the content of the first pane of the container
        var box = CreateBox(win);
        Efl.IContentConcrete.static_cast(vsplit.GetPart("first")).SetContent(box);

        // Create a second, horizontally-split panes container and set it as the content of
        // the second pane of the first container
        Efl.Ui.Panes hsplit = new Efl.Ui.Panes(win);
        hsplit.SetDirection(Efl.Ui.Dir.Horizontal);
        hsplit.SetSplitRatio(0.85);
        Efl.IContentConcrete.static_cast(vsplit.GetPart("second")).SetContent(hsplit);

        // Create a table and set it as the content of the first pane of the horizontal
        // container
        var table = CreateTable(win);
        Efl.IContentConcrete.static_cast(hsplit.GetPart("first")).SetContent(table);

        // Create a button and set it as the content of the second pane of the horizontal
        // container
        Efl.Ui.Button quit_btn = new Efl.Ui.Button(win);
        quit_btn.SetText("Quit");
        quit_btn.SetHintSizeMax(new Eina.Size2D(150, 30));
        quit_btn.ClickedEvt += (object sender, EventArgs e) => {
            // Exit the EFL main loop
            Efl.Ui.Config.Exit();
        };
        Efl.IContentConcrete.static_cast(hsplit.GetPart("second")).SetContent(quit_btn);
    }

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