csharp: Refactor UI examples
Summary: Adapt these two UI examples to the style of the Hello World tutorials, using initialization methods, more comments, and try to avoid creating vars for widgets. Reviewers: vitor.sousa, lauromoura Reviewed By: vitor.sousa Differential Revision: https://phab.enlightenment.org/D7038
This commit is contained in:
parent
44155d8827
commit
fce18f2ebe
|
@ -1,112 +1,128 @@
|
|||
/*
|
||||
* Efl.UI container exmaples.
|
||||
* Efl.UI container examples.
|
||||
*
|
||||
* Load and pack a selection of containers.
|
||||
* Each has it's own unique layout and methods which are demonstrated below.
|
||||
* Each has its 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)
|
||||
// Create a box container full of buttons
|
||||
static efl.ui.IBox CreateBox(efl.ui.IWin win)
|
||||
{
|
||||
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);
|
||||
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)
|
||||
{
|
||||
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}");
|
||||
// Add 4 buttons, one below the other
|
||||
new efl.ui.Button(win, (efl.ui.IButton ebutton) => {
|
||||
ebutton.SetText($"Boxed {i}");
|
||||
if (i == 2)
|
||||
{
|
||||
eina.Size2D sz;
|
||||
sz.W = 100;
|
||||
sz.H = 50;
|
||||
button.SetHintMax(sz);
|
||||
// Button 2 has its maximum size limited, so it will be smaller
|
||||
ebutton.SetHintMax(new eina.Size2D(100,50));
|
||||
}
|
||||
box.DoPack(button);
|
||||
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("Hello World");
|
||||
ewin.SetText("Container demo");
|
||||
ewin.SetAutohide(true);
|
||||
ewin.HideEvt += (object sender, EventArgs e) => {
|
||||
// Exit the EFL main loop
|
||||
efl.ui.Config.Exit();
|
||||
};
|
||||
});
|
||||
eina.Size2D sz;
|
||||
sz.W = 350;
|
||||
sz.H = 250;
|
||||
win.SetSize(sz);
|
||||
// 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));
|
||||
|
||||
// when the user clicks "close" on a window there is a request to hide
|
||||
win.HideEvt += GuiQuitCb;
|
||||
// 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);
|
||||
});
|
||||
|
||||
// Load a vertical and horizontal split into the window
|
||||
// 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);
|
||||
|
||||
efl.ui.IPanes split = new efl.ui.Panes(win);
|
||||
split.SetSplitRatio(0.75);
|
||||
win.SetContent(split);
|
||||
// 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);
|
||||
|
||||
var boxes = SetupUiBoxes(win);
|
||||
efl.Content.static_cast(split.GetPart("first")).SetContent(boxes);
|
||||
// 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);
|
||||
|
||||
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);
|
||||
// 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);
|
||||
|
||||
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
|
||||
// Start the EFL main loop
|
||||
efl.ui.Config.Run();
|
||||
|
||||
// Shutdown EFL
|
||||
efl.All.Shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,57 +2,62 @@
|
|||
* Efl.UI sizing examples.
|
||||
*
|
||||
* Demonstrate how to use the sizing api from Efl.Gfx.
|
||||
* We load a box with 3 buttons, one with default sizing, one that has a max
|
||||
* and the last has a min size. Try resizing the window to see how this changes.
|
||||
* We load a box with 3 buttons, one with default sizing, one that has a max size
|
||||
* and the last one has a min size. Try resizing the window to see how this changes.
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
public class Example
|
||||
{
|
||||
#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("Size Control");
|
||||
ewin.SetAutohide(true);
|
||||
});
|
||||
eina.Size2D sz;
|
||||
sz.W = 320;
|
||||
sz.H = 320;
|
||||
win.SetSize(sz);
|
||||
|
||||
// when the user clicks "close" on a window there is a request to hide
|
||||
win.HideEvt += (object sender, EventArgs e) => {
|
||||
// quit the app, called if the window is hidden
|
||||
ewin.HideEvt += (object sender, EventArgs e) => {
|
||||
// Exit the EFL main loop
|
||||
efl.ui.Config.Exit();
|
||||
};
|
||||
});
|
||||
|
||||
efl.ui.IBox box = new efl.ui.Box(win);
|
||||
win.SetContent(box);
|
||||
// Create a box container
|
||||
efl.ui.IBox box = new efl.ui.Box(win, (efl.ui.IBox ebox) => {
|
||||
win.SetContent(ebox);
|
||||
});
|
||||
|
||||
efl.ui.IButton button = new efl.ui.Button(win);
|
||||
button.SetText("Button");
|
||||
box.DoPack(button);
|
||||
// Create a regular button (without size hints)
|
||||
new efl.ui.Button(win, (efl.ui.IButton ebutton) => {
|
||||
ebutton.SetText("Button");
|
||||
box.DoPack(ebutton);
|
||||
});
|
||||
|
||||
efl.ui.IButton small_btn = new efl.ui.Button(win);
|
||||
small_btn.SetText("Small");
|
||||
sz.W = 50;
|
||||
sz.H = 50;
|
||||
small_btn.SetHintMax(sz);
|
||||
box.DoPack(small_btn);
|
||||
// Create a small button (max size is limited)
|
||||
new efl.ui.Button(win, (efl.ui.IButton ebutton) => {
|
||||
ebutton.SetText("Small");
|
||||
ebutton.SetHintMax(new eina.Size2D(50,50));
|
||||
box.DoPack(ebutton);
|
||||
});
|
||||
|
||||
efl.ui.IButton big_btn = new efl.ui.Button(win);
|
||||
big_btn.SetText("Big Button");
|
||||
sz.W = 100;
|
||||
sz.H = 100;
|
||||
big_btn.SetHintMin(sz);
|
||||
box.DoPack(big_btn);
|
||||
// Create a big button (min size is limited)
|
||||
new efl.ui.Button(win, (efl.ui.IButton ebutton) => {
|
||||
ebutton.SetText("Big button");
|
||||
ebutton.SetHintMin(new eina.Size2D(100,100));
|
||||
box.DoPack(ebutton);
|
||||
});
|
||||
|
||||
// Start the EFL main loop
|
||||
efl.ui.Config.Run();
|
||||
|
||||
// Shutdown EFL
|
||||
efl.All.Shutdown();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue