examples/reference/csharp/ui/src/ui_container.cs

129 lines
4.3 KiB
C#
Raw Normal View History

/*
* 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
{
// 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, (Efl.Ui.Box 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.Button ebutton) => {
ebutton.SetText($"Boxed {i}");
if (i == 2)
{
// Button 2 has its maximum size limited, so it will be smaller
ebutton.SetHintMax(new Eina.Size2D(100,50));
}
box.DoPack(ebutton);
});
}
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, (Efl.Ui.Table 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.Button ebutton) => {
ebutton.SetText($"Table {i}");
table.DoPack(ebutton);
});
}
// Last button spans two table cells
new Efl.Ui.Button(win, (Efl.Ui.Button ebutton) => {
ebutton.SetText("Long Button");
table.PackTable(ebutton, 0, 2, 2, 1);
});
return table;
}
#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(null, (Efl.Ui.Win ewin) => {
ewin.SetWinType(Efl.Ui.WinType.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.Panes vsplit = new Efl.Ui.Panes(win, (Efl.Ui.Panes 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 = CreateBox(win);
Efl.ContentConcrete.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, (Efl.Ui.Panes epanes) => {
epanes.SetDirection(Efl.Ui.Dir.Horizontal);
epanes.SetSplitRatio(0.85);
});
Efl.ContentConcrete.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.ContentConcrete.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, (Efl.Ui.Button ebutton) => {
ebutton.SetText("Quit");
ebutton.SetHintMax(new Eina.Size2D(150, 30));
ebutton.ClickedEvt += (object sender, EventArgs e) => {
// Exit the EFL main loop
Efl.Ui.Config.Exit();
};
});
Efl.ContentConcrete.static_cast(hsplit.GetPart("second")).SetContent(quit_btn);
// Start the EFL main loop
Efl.Ui.Config.Run();
// Shutdown EFL
Efl.All.Shutdown();
}
}