summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavi Artigas <xavierartigas@yahoo.es>2018-07-25 02:17:21 -0700
committerapache <apache@e5-web1.enlightenment.org>2018-07-25 02:17:21 -0700
commit968d91f3298eb0ed218593f907c96beb311190bb (patch)
treeba2f48d8b367cd502391d504053b66443928c7d7
parentb6b586140eb26de40d18c0173697e796cce2d2a0 (diff)
Wiki page start.md changed with summary [Put C# in proper place] by Xavi Artigas
-rw-r--r--pages/develop/setup/csharp/start.md.txt231
1 files changed, 231 insertions, 0 deletions
diff --git a/pages/develop/setup/csharp/start.md.txt b/pages/develop/setup/csharp/start.md.txt
new file mode 100644
index 000000000..4704248e4
--- /dev/null
+++ b/pages/develop/setup/csharp/start.md.txt
@@ -0,0 +1,231 @@
1~~Title: C# Tutorial~~
2===== C# Tutorial =====
3
4This tutorial shows how to compile and install the Enlightenment Foundation Libraries (EFL) with C# bindings support, and some examples of how to use it.
5
6<note important>
7The C# bindings are currently in BETA state.
8</note>
9
10==== Getting Started ====
11
12=== Prerequisite ===
13
14Before you start you may want to read about how to compile the EFL:
15
16 * Installed from source: [[docs/distros/start]].
17
18=== Dependencies ===
19
20== On Linux ==
21
22You need a compatible version of [[http://www.mono-project.com/download/stable/|Mono]] (5.0 or higher).
23
24<note important>
25The current version of the bindings do not work with Mono 4.x.
26</note>
27
28The paths to the ''mcs'' compiler and to the ''mono'' application must be in the ''PATH'' environment variable before compiling.
29
30Once all conditions are met proceed to [[#Compilation]].
31
32Ubunut
33
34== On Windows ==
35
36In order to have EFL on a Windows environment we highly recommend following [[https://phab.enlightenment.org/w/windows/|this guide]] which accomplishes that using [[http://win-builds.org|win-builds]] and [[http://www.msys2.org/|MSYS2]].
37
38You need a compatible version of [[http://www.mono-project.com|Mono]] (4.0 or higher).
39You can use Mono binaries installed directly to your Windows system (i.e. outside the MSYS2 environment), you just need to make sure that the paths to the ''mcs.exe'' compiler and to the ''mono.exe'' application are in the ''PATH'' environment variable in your MSYS2 terminal.
40Using the default installation path, Mono binaries normally goes in ''C:\Program Files\Mono''; so in MSYS2 you can point to the binaries using the path ''/c/Program Files/Mono/bin''.
41You can also permanently set this in your ''/etc/profile'' in MSYS2 adding something like this at the end of the file:
42<code bash>
43export PATH="$PATH:/c/Program Files/Mono/bin"
44</code>
45If you used another installation path to Mono just adjust the paths used.
46
47<note important>
48It is advisable to add the Mono path at the **end** of the ''PATH'' environment variable, like in the example above.
49Mono has its own version of some applications (like ''pkg-config'') which can take priority over the ones from MSYS2 and cause things to fail.
50</note>
51
52Now you can use the MSYS2 console to compile, install and run EFL and your applications.
53Once all conditions are met proceed to [[#Compilation]].
54
55=== Compiling and Installing ===
56
57In order to compile and install EFL with C# binding support, in both Windows and Linux just compile the EFL like the respective guide suggests, only add the argument ''--enable-csharp-bindings'' to the ''autogen.sh'' or ''configure'' command.
58Like:
59<code bash>
60./autogen.sh --enable-csharp-bindings #other arguments
61make -j4
62sudo make install
63</code>
64
65<note>
66It is known that some tutorials can get a bit outdated from time to time, causing the building process to fail, usually because of a missing dependency.
67Normally reading the error message and installing the missing package solves the problem.
68If you can not solve the problem by yourself, try [[/contact|contacting]] the community.
69</note>
70
71==== Examples ====
72
73Now that you can compile and install EFL with C# bindings lets see some code examples.
74
75=== Button Example ===
76
77Lets start with a very simple example that just creates a window with a button and show how to compile it.
78After, the code will be explained.
79
80<note tip>
81You can find this example in ''<efl_source>/src/examples/elementary/button_example_00.cs''
82</note>
83
84The code:
85<code csharp>
86using System;
87
88public class Example
89{
90#if WIN32
91 [STAThreadAttribute()]
92#endif
93 public static void Main()
94 {
95 efl.All.Init(efl.Components.Ui);
96
97 efl.ui.IWin win = new efl.ui.Win(null);
98 win.SetText("Hello, World!");
99 win.SetAutohide(true);
100 //win.SetSize(240, 60);
101 win.SetSize(new eina.Size2D(240, 60));
102 win.SetVisible(true);
103
104 efl.ui.IButton btn = new efl.ui.Button(win);
105 btn.SetText("Good-Bye, World!");
106 //btn.SetSize(120, 30);
107 btn.SetSize(new eina.Size2D(120, 30));
108 eina.Position2D pos;
109 pos.X = 60;
110 pos.Y = 15;
111 btn.SetPosition(pos);
112 btn.SetVisible(true);
113 btn.ClickedEvt += (object sender, EventArgs e) => {
114 efl.ui.Config.Exit();
115 };
116
117 efl.ui.Config.Run();
118
119 efl.All.Shutdown();
120 }
121}
122</code>
123
124== Compiling and running ==
125
126If you have EFL installed you can compile the example using ''pkg-config'' to get the proper flags for using the C# binding:
127<code bash>
128mcs button_example_00.cs -out:button_example_00.exe `pkg-config --libs efl-mono`
129</code>
130
131Otherwise, you have to point the library location manually, like:
132<code bash>
133mcs button_example_00.cs -out:button_example_00.exe -r:/home/my_user/efl/build/src/lib/efl_mono/libefl_mono.dll
134</code>
135
136To run the application you can either copy the EFL C# binding library to your folder or set the ''MONO_PATH'' environment variable, them execute it using ''mono''.
137In both cases, you can use ''pkg-config'' to get the right paths.
138
139Example coping the library:
140<code bash>
141cp `pkg-config --variable=Libraries efl-mono` .
142mono button_example_00.exe
143</code>
144
145Example setting ''MONO_PATH'':
146<code bash>
147export MONO_PATH=`pkg-config --variable=assemblies_dir efl-mono`
148mono button_example_00.exe
149</code>
150
151Note that if you installed EFL in a path that is not directly accessible to ''pkg-config'' or to your application you have to manually make it accessible someway,
152for example setting proper environment variables before compiling and running:
153<code bash>
154export PKG_CONFIG_PATH=/opt/my_install_prefix/lib/pkgconfig
155export LD_LIBRARY_PATH=/opt/my_install_prefix/lib
156</code>
157
158== Explaining the code ==
159
160First, we start with a basic class structure to define our ''Main'' entry point:
161<code csharp>
162using System;
163
164public class Example
165{
166#if WIN32
167 [STAThreadAttribute()]
168#endif
169 public static void Main()
170 {
171 // <code goes here>
172 }
173}
174</code>
175<note important>
176The ''STAThreadAttribute'' is currently necessary in Windows systems because of limitations in ''ecore_win32''.
177You can compile passing ''-define:WIN32'' to ''mcs'' to flag when you are compiling on a Windows system.
178</note>
179
180Then we initialize EFL with Ui components enabled:
181<code csharp>
182 efl.All.Init(efl.Components.Ui);
183</code>
184
185And create a new Window with auto-hide (the window is automatically hidden when the close button is clicked), set its title, give it a dimension and turn it visible:
186<code csharp>
187 efl.ui.IWin win = new efl.ui.Win(null);
188 win.SetText("Hello, World!");
189 win.SetAutohide(true);
190 //win.SetSize(240, 60);
191 win.SetSize(new eina.Size2D(240, 60));
192 win.SetVisible(true);
193</code>
194
195Create a new Button (passing the newly created window as the parent), set new label text to the button, give it a dimension and position and turn it visible:
196<code csharp>
197 efl.ui.IButton btn = new efl.ui.Button(win);
198 btn.SetText("Good-Bye, World!");
199 //btn.SetSize(120, 30);
200 btn.SetSize(new eina.Size2D(120, 30));
201 eina.Position2D pos;
202 pos.X = 60;
203 pos.Y = 15;
204 btn.SetPosition(pos);
205 btn.SetVisible(true);
206</code>
207
208And then register a function to the button ''CLICKED'' event:
209<code csharp>
210 btn.ClickedEvt += (object sender, EventArgs e) => {
211 efl.ui.Config.Exit();
212 };
213</code>
214We use a simple lambda that calls a function to end the event loop, exiting ''efl.ui.Config.Run()'' and finishing the application.
215
216Once the setup is finished, we call:
217<code csharp>
218 efl.ui.Config.Run();
219</code>
220It starts the event loop and display the application main window.
221
222After the event loop is finished (when closing the last window or by calling ''efl.ui.Config.Exit()'') we shut down the EFL components and let the application end:
223<code csharp>
224 efl.All.Shutdown();
225</code>
226
227And this concludes the basic button example.
228
229=== Efl.Ui.List and Efl.Model Example ===
230
231WIP \ No newline at end of file