summaryrefslogtreecommitdiff
path: root/pages/develop/tutorials
diff options
context:
space:
mode:
authorXavi Artigas <xavierartigas@yahoo.es>2018-08-24 01:41:02 -0700
committerapache <apache@e5-web1.enlightenment.org>2018-08-24 01:41:02 -0700
commit98ea1bb4069ac0714fcbf987bfbbf3a72946746e (patch)
tree6fd5ad386f7ef789693a4b3ff1d9cb45485d831a /pages/develop/tutorials
parent9f298a3b263da75a77fdba6c0ce08bfd01562518 (diff)
Wiki page hello-world-cs.md changed with summary [created] by Xavi Artigas
Diffstat (limited to 'pages/develop/tutorials')
-rw-r--r--pages/develop/tutorials/csharp/hello-world-cs.md.txt185
1 files changed, 185 insertions, 0 deletions
diff --git a/pages/develop/tutorials/csharp/hello-world-cs.md.txt b/pages/develop/tutorials/csharp/hello-world-cs.md.txt
new file mode 100644
index 000000000..4eba59d28
--- /dev/null
+++ b/pages/develop/tutorials/csharp/hello-world-cs.md.txt
@@ -0,0 +1,185 @@
1---
2~~Title: "Hello World" in C#~~
3~~NOCACHE~~
4---
5
6# "Hello World" in C# #
7
8This first tutorial ensures that your EFL installation is ready to produce C# applications and demonstrates the first basic EFL concepts.
9
10| | WARNING | |
11| --- | ------- | --- |
12| ![NOTE](/_media/note-important.png) | **The C# bindings are currently in BETA state**<br>They should only be used for experimenting and **NOT** for any product development.<br>The source code for the tutorials is subject to change in the future. | ![NOTE](/_media/note-important.png) |
13
14## Prerequisites ##
15
16* Read the [Setting Up a C# Development Environment](/develop/setup/csharp/) guide so you have a working EFL installation with C# support.
17
18## Hello World ##
19
20Copy the code below into a file named ``hello-world.cs`` (The walkthrough is in the following section).
21
22```csharp
23using System;
24
25public class Example
26{
27#if WIN32
28 [STAThreadAttribute()]
29#endif
30 public static void Main()
31 {
32 // Initialize EFL and all UI components
33 efl.All.Init(efl.Components.Ui);
34
35 // Create a window and initialize it
36 efl.ui.IWin win = new efl.ui.Win(null, (efl.ui.IWin ewin) => {
37 // Set the window's title
38 ewin.SetText("Hello World");
39 // Request that the window is automatically hidden when the "close"
40 // button is pressed
41 ewin.SetAutohide(true);
42 });
43 // Window size must be explicitly set, otherwise it will be invisible
44 // due to its lack of content.
45 win.SetSize(new eina.Size2D(360, 240));
46
47 // Start the EFL main loop
48 efl.ui.Config.Run();
49
50 // Shutdown EFL
51 efl.All.Shutdown();
52 }
53}
54```
55
56Compile it as explained in the [Setting Up a C# Development Environment](/develop/setup/csharp/) guide and run the executable. If everything worked according to plan, you should see an empty window like this:
57
58![Full application with text box and button](https://www.enlightenment.org/_media/playground/03-hello-world-gui/image02.png)
59
60## Walkthrough ##
61
62### Main ###
63
64The program starts with a simple class structure to define the ``Main`` entry point:
65
66```csharp
67using System;
68
69public class Example
70{
71#if WIN32
72 [STAThreadAttribute()]
73#endif
74 public static void Main()
75 {
76 [...]
77 }
78}
79```
80
81> **NOTE**:
82> The ``STAThreadAttribute`` is currently necessary in Windows systems because of limitations in the ``ecore_win32`` internal library of EFL. You can compile passing ``-define:WIN32`` to ``mcs`` to indicate that you are compiling on a Windows system.
83
84### EFL Initialization ###
85
86EFL is initialized with the `efl.All.Init()` method:
87
88```csharp
89 // Initialize EFL and all UI components
90 efl.All.Init(efl.Components.Ui);
91```
92
93It accepts a parameter specifying which EFL components your app will require. This enables faster boot times and better resource usage by not loading and starting unnecessary components.
94
95The only currently available options are `efl.Components.Basic` and `efl.Components.Ui`. When not specified, `Basic` is assumed.
96
97### Creating the Window ###
98
99All EFL objects, like Windows, Widgets or Timers, are created using the standard `new` operator, for example:
100
101```csharp
102var win = new efl.ui.Win();
103```
104
105However, EFL object constructors have two optional parameters which are worth knowing:
106
107* `parent`: Any EFL object can be the child of another EFL object (its parent). Parents will take care of disposing of all their children upon destruction, greatly simplifying object lifecycle management.
108* `initialization method`: This is a delegate method accepting an object of the class being instantiated (see the example below). This method will be called during construction to allow you to customize the EFL object being created.
109
110 The advantage over first creating and then customizing the object is that, in most cases, you won't even need to keep the object in a variable: just create it with a parent, customize it, and forget about it.
111
112In the tutorial code:
113
114```csharp
115 // Create a window and initialize it
116 efl.ui.IWin win = new efl.ui.Win(null, (efl.ui.IWin ewin) => {
117 // Set the window's title
118 ewin.SetText("Hello World");
119 // Request that the window is automatically hidden when the "close"
120 // button is pressed
121 ewin.SetAutohide(true);
122 });
123```
124
125Observe how the window is created with a `null` parent and the initialization method is a lambda function which:
126
127* Sets the window title to `Hello World`.
128* Sets the `autohide` flag to true. This means that the window will automatically be hidden when the user closes it. The default behavior for an app when all its windows are hidden is to quit.
129
130### The Window Size ###
131
132By default, windows adjust themselves to have the minimum size that allows displaying all their content. In this tutorial the window has no content at all, so its size will be 0 pixels wide and 0 pixels tall.
133
134The next tutorial adds some content to the window, but meanwhile, you can manually set the size of a window:
135
136```csharp
137 // Window size must be explicitly set, otherwise it will be invisible
138 // due to its lack of content.
139 win.SetSize(new eina.Size2D(360, 240));
140```
141
142> **NOTE:**
143> You could have done this in the initialization method described above, but setting the size of a window during its construction has some issues at this moment (See [T7343](https://phab.enlightenment.org/T7343)).
144
145### Starting Up the User Interface ###
146
147Now that all the required EFL objects have been created (only a window, actually), it's time to relinquish control to EFL.
148
149```csharp
150 // Start the EFL main loop
151 efl.ui.Config.Run();
152```
153
154This method does not return until EFL exits. In any application you will set callback methods that EFL will use to inform you of some events, and you will plug more code on those methods.
155
156The following tutorials show how to do that. For this one, the only remaining thing is:
157
158### Shutting Down ###
159
160```csharp
161 // Shutdown EFL
162 efl.All.Shutdown();
163```
164
165Always remember to shut down EFL to close windows, network connections and free resources.
166
167## Summary
168
169In this tutorial you have learned:
170
171* How to properly initialize and shutdown the EFL library with `efl.All.Init()` and `efl.All.Shutdown()`.
172* How to create and initialize EFL objects using `new` and `initialization methods`.
173* How to instantiate an EFL window and customize it using the `efl.ui.Win` class.
174* How to start the UI by giving control to EFL with `efl.ui.Config.Run()`.
175
176The following tutorial adds some text and a button to the UI, and shows how to react to a button press.
177
178
179## Resources ##
180
181[Setting Up a C# Development Environment](/develop/setup/csharp/)
182: Instructions for having EFL ready to work from C#.
183
184[Tutorial Code Examples](https://git.enlightenment.org/tools/examples.git/tree/tutorial/csharp)
185: C# Source code for the tutorials. \ No newline at end of file