1 /*! \page hello-world Hello World - explained
3 The following steps are required for displaying the sentence 'Hello World' with Dali:
5 - initialize the Dali library
6 - create an Actor showing text
9 To understand the basic building blocks of the UI make sure to read the chapter on \link fundamentals Dali Fundamentals\endlink first.
11 Let's take a look at the code for this test application.
13 <h2 class="pg"> Example code </h2>
16 #include <dali-toolkit/dali-toolkit.h>
19 using Dali::Toolkit::TextLabel;
21 // This example shows how to create and display Hello World! using a simple TextActor
23 class HelloWorldController : public ConnectionTracker
27 HelloWorldController( Application& application )
28 : mApplication( application )
30 // Connect to the Application's Init signal
31 mApplication.InitSignal().Connect( this, &HelloWorldController::Create );
34 ~HelloWorldController()
36 // Remove Hello World actor from stage
37 Stage::GetCurrent().Remove(mTextLabel);
40 // The Init signal is received once (only) during the Application lifetime
41 void Create( Application& application )
43 // Get a handle to the stage
44 Stage stage = Stage::GetCurrent();
46 mTextLabel = TextLabel::New( "Hello World" );
47 mTextLabel.SetAnchorPoint( AnchorPoint::TOP_LEFT );
48 stage.Add( mTextLabel );
50 // Respond to a click anywhere on the stage
51 stage.GetRootLayer().TouchedSignal().Connect( this, &HelloWorldController::OnTouch );
54 bool OnTouch( Actor actor, const TouchEvent& touch )
56 // quit the application
62 Application& mApplication;
66 void RunTest( Application& application )
68 HelloWorldController test( application );
70 application.MainLoop();
73 // Entry point for Linux & Tizen applications
75 int main( int argc, char **argv )
77 Application application = Application::New( &argc, &argv );
79 RunTest( application );
86 There are a couple of steps which are very important to understand.
88 <h2 class="pg"> Initializing Dali </h2>
89 The application should not use the Dali library until it has sent the init complete signal!
90 That's why we connect our ExampleApp::Create callback to Dali::Application's SignalInit signal:
93 app.SignalInit().Connect(this, &ExampleApp::Create);
97 <h2 class="pg"> Reference counting </h2>
98 The application should store Actors' and resources' handles.
99 Dali objects are reference counted, which makes sure they exist only as long as they are needed.
100 That's why we store the Actor's handle:
103 mTextLabel = TextLabel::New("Hello World");
106 Even if the TextLabel is removed from the stage, it will be kept alive through our reference.\n
107 You can read more about implicit smart-pointer semantics in chapter \link handle-body-idiom Handle – body\endlink.
109 <h2 class="pg"> Main loop </h2>
110 To 'run' the application, it's main loop should be started.
111 This ensures that images are displayed, events, signals are dispatched and captured and so on.
118 On X11 platform you can compile the above example with:
120 g++ `pkg-config --libs --cflags dali` hello-dali.cpp -o hello
123 After running './hello' this should be visible on the screen:
125 <table border=0 cellpadding=10>
128 \image html Text-Label.png "Hello world example"