summaryrefslogtreecommitdiff
path: root/reference/csharp/ui/src/ui_container.cs
blob: 0cd9a9f72554c4348c583f9a059ed59ce4432d49 (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
 * Efl.Ui container examples.
 * Showcase a selection of containers.
 * Each has its own unique layout and methods which are demonstrated below.
 *
 * +vpanes---------------------+
 * | +vbox---+ # +hpanes-----+ |
 * | |       | # | +table--+ | |
 * | |       | # | |       | | |
 * | |       | # | |       | | |
 * | |       | # | +-------+ | |
 * | |       | # | ######### | |
 * | |       | # | +stack--+ | |
 * | |       | # | |       | | |
 * | |       | # | |       | | |
 * | |       | # | +-------+ | |
 * | +-------+ # +-----------+ |
 * +---------------------------+
 */

using System;

public class Example
{
    efl.ui.IButton quit_btn;
    efl.ui.IButton about_btn;

    // Create a box container full of buttons
    efl.ui.IBox CreateBox(efl.ui.IWin win)
    {
        efl.ui.IBox box = new efl.ui.Box(win, (efl.ui.IBox ebox) => {
          // Set distance between contained elements
          ebox.SetPackPadding(5, 0, true);
        });

        for (int i = 1; i <= 4; ++i)
        {
            // Add 4 buttons, one below the other
            new efl.ui.Button(win, (efl.ui.IButton ebutton) => {
              switch (i) {
                case 1:
                  ebutton.SetText("Show About button");
                  ebutton.ClickedEvt += (object sender, EventArgs e) => {
                    about_btn.SetVisible(true);
                    quit_btn.SetVisible(false);
                  };
                  break;
                case 2:
                  ebutton.SetText("Show Quit button");
                  ebutton.ClickedEvt += (object sender, EventArgs e) => {
                    about_btn.SetVisible(false);
                    quit_btn.SetVisible(true);
                  };
                  break;
                case 3:
                  // Button 2 has its maximum size limited, so it will be smaller
                  ebutton.SetText("Smaller button");
                  ebutton.SetHintMax(new eina.Size2D(100,50));
                  ebutton.SetDisabled(true);
                  break;
                default:
                  ebutton.SetText($"Boxed {i}");
                  ebutton.SetDisabled(true);
                  break;
              }
              box.DoPack(ebutton);
            });
        }

        return box;
    }

    // Create a simple table layout
    efl.ui.ITable CreateTable(efl.ui.IWin win)
    {
        efl.ui.ITable table = new efl.ui.Table(win, (efl.ui.ITable etable) => {
          // Table with two columns, that get filled left to right, and then top to bottom
          etable.SetTableColumns(2);
          etable.SetTableDirection(efl.ui.Dir.Right, efl.ui.Dir.Down);
        });

        for (int i = 1; i <= 4; ++i)
        {
            // Add 4 buttons, following the defined table flow
            new efl.ui.Button(win, (efl.ui.IButton ebutton) => {
              ebutton.SetText($"Table {i}");
              ebutton.SetDisabled(true);
              table.DoPack(ebutton);
            });
        }

        // Last button spans two table cells
        new efl.ui.Button(win, (efl.ui.IButton ebutton) => {
          ebutton.SetText("Long Button");
          ebutton.SetDisabled(true);
          table.PackTable(ebutton, 0, 2, 2, 1);
        });

        return table;
    }

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

        // Initialize EFL and all UI components
        efl.All.Init(efl.Components.Ui);

        // Create a window and initialize it
        efl.ui.IWin win = new efl.ui.Win(null, (efl.ui.IWin ewin) => {
            ewin.SetWinType(efl.ui.Win_Type.Basic);
            ewin.SetText("Container demo");
            ewin.SetAutohide(true);
            ewin.HideEvt += (object sender, EventArgs e) => {
              // Exit the EFL main loop
              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.IPanes vsplit = new efl.ui.Panes(win, (efl.ui.IPanes epanes) => {
          epanes.SetSplitRatio(0.75);
          win.SetContent(epanes);
        });

        // Create some boxes and set them as the content of the first pane of the container
        var box = example.CreateBox(win);
        efl.Content.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.IPanes hsplit = new efl.ui.Panes(win, (efl.ui.IPanes epanes) => {
          epanes.SetDirection(efl.ui.Dir.Horizontal);
          epanes.SetSplitRatio(0.85);
        });
        efl.Content.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 = example.CreateTable(win);
        efl.Content.static_cast(hsplit.GetPart("first")).SetContent(table);

        // Create a stacked box and set it as the content of the second pane of the horizontal
        // container
        efl.ui.IBox_Stack stack = new efl.ui.Box_Stack(win);
        efl.Content.static_cast(hsplit.GetPart("second")).SetContent(stack);

        // Add an About button to the stacked box container
        example.about_btn = new efl.ui.Button(win, (efl.ui.IButton ebutton) => {
          ebutton.SetText("About");
          ebutton.SetHintMax(new eina.Size2D(150, 30));
          ebutton.SetDisabled(true);
          stack.DoPack(ebutton);
        });
        // Add a Quit button to the stacked box container
        example.quit_btn = new efl.ui.Button(win, (efl.ui.IButton ebutton) => {
          ebutton.SetText("Quit");
          ebutton.SetHintMax(new eina.Size2D(150, 30));
          ebutton.SetVisible(false);
          ebutton.ClickedEvt += (object sender, EventArgs e) => {
            // Exit the EFL main loop
            efl.ui.Config.Exit();
          };
          stack.DoPack(ebutton);
        });

        // Start the EFL main loop
        efl.ui.Config.Run();

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