<p>I will use for all test a basic template <ahref="http://atria-soft.github.io/elog">elog</a> for debug logger that redirect logs in Android and IOs</p>
<p>A generic Ewol application is manage by creating an <aclass="el"href="classewol_1_1context_1_1_application.html">ewol::context::Application</a> that is the basis of your application.</p>
<p>Due to the fact the ewol library is a multi-platform framework (base on <ahref="http://atria-soft.github.io/gale">GALE</a>), you will have many contraint like:</p><ul>
<li>One application at the same time (note an exception for android wallpaper)</li>
<li>One Windows displayable at the time (main point of view of apple developpers)</li>
<li>Not a big CPU ...</li>
</ul>
<p>Then we will create the application:</p>
<p>First things: Some includes:</p>
<divclass="fragment"><divclass="line"><spanclass="preprocessor">#include <<aclass="codeRef"doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/"href="http://atria-soft.github.io/etk/types__8hpp.html">etk/types.hpp</a>></span></div><divclass="line"><spanclass="preprocessor">#include <<aclass="code"href="ewol_8hpp.html">ewol/ewol.hpp</a>></span></div><divclass="line"><spanclass="preprocessor">#include <gale/context/commandLine.hpp></span></div></div><!-- fragment --><p> Declare the application:</p>
<divclass="fragment"><divclass="line">It is important to know that the system can create your application multiple times, the basic example of this is the Wallpaper on Android.</div><divclass="line"></div><divclass="line">What is done:</div><divclass="line"> - When we select the wallpaper it create a new application (to show an example)</div><divclass="line"> - When applying your choice, it create the real one an remove the previous one.</div></div><!-- fragment --><p>In all program we need to have a main()</p>
<p>To be portable on Android, the "main" in the java might call your main through the Android wrapper.</p>
<p>To simplify compabilities between platform it is recommanded to not add other things in the application main:</p>
<divclass="fragment"><divclass="line"></div><divclass="line"><spanclass="keywordtype">int</span> main(<spanclass="keywordtype">int</span> _argc, <spanclass="keyword">const</span><spanclass="keywordtype">char</span> *_argv[]) {</div><divclass="line"><spanclass="comment">// second possibility</span></div><divclass="line"><spanclass="keywordflow">return</span><aclass="code"href="ewol_8hpp.html#a6f0683bb3c85a81f0f61b85971e6bf8b">ewol::run</a>(<spanclass="keyword">new</span> appl::MainApplication(), _argc, _argv);</div><divclass="line">}</div></div><!-- fragment --><h2><aclass="anchor"id="ewol_tutorial_hello_world_sources_config"></a>
Some configuration are needed </h2>
<p>In your application you can use many configuration, it is really better to set all your configuration dynamic. With this basic condition will simplify the interface of the library if you would have many different application (never forget the compilator garbage collector is really very efficient).</p>
<p>All of this will be done one time: Then we will do it in:</p>
<p>All the argument is store in the ewol main application context: just get it...</p>
<divclass="fragment"><divclass="line"><spanclass="comment">// parse all the argument of the application</span></div><divclass="line"><spanclass="keywordflow">for</span> (int32_t iii=0 ; iii<_context.getCmd().size(); iii++) {</div><divclass="line"> std::string tmpppp = _context.getCmd().get(iii);</div><divclass="line"><spanclass="keywordflow">if</span> ( tmpppp == <spanclass="stringliteral">"-h"</span></div><divclass="line"> || tmpppp == <spanclass="stringliteral">"--help"</span>) {</div><divclass="line"> APPL_INFO(<spanclass="stringliteral">" -h/--help display this help"</span> );</div><divclass="line"> exit(0);</div><divclass="line"> }</div><divclass="line"> }</div></div><!-- fragment --><h3>Set basic windosw size (for desktop):</h3>
<p>On descktop you can specify a start windows size:</p>
<divclass="fragment"><divclass="line"><spanclass="comment">// TODO : Remove this: Move if in the windows properties</span></div><divclass="line"> _context.setSize(<aclass="codeRef"doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/"href="http://atria-soft.github.io/etk/classetk_1_1_vector2_d.html">vec2</a>(800, 600));</div></div><!-- fragment --><h3>Select fonts:</h3>
<p>This can be a problem when you design an application for some other operating system (OS), They do not have the same default fonts, than you can embended some of them or try to use the system fonts.</p>
<p>We select an order to search the font names and the system basic size.</p>
<divclass="fragment"><divclass="line"><spanclass="comment">// eneble the search of the font in the system font path</span></div><divclass="line"> _context.getFontDefault().setUseExternal(<spanclass="keyword">true</span>);</div><divclass="line"><spanclass="comment">// select font preference of der with a basic application size</span></div><divclass="line"> _context.getFontDefault().set(<spanclass="stringliteral">"FreeSerif;DejaVuSansMono"</span>, 19);</div></div><!-- fragment --><h2><aclass="anchor"id="ewol_tutorial_hello_world_sources_windows"></a>
Main Windows: </h2>
<p>Create the main Windows:</p>
<p>For this point we will create a class that herited form the basic <aclass="el"href="classewol_1_1widget_1_1_windows.html"title="Windows basic interface. ">ewol::widget::Windows</a> class:</p>
<divclass="fragment"><divclass="line"></div><divclass="line"><spanclass="preprocessor">#pragma once</span></div><divclass="line"></div><divclass="line"><spanclass="preprocessor">#include <<aclass="code"href="_windows_8hpp.html">ewol/widget/Windows.hpp</a>></span></div><divclass="line"></div><divclass="line"><spanclass="keyword">namespace </span>appl {</div><divclass="line"><spanclass="keyword">class </span>Windows;</div><divclass="line"><spanclass="keyword">using</span> WindowsShared = <aclass="codeRef"doxygen="/home/heero/dev/perso/out/doc/release/ememory.tag:http://atria-soft.github.io/ememory/"href="http://atria-soft.github.io/ememory/classememory_1_1_shared_ptr.html">ememory::SharedPtr<appl::Windows></a>;</div><divclass="line"><spanclass="keyword">using</span> WindowsWeak = <aclass="codeRef"doxygen="/home/heero/dev/perso/out/doc/release/ememory.tag:http://atria-soft.github.io/ememory/"href="http://atria-soft.github.io/ememory/classememory_1_1_weak_ptr.html">ememory::WeakPtr<appl::Windows></a>;</div><divclass="line"><spanclass="keyword">class </span>Windows : <spanclass="keyword">public</span><aclass="code"href="classewol_1_1widget_1_1_windows.html">ewol::widget::Windows</a> {</div><divclass="line"><spanclass="keyword">protected</span>:</div><divclass="line"> Windows();</div><divclass="line"><spanclass="keywordtype">void</span><aclass="codeRef"doxygen="/home/heero/dev/perso/out/doc/release/elog.tag:http://atria-soft.github.io/elog/"href="http://atria-soft.github.io/elog/namespaceelog.html#a1005ac82c94e09b499d29b70a98cd5cc">init</a>();</div><divclass="line"><spanclass="keyword">public</span>:</div><divclass="line"> DECLARE_FACTORY(Windows);</div><divclass="line"> };</div><divclass="line">}</div><divclass="line"></div></div><!-- fragment --><p>The C macro "DECLARE_FACTORY" create a simple factory function "create" that return the <aclass="el"href="classewol_1_1_object.html"title="Basic message classes for ewol system this class mermit at every Object to communicate between them...">ewol::Object</a> well create.</p>
<p>For some internal reason, we create the object and we call the "init" function after creating the object. When well done we return the shared object created.</p>
<p>See <aclass="el"href="ewol_tutorial_object_model.html">EWOL: Object model</a> to understand why this structure is so complex.</p>
<divclass="fragment"><divclass="line"></div><divclass="line"><spanclass="preprocessor">#include <<aclass="code"href="ewol_8hpp.html">ewol/ewol.hpp</a>></span></div><divclass="line"><spanclass="preprocessor">#include <appl/debug.hpp></span></div><divclass="line"><spanclass="preprocessor">#include <appl/Windows.hpp></span></div><divclass="line"><spanclass="preprocessor">#include <<aclass="code"href="_label_8hpp.html">ewol/widget/Label.hpp</a>></span></div><divclass="line"></div><divclass="line">appl::Windows::Windows() {</div><divclass="line"> addObjectType(<spanclass="stringliteral">"appl::Windows"</span>);</div><divclass="line"> propertyTitle.setDirectCheck(std::string(<spanclass="stringliteral">"sample "</span>) + PROJECT_NAME);</div><divclass="line">}</div><divclass="line"></div><divclass="line"><spanclass="keywordtype">void</span> appl::Windows::init() {</div><divclass="line"> ewol::widget::Windows::init();</div><divclass="line"><aclass="codeRef"doxygen="/home/heero/dev/perso/out/doc/release/ememory.tag:http://atria-soft.github.io/ememory/"href="http://atria-soft.github.io/ememory/classememory_1_1_shared_ptr.html">ewol::widget::LabelShared</a> tmpWidget = ewol::widget::Label::create();</div><divclass="line"><spanclass="keywordflow">if</span> (tmpWidget == <spanclass="keyword">nullptr</span>) {</div><divclass="line"> APPL_ERROR(<spanclass="stringliteral">"Can not allocate widget ==> display might be in error"</span>);</div><divclass="line"> } <spanclass="keywordflow">else</span> {</div><divclass="line"> tmpWidget-><aclass="code"href="classewol_1_1widget_1_1_label.html#a9d6420ddec78c0d1abea850a79b4577a">propertyValue</a>.<aclass="codeRef"doxygen="/home/heero/dev/perso/out/doc/release/eproperty.tag:http://atria-soft.github.io/eproperty/"href="http://atria-soft.github.io/eproperty/classeproperty_1_1_property_type.html#a29dd42486e15d92b9ea94d30e99854e1">set</a>(<spanclass="stringliteral">"Hello <font color='blue'>World</font>"</span>);</div><divclass="line"> tmpWidget-><aclass="code"href="classewol_1_1_widget.html#a3bc497e98895d8fcfcc130cd072853f0">propertyExpand</a>.set(<aclass="codeRef"doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/"href="http://atria-soft.github.io/etk/classetk_1_1_vector2_d.html">bvec2</a>(<spanclass="keyword">true</span>,<spanclass="keyword">true</span>));</div><divclass="line"><spanclass="comment">// confidure the label as a windows sub-widget</span></div><divclass="line"> setSubWidget(tmpWidget);</div><divclass="line"> }</div><divclass="line">}</div><divclass="line"></div><divclass="line"></div></div><!-- fragment --><p>The init function is virtual and you must call your parent object (or at least the ewol::Object::init)</p>
<divclass="fragment"><divclass="line"> ewol::widget::Windows::init();</div></div><!-- fragment --><p>The title is associated on the current windows then it is a simple property of <aclass="el"href="classewol_1_1widget_1_1_windows.html"title="Windows basic interface. ">ewol::widget::Windows</a>.</p>
<p>We can change with calling the "setDirectCheck" function instead of "set" function when you are in the constructor (the callback can be unstable when we construct the object)</p>
<divclass="fragment"><divclass="line"> propertyTitle.setDirectCheck(std::string(<spanclass="stringliteral">"sample "</span>) + PROJECT_NAME);</div></div><!-- fragment --><p>The object <aclass="el"href="classewol_1_1widget_1_1_windows.html"title="Windows basic interface. ">ewol::widget::Windows</a> is a simple container. But the reference between Object is <aclass="elRef"doxygen="/home/heero/dev/perso/out/doc/release/ememory.tag:http://atria-soft.github.io/ememory/"href="http://atria-soft.github.io/ememory/classememory_1_1_shared_ptr.html">ememory::SharedPtr</a>, and this is not accessible in the constructor. This is the reason we use init function.</p>
<p>After we simple create a <aclass="el"href="classewol_1_1widget_1_1_label.html">ewol::widget::Label</a> in the main windows init. We set label and basic properties:</p>
<divclass="fragment"><divclass="line"><aclass="codeRef"doxygen="/home/heero/dev/perso/out/doc/release/ememory.tag:http://atria-soft.github.io/ememory/"href="http://atria-soft.github.io/ememory/classememory_1_1_shared_ptr.html">ewol::widget::LabelShared</a> tmpWidget = ewol::widget::Label::create();</div><divclass="line"><spanclass="keywordflow">if</span> (tmpWidget == <spanclass="keyword">nullptr</span>) {</div><divclass="line"> APPL_ERROR(<spanclass="stringliteral">"Can not allocate widget ==> display might be in error"</span>);</div><divclass="line"> } <spanclass="keywordflow">else</span> {</div><divclass="line"> tmpWidget-><aclass="code"href="classewol_1_1widget_1_1_label.html#a9d6420ddec78c0d1abea850a79b4577a">propertyValue</a>.<aclass="codeRef"doxygen="/home/heero/dev/perso/out/doc/release/eproperty.tag:http://atria-soft.github.io/eproperty/"href="http://atria-soft.github.io/eproperty/classeproperty_1_1_property_type.html#a29dd42486e15d92b9ea94d30e99854e1">set</a>(<spanclass="stringliteral">"Hello <font color='blue'>World</font>"</span>);</div><divclass="line"> tmpWidget-><aclass="code"href="classewol_1_1_widget.html#a3bc497e98895d8fcfcc130cd072853f0">propertyExpand</a>.set(<aclass="codeRef"doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/"href="http://atria-soft.github.io/etk/classetk_1_1_vector2_d.html">bvec2</a>(<spanclass="keyword">true</span>,<spanclass="keyword">true</span>));</div><divclass="line"><spanclass="comment">// confidure the label as a windows sub-widget</span></div><divclass="line"> setSubWidget(tmpWidget);</div><divclass="line"> }</div></div><!-- fragment --><p> When we call the function <code>ewol::Windows::setSubWidget</code>, it use the SharedFromThis() function that create an exception if we are in constructor (when setting the sub-widget parrent)</p>
<p>We can see in this example that the label have some other property like the font color.</p>
<p>The label can have decorated text based on the html generic writing but it is composed with really simple set of balise. I will take a really long time to create a real html parser.</p>
<p>The availlable property is:</p><ul>
<li><code><br/></code> : New line</li>
<li><code><font color="#FF0000\"> ... </font></code> : change the font color.</li>
<li><code><center> ... </center></code> : center the text.</li>
<li><code><left> ... </left></code> : Set the text on the left.</li>
<li><code><right> ... </right></code> : Set the text on the right.</li>
<li><code><justify> ... </justify></code> : Set the text mode in justify.</li>
</ul>
<p><b>Note:</b></p>
<divclass="fragment"><divclass="line">The xml parser is a little strict on the case and end node (!! </br> !!),</div><divclass="line">but it support to:</div><divclass="line"> - Not have a main node.</div><divclass="line"> - replace '"' with ''' to simplify xml writing in C code.</div></div><!-- fragment --><h2><aclass="anchor"id="ewol_tutorial_hello_world_sources_configure_ewol"></a>
Configure Ewol to have display the windows </h2>
<p>At this point we have created the basic windows. But the system does not know it. Then we create windows and set it in the main context main <code>appl::MainApplication::onCreate</code>:</p>
<divclass="fragment"><divclass="line"><spanclass="comment">// Create the windows</span></div><divclass="line"><aclass="codeRef"doxygen="/home/heero/dev/perso/out/doc/release/ememory.tag:http://atria-soft.github.io/ememory/"href="http://atria-soft.github.io/ememory/classememory_1_1_shared_ptr.html">ewol::widget::WindowsShared</a> basicWindows = appl::Windows::create();</div><divclass="line"><spanclass="comment">// configure the ewol context to use the new windows</span></div><divclass="line"> _context.setWindows(basicWindows);</div></div><!-- fragment --><p> Here we call the create function that is created by the DECLARE_FACTORY macro</p>
<p><b>Note:</b></p>
<divclass="fragment"><divclass="line">You can use many windows and select the one you want to display, but I do not think it is the best design.</div></div><!-- fragment --><h1><aclass="anchor"id="ewol_tutorial_hello_world_build"></a>
Build declaration: </h1>
<p>Ewol commonly use the <ahref="http://HeeroYui.github.io/lutin">lutin</a> build system.</p>
<p>Then we need to add a "lutin_YourApplicationName.py", then for this example: <code>lutin_ewol-sample-HelloWord.py</code></p>
<divclass="fragment"><divclass="line">lutin -C -mdebug ewol-sample-HelloWord</div><divclass="line"># or</div><divclass="line">lutin -C -mdebug ewol-sample-HelloWord?build</div></div><!-- fragment --><p>You can now execute your application:</p>
<divclass="fragment"><divclass="line">lutin -C -mdebug ewol-sample-HelloWord?run</div></div><!-- fragment --></div></div><!-- contents -->