hello word


Previous: Build
Next: Object model

Objectif

Application Sources:


Application Main:


A generic Ewol application is manage by creating an ewol::context::Application that is the basis of your application.
Due to the fact the ewol library is a multi-platform framework, you will have many contraint like: Then we will create the application:
namespace appl {
	class MainApplication : public ewol::context::Application {
		public:
			bool init(ewol::Context& _context, size_t _initId) {
				APPL_INFO("==> Init APPL (START)");
				// nothing to do ...
				APPL_INFO("==> Init APPL (END)");
				return true;
			}
			void unInit(ewol::Context& _context) {
				APPL_INFO("==> Un-Init APPL (START)");
				// nothing to do ...
				APPL_INFO("==> Un-Init APPL (END)");
			}
	};
};

The input ewol::Context is the main system context.

Note:
It is important to know that the system can create your application multiple times, the basic exemple of this is the Wallpaper on Android.
What is done:
  • When we select the wallpaper it create a new application (to show an example)
  • When applying your choice, it create the real one an remove the previous one.

  • In all program we need to have a main()
    To be portable on Android, the "main" in the java might call your main through the Android wrapper.
    To simplify compabilities between platform it is recommanded to not add other things in the application main:
    	int main(int argc, const char *argv[]) {
    		// only one things to do : 
    		return ewol::run(new appl::MainApplication(), _argc, _argv);
    	}
    

    Some configuration are needed


    In your application you can use many configuration, it is really better to set all your configuration dynamic. With this basic condiction will simplify the interface of the library if you would have many different application (never forger the compilator garbage collector is really very efficient).

    Select fonts:
    This can be a problem when you design an application for some other operating system (OS), They do not have the same default font.
    We select an order to search the font names and the system basic size.
    	// Use External font depending on the system (for specific application, it is better to provide fonts)
    	_context.getFontDefault().setUseExternal(true);
    	// Select font in order you want : if Ewol find FreeSerif, it selected it ...
    	_context.getFontDefault().set("FreeSerif;DejaVuSansMono", 19);
    

    Main Windows:


    Create the main Windows:
    For this point we will create a class that herited form the basic ewol::wiget::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 {
    			protected:
    				Windows(void);
    				init()
    			public:
    				DECLARE_FACTORY(Windows);
    				virtual ~Windows(void) {};
    		};
    	};
    	#endif
    

    See Next: Object model to understand why this structure is so complex.
    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) {
    		// To simplify log (if you have a better solution, I am aware)
    		addObjectType("appl::Windows");
    	}
    	appl::Windows::init(void) {
    		ewol::widget::Windows::init();
    		setTitle("example 001_HelloWord");
    		std::shared_ptr<ewol::widget::Label> tmpWidget = ewol::widget::Label::create();
    		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 init function can not be virtual due to his polymorphic status, then we need to call parrent init
    	ewol::widget::Windows::init();
    

    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).
    	std::shared_ptr<ewol::widget::Label> tmpWidget = ewol::widget::Label::create();
    	tmpWidget->setLabel("Hello <font color='blue'>Word</font>");
    	tmpWidget->setExpand(bvec2(true,true));
    
    We can see 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 availlable property is:
    Note:
    The xml parser is a little strict on the case and end node (!! </br> !!),
    but it support to:
    

    The last step is to add the widget on the windows :
    	setSubWidget(tmpWidget);
    
    When we call this function, it use the shard_from_this() function that create an exception if we are in constructor

    Configure Ewol to have display the windows


    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 MainApplication::init()):
    	std::shared_ptr<ewol::Windows> basicWindows = appl::Windows::create());
    	// create the specific windows
    	_context.setWindows(basicWindows);
    
    Her we call the create function that is created by the DECLARE_FACTORY macro
    Then the init fuction is :
    bool MainApplication::init(ewol::Context& _context, size_t _initId) {
    	APPL_INFO("==> Init APPL (START)");
    	// select internal data for font ...
    	_context.getFontDefault().setUseExternal(true);
    	_context.getFontDefault().set("FreeSerif;DejaVuSansMono", 19);
    	
    	std::shared_ptr<ewol::Windows> basicWindows = appl::Windows::create();
    	// create the specific windows
    	_context.setWindows(basicWindows);
    	APPL_INFO("==> Init APPL (END)");
    	return true;
    }
    

    To un-init the application, the context call a generic function MainApplication::unInit. In this function we just need to remove the windows and un-init all needed by the system.
    void MainApplication::unInit(ewol::Context& _context) {
    	APPL_INFO("==> Un-Init APPL (START)");
    	// Windows is auto-removed just before
    	APPL_INFO("==> Un-Init APPL (END)");
    }
    


    Note:
    You can use many windows and select the one you want to display, but I do not think it is the best design.
    

    Build declaration:


    ewol commonly use the lutin.py build system.
    Then we need to add a "lutin_YourApplicationName.py", then for this example: lutin_001_HelloWord.py
    #!/usr/bin/python
    import lutinModule as module
    import lutinTools as tools
    # optionnal : Describe in the "lutin.py --help" def get_desc(): return "Tutorial 001 : Hello Word"
    # Module creation instance (not optionnal) def create(target): # module name is '001_HelloWord' and type binary. myModule = module.Module(__file__, '001_HelloWord', 'BINARY') # add the file to compile: myModule.add_src_file([ 'appl/Main.cpp', 'appl/debug.cpp', 'appl/Windows.cpp', ]) # add Library dependency name myModule.add_module_depend(['ewol']) # add application C flags myModule.compile_flags_CC([ "-DPROJECT_NAME=\"\\\""+myModule.name+"\\\"\""]) # Add current include Path myModule.add_path(tools.get_current_path(__file__)) return the created module return myModule

    show lutin doc for more information...

    Note:
    I do not explain again the lutin file, for next tutorial, show example sources ...
    

    Build your application


    Go to your workspace folder and launch
    	./ewol/build/lutin.py -C -mdebug 001_HelloWord
    

    Your program example will build correctly...
    Launch it :
    	./out/Linux/debug/staging/gcc/001_HelloWord/usr/bin/001_HelloWord -l6
    

    The -l6 is used to specify the Log level of the application display (this log is synchronous)
    The output compile in a separate folder depending on the compilation tool (gcc or clang)
    It create a complete final tree in the ./out/Linux/debug/staging/gcc/001_HelloWord/ folder
    The final folder contain the package generated: