aboutsummaryrefslogtreecommitdiffstats
path: root/reference
diff options
context:
space:
mode:
authorXavi Artigas <xavierartigas@yahoo.es>2018-09-17 14:18:06 -0300
committerVitor Sousa <vitorsousa@expertisesolutions.com.br>2018-09-17 15:03:12 -0300
commitfce18f2ebe3dd22d817356594ee08dcd83cc3490 (patch)
tree96361993934024268d1368c89105c274946764ba /reference
parentcsharp: Remove Flush() from eina.Value examples (diff)
downloadexamples-fce18f2ebe3dd22d817356594ee08dcd83cc3490.tar.gz
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
Diffstat (limited to 'reference')
-rw-r--r--reference/csharp/ui/src/ui_container.cs158
-rw-r--r--reference/csharp/ui/src/ui_sizing.cs71
2 files changed, 125 insertions, 104 deletions
diff --git a/reference/csharp/ui/src/ui_container.cs b/reference/csharp/ui/src/ui_container.cs
index 714572d3..fe5cc976 100644
--- a/reference/csharp/ui/src/ui_container.cs
+++ b/reference/csharp/ui/src/ui_container.cs
@@ -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);
+ // 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 table;
+ return box;
}
- // 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)
+ // Create a simple table layout
+ static efl.ui.ITable CreateTable(efl.ui.IWin win)
{
- efl.ui.IBox box = new efl.ui.Box(win);
- box.SetPackPadding(5, 0, true);
+ 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)
{
- 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);
+ // Add 4 buttons, following the defined table flow
+ new efl.ui.Button(win, (efl.ui.IButton ebutton) => {
+ ebutton.SetText($"Table {i}");
+ table.DoPack(ebutton);
+ });
}
- return box;
+ // 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();
+ };
+ });
+ // 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);
});
- 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);
+ // 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.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);
+ // 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 event loop
+ // Start the EFL main loop
efl.ui.Config.Run();
+ // Shutdown EFL
efl.All.Shutdown();
}
}
+
diff --git a/reference/csharp/ui/src/ui_sizing.cs b/reference/csharp/ui/src/ui_sizing.cs
index 2f74b60e..b56cf482 100644
--- a/reference/csharp/ui/src/ui_sizing.cs
+++ b/reference/csharp/ui/src/ui_sizing.cs
@@ -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);
+ ewin.HideEvt += (object sender, EventArgs e) => {
+ // Exit the EFL main loop
+ efl.ui.Config.Exit();
+ };
});
- 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
- efl.ui.Config.Exit();
- };
-
- efl.ui.IBox box = new efl.ui.Box(win);
- win.SetContent(box);
-
- efl.ui.IButton button = new efl.ui.Button(win);
- button.SetText("Button");
- box.DoPack(button);
-
- 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);
-
- 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 box container
+ efl.ui.IBox box = new efl.ui.Box(win, (efl.ui.IBox ebox) => {
+ win.SetContent(ebox);
+ });
+
+ // Create a regular button (without size hints)
+ new efl.ui.Button(win, (efl.ui.IButton ebutton) => {
+ ebutton.SetText("Button");
+ box.DoPack(ebutton);
+ });
+
+ // 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);
+ });
+
+ // 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();
}
}