/*! \page hello-world Hello World - explained
-The following steps are required for displaying the sentence 'Hello World' with Dali:
+The following steps are required for displaying the sentence 'Hello World' with DALi:
-- initialize the Dali library
+- initialize the DALi library
- create an Actor showing text
- add it to the Stage
-To understand the basic building blocks of the UI make sure to read the chapter on \link fundamentals Dali Fundamentals\endlink first.
+To understand the basic building blocks of the UI make sure to read the chapter on \link fundamentals DALi Fundamentals\endlink first.
Let's take a look at the code for this test application.
<h2 class="pg"> Example code </h2>
\code
-#include <dali/dali.h>
-using namespace Dali;
+#include <dali-toolkit/dali-toolkit.h>
-/******************************************************
- * Demonstrates how to display "Hello World" on screen
- ******************************************************/
+using namespace Dali;
+using Dali::Toolkit::TextLabel;
-class ExampleApp
+// This example shows how to create and display Hello World! using a simple TextActor
+//
+class HelloWorldController : public ConnectionTracker
{
public:
- ExampleApp(Application &app)
- : mApp(app)
+
+ HelloWorldController( Application& application )
+ : mApplication( application )
{
- // Connect to Dali::Application init signal. Do not make calls to Dali before this signal is received.
- app.SignalInit().Connect(this, &ExampleApp::Create);
+ // Connect to the Application's Init signal
+ mApplication.InitSignal().Connect( this, &HelloWorldController::Create );
}
- ~ExampleApp()
+ ~HelloWorldController()
{
- // Remove Hello World TextActor from stage
- Stage::GetCurrent().Remove(mTextActor);
+ // Remove Hello World actor from stage
+ Stage::GetCurrent().Remove(mTextLabel);
}
-public:
-
- void Create(Application& app)
+ // The Init signal is received once (only) during the Application lifetime
+ void Create( Application& application )
{
- // Initialize the actor
- mTextActor = TextActor::New("Hello World");
+ // Get a handle to the stage
+ Stage stage = Stage::GetCurrent();
+
+ mTextLabel = TextLabel::New( "Hello World" );
+ mTextLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+ stage.Add( mTextLabel );
- // Center the actor. Note: default anchor point is CENTER
- mTextActor.SetParentOrigin(ParentOrigin::CENTER);
+ // Respond to a click anywhere on the stage
+ stage.GetRootLayer().TouchedSignal().Connect( this, &HelloWorldController::OnTouch );
+ }
- // Display the actor on the stage
- Stage::GetCurrent().Add(mTextActor);
+ bool OnTouch( Actor actor, const TouchEvent& touch )
+ {
+ // quit the application
+ mApplication.Quit();
+ return true;
}
private:
- Application& mApp;
- TextActor mTextActor;
+ Application& mApplication;
+ TextLabel mTextLabel;
};
-int
-main(int argc, char **argv)
+void RunTest( Application& application )
+{
+ HelloWorldController test( application );
+
+ application.MainLoop();
+}
+
+// Entry point for Linux & Tizen applications
+//
+int main( int argc, char **argv )
{
- Application daliApp(&argc, &argv);
+ Application application = Application::New( &argc, &argv );
- ExampleApp helloApp (daliApp);
- daliApp.MainLoop();
+ RunTest( application );
return 0;
}
There are a couple of steps which are very important to understand.
- <h2 class="pg"> Initializing Dali </h2>
- The application should not use the Dali library until it has sent the init complete signal!
+ <h2 class="pg"> Initializing DALi </h2>
+ The application should not use the DALi library until it has sent the init complete signal!
That's why we connect our ExampleApp::Create callback to Dali::Application's SignalInit signal:
\code
...
<h2 class="pg"> Reference counting </h2>
The application should store Actors' and resources' handles.
- Dali objects are reference counted, which makes sure they exist only as long as they are needed.
+ DALi objects are reference counted, which makes sure they exist only as long as they are needed.
That's why we store the Actor's handle:
\code
...
- mTextActor = TextActor::New("Hello World");
+ mTextLabel = TextLabel::New("Hello World");
...
\endcode
- Even if the TextActor is removed from the stage, it will be kept alive through our reference.\n
+ Even if the TextLabel is removed from the stage, it will be kept alive through our reference.\n
You can read more about implicit smart-pointer semantics in chapter \link handle-body-idiom Handle – body\endlink.
<h2 class="pg"> Main loop </h2>
After running './hello' this should be visible on the screen:
- \image html Text-Actor.png "Hello world example"
+<table border=0 cellpadding=10>
+<tr>
+ <td>
+ \image html Text-Label.png "Hello world example"
+ </td>
+</tr>
+</table>
*/