Tutorial 1: Hello Word
Objectif
- Understand basis of ewol
- Create a simple windows with a label "Hello Word"
Application Sources:
Main Windows:
Application "main()":
Build declaration:
Build your application
In all the application we need to have a main, for some reason this main is stored by the application and only call the EWOL main:
int main(int argc, const char *argv[]) { // only one things to do : return ewol::run(argc, argv); }
Then the first question, is where is the input of the application:
// application start: bool APP_Init(ewol::Context& _context) { return true; } // application stop: void APP_UnInit(ewol::Context& _context) { }
The input ewol::eContext is the main application context. All the application globals have a reference in this element. It is important to note that the system can call you some time in parallele, the basic exemple of this is the Wallpaper on Android. When selected, it create an intance and when it is apply Android create a new instance and remove the previous one...
Now we will create some generic property:
In first: set the font availlagle on the global font property (system font). This can be a problem when you designe an application for some other operating system (OS), They do not have the same default font. and we select an order to search the font names and the system basic size.
_context.getFontDefault().setUseExternal(true); _context.getFontDefault().set("FreeSerif;DejaVuSansMono", 19);
In second: we will create a windows.
For this point we will create a class that herited form the basic windows class:
Windows.h
#ifndef __APPL_WINDOWS_H__ #define __APPL_WINDOWS_H__ #include <ewol/widget/Windows.h> namespace appl { class Windows : public ewol::widget::Windows { public: Windows(void); public: }; }; #endif
Windows.cpp
#include <ewol/ewol.h> #include <appl/debug.h> #include <appl/Windows.h> #include <ewol/widget/Label.h> #undef __class__ #define __class__ "Windows" appl::Windows::Windows(void) { setTitle("example 001_HelloWord"); ewol::widget::Label* tmpWidget = new ewol::widget::Label(); if (NULL == tmpWidget) { APPL_ERROR("Can not allocate widget ==> display might be in error"); } else { tmpWidget->setLabel("Hello <font color=\"blue\">Word</font>"); tmpWidget->setExpand(bvec2(true,true)); setSubWidget(tmpWidget); } }
The fist basic property to set is the Title:
setTitle("example 001_HelloWord");
After we simple create a widget::Label in the main windows constructor. And we set the widget property (label).
ewol::widget::Label* tmpWidget = new ewol::widget::Label(); tmpWidget->setLabel("Hello <font color=\"blue\">Word</font>"); tmpWidget->setExpand(bvec2(true,true));We can se in this example that the label have some other property like the font color.
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, the the availlable property is:
- <br/> : New line
- <font color="#FF0000\"> ... </font> : change the font color.
- <center> ... </center> : center the text.
- <left> ... </left> : Set the text on the left.
- <right> ... </right> : Set the text on the right.
- <justify> ... </justify> : Set the text mode in justify.
Note:
The xml parser is a little strict on the case and end node, but it support to not have a main node.
The last step is to add the widget on the windows :
setSubWidget(tmpWidget);
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 contect main (in the APPL_init()):
ewol::Windows* basicWindows = new appl::Windows(); // create the specific windows _context.setWindows(basicWindows);
Then the init fuction is :
bool APP_Init(ewol::Context& _context) { // select internal data for font ... _context.getFontDefault().setUseExternal(true); _context.getFontDefault().set("FreeSerif;DejaVuSansMono", 19); ewol::Windows* basicWindows = new appl::Windows(); // create the specific windows _context.setWindows(basicWindows); return true; }
To un-init the application, the context call a generic function APP_UnInit. In this function we just need to remove the windows and un-init all needed by the system.
void APP_UnInit(ewol::Context& _context) { // The main windows will be auto-remove after this call if it is not done... }