summaryrefslogtreecommitdiff
path: root/reference/csharp/ui
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousasilva@gmail.com>2018-02-19 16:19:01 -0300
committerVitor Sousa <vitorsousasilva@gmail.com>2018-02-19 16:32:24 -0300
commitf22bd3aa1f4106acab3a51517d552fc2c79bcd6c (patch)
treed591a6c3908f39f47d63eea2eb143c309cb26c17 /reference/csharp/ui
parentbc174ae1159bf024877b84bbfad2465ab7c9bf64 (diff)
ui_mono: add ui_content reference example for C#
Diffstat (limited to 'reference/csharp/ui')
-rw-r--r--reference/csharp/ui/src/meson.build7
-rw-r--r--reference/csharp/ui/src/ui_container.cs112
2 files changed, 119 insertions, 0 deletions
diff --git a/reference/csharp/ui/src/meson.build b/reference/csharp/ui/src/meson.build
index 3adaecf..a975e0f 100644
--- a/reference/csharp/ui/src/meson.build
+++ b/reference/csharp/ui/src/meson.build
@@ -6,3 +6,10 @@ executable('efl_reference_ui_sizing',
6 cs_args : efl_mono_libs, 6 cs_args : efl_mono_libs,
7 install : true 7 install : true
8) 8)
9
10executable('efl_reference_ui_container',
11 files(['ui_container.cs']),
12 dependencies : deps,
13 cs_args : efl_mono_libs,
14 install : true
15)
diff --git a/reference/csharp/ui/src/ui_container.cs b/reference/csharp/ui/src/ui_container.cs
new file mode 100644
index 0000000..a36a805
--- /dev/null
+++ b/reference/csharp/ui/src/ui_container.cs
@@ -0,0 +1,112 @@
1/*
2 * Efl.UI container exmaples.
3 *
4 * Load and pack a selection of containers.
5 * Each has it's own unique layout and methods which are demonstrated below.
6 */
7
8using System;
9
10public class Example
11{
12 // quit the app, called if the user clicks the Quit button or the window is hidden
13 static void GuiQuitCb(object sender, EventArgs e)
14 {
15 efl.ui.Config.Exit();
16 }
17
18 // Load a simple table layout into the window
19 static efl.ui.Table SetupUiTable(efl.ui.Win win)
20 {
21 efl.ui.Table table = new efl.ui.TableConcrete(win);
22
23 table.SetTableColumns(2);
24 table.SetTableDirection(efl.ui.Dir.Right, efl.ui.Dir.Down);
25
26 efl.ui.Button button = new efl.ui.ButtonConcrete(win);
27 button.SetText("Long Button");
28
29 table.PackTable(button, 0, 2, 2, 1);
30
31 for (int i = 1; i <= 4; ++i)
32 {
33 efl.ui.Button btn = new efl.ui.ButtonConcrete(win);
34 btn.SetText($"Table {i}");
35 table.Pack(btn);
36 }
37
38 return table;
39 }
40
41 // Load some boxes - a horizontal one for the window layout and a vertical
42 // one to contain a flow
43 static efl.ui.Box SetupUiBoxes(efl.ui.Win win)
44 {
45 efl.ui.Box box = new efl.ui.BoxConcrete(win);
46 box.SetPackPadding(5, 0, true);
47
48 for (int i = 1; i <= 4; ++i)
49 {
50 efl.ui.Button button = new efl.ui.ButtonConcrete(win);
51 button.SetText($"Boxed {i}");
52 if (i == 2)
53 {
54 eina.Size2D sz;
55 sz.W = 100;
56 sz.H = 50;
57 button.SetHintMax(sz);
58 }
59 box.Pack(button);
60 }
61
62 return box;
63 }
64
65 public static void Main()
66 {
67 efl.All.Init(efl.Components.Ui);
68
69 efl.ui.Win win = new efl.ui.WinConcrete(null, (efl.ui.Win ewin) => {
70 ewin.SetWinType(efl.ui.win.Type.Basic);
71 ewin.SetText("Hello World");
72 ewin.SetAutohide(true);
73 });
74 eina.Size2D sz;
75 sz.W = 350;
76 sz.H = 250;
77 win.SetSize(sz);
78
79 // when the user clicks "close" on a window there is a request to hide
80 win.HIDE += GuiQuitCb;
81
82 // Load a vertical and horizontal split into the window
83
84 efl.ui.Panes split = new efl.ui.PanesConcrete(win);
85 split.SetSplitRatio(0.75);
86 win.SetContent(split);
87
88 var boxes = SetupUiBoxes(win);
89 efl.ContentConcrete.static_cast(split.Part("first")).SetContent(boxes);
90
91 efl.ui.Panes horiz_split = new efl.ui.PanesConcrete(win);
92 horiz_split.SetDirection(efl.ui.Dir.Horizontal);
93 horiz_split.SetSplitRatio(0.85);
94 efl.ContentConcrete.static_cast(split.Part("second")).SetContent(horiz_split);
95
96 var table = SetupUiTable(win);
97 efl.ContentConcrete.static_cast(horiz_split.Part("first")).SetContent(table);
98
99 efl.ui.Button quit_btn = new efl.ui.ButtonConcrete(win);
100 quit_btn.SetText("Quit");
101 sz.W = 150;
102 sz.H = 30;
103 quit_btn.SetHintMax(sz);
104 quit_btn.CLICKED += GuiQuitCb;
105 efl.ContentConcrete.static_cast(horiz_split.Part("second")).SetContent(quit_btn);
106
107 // Start event loop
108 efl.ui.Config.Run();
109
110 efl.All.Shutdown();
111 }
112}