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>
15 #include <dali/dali.h>
19 /******************************************************
20 * Demonstrates how to display "Hello World" on screen
21 ******************************************************/
26 ExampleApp(Application &app)
29 // Connect to Dali::Application init signal. Do not make calls to Dali before this signal is received.
30 app.SignalInit().Connect(this, &ExampleApp::Create);
35 // Remove Hello World TextActor from stage
36 Stage::GetCurrent().Remove(mTextActor);
41 void Create(Application& app)
43 // Initialize the actor
44 mTextActor = TextActor::New("Hello World");
46 // Center the actor. Note: default anchor point is CENTER
47 mTextActor.SetParentOrigin(ParentOrigin::CENTER);
49 // Display the actor on the stage
50 Stage::GetCurrent().Add(mTextActor);
59 main(int argc, char **argv)
61 Application daliApp(&argc, &argv);
63 ExampleApp helloApp (daliApp);
71 There are a couple of steps which are very important to understand.
73 <h2 class="pg"> Initializing Dali </h2>
74 The application should not use the Dali library until it has sent the init complete signal!
75 That's why we connect our ExampleApp::Create callback to Dali::Application's SignalInit signal:
78 app.SignalInit().Connect(this, &ExampleApp::Create);
82 <h2 class="pg"> Reference counting </h2>
83 The application should store Actors' and resources' handles.
84 Dali objects are reference counted, which makes sure they exist only as long as they are needed.
85 That's why we store the Actor's handle:
88 mTextActor = TextActor::New("Hello World");
91 Even if the TextActor is removed from the stage, it will be kept alive through our reference.\n
92 You can read more about implicit smart-pointer semantics in chapter \link handle-body-idiom Handle – body\endlink.
94 <h2 class="pg"> Main loop </h2>
95 To 'run' the application, it's main loop should be started.
96 This ensures that images are displayed, events, signals are dispatched and captured and so on.
103 On X11 platform you can compile the above example with:
105 g++ `pkg-config --libs --cflags dali` hello-dali.cpp -o hello
108 After running './hello' this should be visible on the screen:
110 \image html Text-Actor.png "Hello world example"