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

129 lines
4.3 KiB
C#

/*
* 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.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) => {
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.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}");
table.DoPack(ebutton);
});
}
// Last button spans two table cells
new efl.ui.Button(win, (efl.ui.IButton 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.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 = 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 = CreateTable(win);
efl.Content.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.IButton quit_btn = new efl.ui.Button(win, (efl.ui.IButton 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.Content.static_cast(hsplit.GetPart("second")).SetContent(quit_btn);
// Start the EFL main loop
efl.ui.Config.Run();
// Shutdown EFL
efl.All.Shutdown();
}
}