summaryrefslogtreecommitdiff
path: root/pages/develop/legacy/tutorial
diff options
context:
space:
mode:
authorVitor Sousa da Silva <vitorsousasilva@gmail.com>2018-01-30 04:21:38 -0800
committerapache <apache@e5-web1.enlightenment.org>2018-01-30 04:21:38 -0800
commit5b0249fef676f3587a87e0864c1e0cd8487de14f (patch)
tree65fea92d80ad7aecb1b41f5b7864286d8e299918 /pages/develop/legacy/tutorial
parent820db66422d48145bec167fea60b7893555befc2 (diff)
Wiki page csharp_tutorial changed with summary [] by Vitor Sousa da Silva
Diffstat (limited to 'pages/develop/legacy/tutorial')
-rw-r--r--pages/develop/legacy/tutorial/csharp_tutorial.txt167
1 files changed, 161 insertions, 6 deletions
diff --git a/pages/develop/legacy/tutorial/csharp_tutorial.txt b/pages/develop/legacy/tutorial/csharp_tutorial.txt
index db7535e6c..0e1779010 100644
--- a/pages/develop/legacy/tutorial/csharp_tutorial.txt
+++ b/pages/develop/legacy/tutorial/csharp_tutorial.txt
@@ -1,8 +1,6 @@
1~~Title: C# Tutorial~~ 1~~Title: C# Tutorial~~
2===== C# Tutorial ===== 2===== C# Tutorial =====
3 3
4WIP
5
6<note important> 4<note important>
7The C# bindings are currently in BETA state. 5The C# bindings are currently in BETA state.
8</note> 6</note>
@@ -22,7 +20,7 @@ Before you start you may want to read about how to compile the EFL:
22You will need a compatible version of [[http://www.mono-project.com|Mono]] (4.0 or higher). 20You will need a compatible version of [[http://www.mono-project.com|Mono]] (4.0 or higher).
23The paths to the ''mcs'' compiler and to the ''mono'' application must be in the ''PATH'' environment variable before compiling. 21The paths to the ''mcs'' compiler and to the ''mono'' application must be in the ''PATH'' environment variable before compiling.
24 22
25Once all conditions are met proceed to [[#Compilation|Compilation]]. 23Once all conditions are met proceed to [[#Compilation]].
26 24
27== Windows == 25== Windows ==
28 26
@@ -32,16 +30,173 @@ You will need a compatible version of [[http://www.mono-project.com|Mono]] (4.0
32You can use Mono binaries installed directly to your Windows system (i.e. outside the MSYS2 environment), you will 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. 30You can use Mono binaries installed directly to your Windows system (i.e. outside the MSYS2 environment), you will 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.
33Using 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''. 31Using 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''.
34You can also permanently set this in your ''/etc/profile'' in MSYS2 adding something like this at the end of the file: 32You can also permanently set this in your ''/etc/profile'' in MSYS2 adding something like this at the end of the file:
35<code> 33<code bash>
36export PATH="$PATH:/c/Program Files/Mono/bin" 34export PATH="$PATH:/c/Program Files/Mono/bin"
37</code> 35</code>
38If you used another installation path to Mono just adjust the paths used. 36If you used another installation path to Mono just adjust the paths used.
39 37
38Now you can use the MSYS2 console to compile, install and run EFL and your applications.
40Once all conditions are met proceed to [[#Compilation]]. 39Once all conditions are met proceed to [[#Compilation]].
41 40
42=== Compilation === 41=== Compilation ===
43 42
44In both Windows and Linux environments just 43In order to compile 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.
44Like:
45<code bash>
46./autogen.sh --enable-csharp-bindings #other arguments
47make -j4
48sudo make install
49</code>
50
51
52==== Examples ====
53
54Now that you can compile and install EFL with the C# bindings lets see some code examples.
55
56=== Button Example ===
57
58Lets star with a very simple example that just creates a window with a button and show how to compile it.
59After we will explain the code.
60
61<note tip>
62You can find this example in ''<efl_source>/src/examples/elementary/button_example_00.cs''
63</note>
64
65The code:
66<code csharp>
67using System;
68
69public class Example
70{
71#if WIN32
72 [STAThreadAttribute()]
73#endif
74 public static void Main()
75 {
76 efl.All.Init(efl.Components.Ui);
77
78 efl.ui.Win win = new efl.ui.WinConcrete(null);
79 win.SetText("Hello, World!");
80 win.SetAutohide(true);
81 win.SetSize(240, 60);
82 win.SetVisible(true);
83
84 efl.ui.Button btn = new efl.ui.ButtonConcrete(win);
85 btn.SetText("Good-Bye, World!");
86 btn.SetSize(120, 30);
87 eina.Position2D pos;
88 pos.X = 60;
89 pos.Y = 15;
90 btn.SetPosition(pos);
91 btn.SetVisible(true);
92 btn.CLICKED += (object sender, EventArgs e) => {
93 efl.ui.Config.Exit();
94 };
95
96 efl.ui.Config.Run();
97
98 efl.All.Shutdown();
99 }
100}
101</code>
102
103== Compiling and running ==
104
105If you have EFL installed you can compile the example using ''pkg-config'' to get the proper flags for using the C# binding:
106<code bash>
107mcs button_example_00.cs -out:button_example_00.exe `pkg-config --libs efl-mono`
108</code>
109
110Otherwise, you will have to point the library location manually, like:
111<code bash>
112mcs button_example_00.cs -out:button_example_00.exe -r:/home/my_user/efl/build/src/lib/efl_mono/libefl_mono.dll
113</code>
45 114
115To 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''.
116In both cases you can use ''pkg-config'' to get the right paths.
117
118Example coping the library:
119<code bash>
120cp `pkg-config --variable=Libraries efl-mono` .
121mono button_example_00.exe
122</code>
46 123
47==== Example ==== \ No newline at end of file 124Example setting ''MONO_PATH'':
125<code bash>
126export MONO_PATH=`pkg-config --variable=assemblies_dir efl-mono`
127mono button_example_00.exe
128</code>
129
130Note that if you installed EFL in a path that is not directly accessible to ''pkg-config'' or to your application you will have to manually make it accessible someway,
131for example setting proper environment variables:
132<code bash>
133export PKG_CONFIG_PATH=/opt/my_install_prefix/lib/pkgconfig
134export LD_LIBRARY_PATH=/opt/my_install_prefix/lib
135</code>
136
137== Explaining the code ==
138
139First we start with s basic class structure to define our ''Main'' entry point:
140<code csharp>
141using System;
142
143public class Example
144{
145#if WIN32
146 [STAThreadAttribute()]
147#endif
148 public static void Main()
149 {
150 // <code goes here>
151 }
152}
153</code>
154<note important>
155The ''STAThreadAttribute'' is currently necessary in Windows systems because of limitations in ''ecore_win32''.
156You can compile passing ''-define:WIN32'' to ''mcs'' to flag when you are compiling on a Windows system.
157</note>
158
159Then we initialize EFL with Ui components enabled:
160<code csharp>
161 efl.All.Init(efl.Components.Ui);
162<code>
163
164Create 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:
165<code csharp>
166 efl.ui.Win win = new efl.ui.WinConcrete(null);
167 win.SetText("Hello, World!");
168 win.SetAutohide(true);
169 win.SetSize(240, 60);
170 win.SetVisible(true);
171<code>
172
173Create a new Button (passing the newly created window as parent), set new label text to the button, give it a dimension and position and turn it visible:
174<code csharp>
175 efl.ui.Button btn = new efl.ui.ButtonConcrete(win);
176 btn.SetText("Good-Bye, World!");
177 btn.SetSize(120, 30);
178 eina.Position2D pos;
179 pos.X = 60;
180 pos.Y = 15;
181 btn.SetPosition(pos);
182 btn.SetVisible(true);
183</code>
184
185Register a function to the button ''CLICKED'' event:
186<code csharp>
187 btn.CLICKED += (object sender, EventArgs e) => {
188 efl.ui.Config.Exit();
189 };
190</code>
191We use a simple lambda that calls a function to end the event loop, exiting ''efl.ui.Config.Run()'' and finishing the application.
192
193Once the setup is finished, we call:
194<code csharp>
195 efl.ui.Config.Run();
196</code>
197It will start the event loop and display the application main window.
198
199After the event loop is finished (when closing the last window or by calling ''efl.ui.Config.Exit()'') we shutdown the EFL components and let the application end:
200<code csharp>
201 efl.All.Shutdown();
202</code>