[DEV] update documentation

This commit is contained in:
Edouard DUPIN 2014-06-16 22:34:44 +02:00
parent 21c2bcfd39
commit 8afd56e77e
4 changed files with 83 additions and 48 deletions

View File

@ -10,38 +10,50 @@ __________________________________________________
==== Application Main: ==== ==== Application Main: ====
A generic Ewol application is manage by creating an [class[ewol::context::Application]] that is the basis of your application.
In all the application we need to have a main() Due to the fact the ewol librairy is a multi-platform framework, then you need to think all you will do with only one
In This version the main neen only to call the ewol::run(void) that is the basic interface. application and only one windows displayable at the same time.
To be portable on Android, that have a java main the User might not set other things in this main.
[note]This basic main will change in the future to be more generic!!![/note] Then we will create the application:
[code style=c++]
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)");
}
};
[/code]
The input [class[ewol::Context]] is the main system context.
[note]
It is important to know that the system can call your application in parallele, the basic exemple of this is the Wallpaper on Android.
What is done:
** When selected, it create an intance and when it is apply Android create a new instance and remove the previous one...
[/note]
In all program we need to have a main()
To be portable on Android, that have a java main the User might the Wrapper call the generic main() (please do not add other things in this main).
[code style=c++] [code style=c++]
int main(int argc, const char *argv[]) { int main(int argc, const char *argv[]) {
// only one things to do : // only one things to do :
return ewol::run(argc, argv); return ewol::run(new MainApplication(), _argc, _argv);
} }
[/code] [/code]
Then the first question, is where is the start and stop of the application:
[code style=c++]
// application start:
bool APP_Init(ewol::Context& _context) {
return true;
}
// application stop:
void APP_UnInit(ewol::Context& _context) {
// nothing to do.
}
[/code]
The input [class[ewol::eContext]] is the main application context.
All the application globals have a reference in this element (and can get it everyware).
[note]
It is important to know that the system can call your application 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...
[/note]
==== Some configuration are needed ==== ==== Some configuration are needed ====
@ -99,7 +111,7 @@ For this point we will create a class that herited form the basic windows class:
appl::Windows::Windows(void) { appl::Windows::Windows(void) {
setTitle("example 001_HelloWord"); setTitle("example 001_HelloWord");
ewol::widget::Label* tmpWidget = new ewol::widget::Label(); ewol::object::Shared<ewol::widget::Label> tmpWidget = new ewol::widget::Label();
if (NULL == tmpWidget) { if (NULL == tmpWidget) {
APPL_ERROR("Can not allocate widget ==> display might be in error"); APPL_ERROR("Can not allocate widget ==> display might be in error");
} else { } else {
@ -118,7 +130,7 @@ The fist basic property to set is the Title:
After we simple create a [class[widget::Label]] in the main windows constructor. After we simple create a [class[widget::Label]] in the main windows constructor.
And we set the widget property (label). And we set the widget property (label).
[code style=c++] [code style=c++]
ewol::widget::Label* tmpWidget = new ewol::widget::Label(); ewol::object::Shared<ewol::widget::Label> tmpWidget = ewol::object::makeShared(new ewol::widget::Label());
tmpWidget->setLabel("Hello <font color=\"blue\">Word</font>"); tmpWidget->setLabel("Hello <font color=\"blue\">Word</font>");
tmpWidget->setExpand(bvec2(true,true)); tmpWidget->setExpand(bvec2(true,true));
[/code] [/code]
@ -150,16 +162,17 @@ The last step is to add the widget on the windows :
At this point we have created the basic windows. At this point we have created the basic windows.
But the system does not know it. But the system does not know it.
Then we create windows and set it in the main contect main (in the APPL_init()): Then we create windows and set it in the main contect main (in the MainApplication::init()):
[code style=c++] [code style=c++]
ewol::Windows* basicWindows = new appl::Windows(); ewol::object::Shared<ewol::Windows> basicWindows = ewol::object::makeShared(new appl::Windows());
// create the specific windows // create the specific windows
_context.setWindows(basicWindows); _context.setWindows(basicWindows);
[/code] [/code]
Then the init fuction is : Then the init fuction is :
[code style=c++] [code style=c++]
bool APP_Init(ewol::Context& _context) { bool MainApplication::init(ewol::Context& _context, size_t _initId) {
APPL_INFO("==> Init APPL (START)");
// select internal data for font ... // select internal data for font ...
_context.getFontDefault().setUseExternal(true); _context.getFontDefault().setUseExternal(true);
_context.getFontDefault().set("FreeSerif;DejaVuSansMono", 19); _context.getFontDefault().set("FreeSerif;DejaVuSansMono", 19);
@ -167,15 +180,18 @@ bool APP_Init(ewol::Context& _context) {
ewol::Windows* basicWindows = new appl::Windows(); ewol::Windows* basicWindows = new appl::Windows();
// create the specific windows // create the specific windows
_context.setWindows(basicWindows); _context.setWindows(basicWindows);
APPL_INFO("==> Init APPL (END)");
return true; return true;
} }
[/code] [/code]
To un-init the application, the context call a generic function [b]APP_UnInit[/b]. To un-init the application, the context call a generic function [b]MainApplication::unInit[/b].
In this function we just need to remove the windows and un-init all needed by the system. In this function we just need to remove the windows and un-init all needed by the system.
[code style=c++] [code style=c++]
void APP_UnInit(ewol::Context& _context) { void MainApplication::unInit(ewol::Context& _context) {
// The main windows will be auto-remove after this call if it is not done... APPL_INFO("==> Un-Init APPL (START)");
// Windows is auto-removed just before
APPL_INFO("==> Un-Init APPL (END)");
} }
[/code] [/code]

View File

@ -3,8 +3,8 @@ __________________________________________________
[left][tutorial[001_HelloWord | Previous: Hello Word]][/left] [right][tutorial[011_ObjectConfig | Next: Object config]][/right] [left][tutorial[001_HelloWord | Previous: Hello Word]][/left] [right][tutorial[011_ObjectConfig | Next: Object config]][/right]
=== Objectif === === Objectif ===
:** Understand ewol basic object :** Understand ewol basic [class[ewol::Object]]
:** Use ewol::Object correctly :** Use [class[ewol::Object]] correctly
== Basis of the Object == == Basis of the Object ==
@ -13,7 +13,7 @@ This is designed to manage basis element of complexe structure:
:** Unique ID :** Unique ID
:** Name :** Name
:** Config :** Configuration (decriptive naming of parameters)
:** Event generation and receving :** Event generation and receving
:** Xml configuration :** Xml configuration
:** Delayed removing :** Delayed removing
@ -25,9 +25,11 @@ Please do not compare with the gObject basic class...
== Create an Object: == == Create an Object: ==
This is a really simple way to create an Object, simply generate a new on it : In theory you can use a simple new on an object, but you need to remove the refcounting of this one by yoursef ... really awfull.
It is really better to use the ewol::object::Shared<> declaration to auto manage it. (same as std::shared_ptr)
[code style=c++] [code style=c++]
widget::Label* tmpObject = new widget::Label(); ewol::object::Shared<widget::Label> tmpObject = ewol::object::makeShared(new widget::Label());
if (tmpObject == NULL) { if (tmpObject == NULL) {
APPL_ERROR("An error occured"); APPL_ERROR("An error occured");
return; return;
@ -48,8 +50,6 @@ Force the set of the name :
This is important to note that many element can have a reference on the Object. This is important to note that many element can have a reference on the Object.
And we did not use "ref-counting" for philosophic reasons ...
Then we need to use the fuction: Then we need to use the fuction:
[b]removeObject()[/b] to remove the Object, This will notify avery object in the system that this [b]removeObject()[/b] to remove the Object, This will notify avery object in the system that this
specific object has been removed. specific object has been removed.
@ -60,23 +60,32 @@ Then to remove an object call:
tmpObject->removeObject(); tmpObject->removeObject();
[/code] [/code]
On every object we can have an herited function: [b]virtual void onObjectRemove(ewol::Object * _removeObject);[/b] On every object we can have an herited function: [b]virtual void onObjectRemove(const ewol::object::Shared<ewol::Object>& _removeObject);[/b]
We need to implement this fuction to be notify an object is removed: We need to implement this fuction to be notify an object is removed:
[code style=c++] [code style=c++]
void namespeceName::ClassName::onObjectRemove(ewol::Object * _removeObject) { void namespeceName::ClassName::onObjectRemove(const ewol::object::Shared<ewol::Object>& _removeObject) {
// Never forget to call upper Object (otherwise many object will keep theire reference)
upperClass::onObjectRemove(_removeObject);
if (_removeObject == m_object) { if (_removeObject == m_object) {
m_object = NULL; m_object.reset();
markToRedraw(); // set only for graphical object ... markToRedraw(); // set only for graphical object ...
} }
} }
[/code] [/code]
[note] [note]
If you have well follow the idea, you will never declare an object in local, just use pointer on them. If you have well follow the idea, you will never declare an object in local, just use shared pointer on them.
[/note] [/note]
[note]
For some case it could be interesting to see the [class[ewol::object::Owner<T>]] class that provide an automatic auto remove of object.
See [class[ewol::widget::Container]] for an example.
[/note]
=== Particularity === === Particularity ===
An object can remove itself, just use the function: An object can remove itself, just use the function:
@ -87,7 +96,7 @@ An object can remove itself, just use the function:
== Retrieve an Object: == == Retrieve an Object: ==
In Ewol this is possible to get a widget with his name. In Ewol this is possible to get a object with his name.
This is really simple. This is really simple.
=== In an Object === === In an Object ===
@ -99,7 +108,7 @@ Call a simple function define in the Object:
... ...
ewol::Object* tmpObject = getObjectManager().get("name of the object"); ewol::object::Shared<ewol::Object> tmpObject = getObjectManager().get("name of the object");
if (tmpObject == NULL) { if (tmpObject == NULL) {
APPL_ERROR("The Object does not exist"); APPL_ERROR("The Object does not exist");
} }
@ -115,13 +124,21 @@ In this case, we need to get the context manager and after the object manager:
... ...
ewol::Object* tmpObject = ewol::getContext().getObjectManager().get("name of the object"); ewol::object::Shared<ewol::Object> tmpObject = ewol::getContext().getObjectManager().get("name of the object");
if (tmpObject == NULL) { if (tmpObject == NULL) {
APPL_ERROR("The Object does not exist"); APPL_ERROR("The Object does not exist");
} }
[/code] [/code]
=== Casting your object ===
It could be really interesting to retrive your own instance:
[code style=c++]
ewol::object::Shared<ewol::Object> tmpObject ...;
ewol::object::Shared<appl::MyOwnObject> myObject = ewol::dynamic_pointer_cast<appl::MyOwnObject>(tmpObject);
[/code]
== conclusion == == conclusion ==
@ -129,6 +146,8 @@ If you follow these rules, you will not have memory leek and no segmentation fau
[note] [note]
To be sure that the name is unique, just add the current creator object Id in the name. To be sure that the name is unique, just add the current creator object Id in the name.
See [class[ewol::widget::FileChooser]] class for an example.
[/note] [/note]

2
monk

@ -1 +1 @@
Subproject commit aff1fdf89a04b8a4594c2742f875614e56cf8a31 Subproject commit 895e18786ce732e8cc1c282863677c21e1806062

View File

@ -29,7 +29,7 @@ namespace ewol {
* *
* The first step is to create the file chooser pop-up : * The first step is to create the file chooser pop-up :
* [code style=c++] * [code style=c++]
* ewol::widget::FileChooser* tmpWidget = new ewol::Widget::FileChooser(); * ewol::object::Shared<ewol::widget::FileChooser> tmpWidget = ewol::object::makeShared(new ewol::Widget::FileChooser());
* if (tmpWidget == nullptr) { * if (tmpWidget == nullptr) {
* APPL_ERROR("Can not open File chooser !!! "); * APPL_ERROR("Can not open File chooser !!! ");
* return -1; * return -1;