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

113 lines
3.1 KiB
C#

/*
* 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();
}
}