Merge remote-tracking branch 'origin/tizen' into new_text
[platform/core/uifw/dali-demo.git] / examples / text-label-multi-language / text-label-multi-language-example.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 /**
19  * @file text-label-example.cpp
20  * @brief Basic usage of TextLabel control
21  */
22
23 // INTERNAL INCLUDES
24 #include "vertical-layout.h"
25
26 // EXTERNAL INCLUDES
27 #include <dali-toolkit/dali-toolkit.h>
28 #include <dali/public-api/text-abstraction/text-abstraction.h>
29
30 using namespace Dali;
31 using namespace Dali::Toolkit;
32
33 namespace
34 {
35   struct Language
36   {
37     std::string languageName;
38     std::string languageRomanName;
39     std::string text;
40   };
41
42   const Language LANGUAGES[] = {
43     {
44       "العَرَبِيةُ",
45       "(Arabic)",
46       "لإعادة ترتيب الشاشات، يجب تغيير نوع العرض إلى شبكة قابلة للتخصيص."
47     },
48     {
49       "অসমীয়া লিপি",
50       "(Assamese)",
51       "পৃষ্ঠাসমূহ পুনঃব্যৱস্থিত কৰিবলৈ, আপুনি দৰ্শনৰ প্ৰকাৰ এটা অনুকূলনযোগ্য গ্ৰীডলৈ পৰিৱৰ্তন কৰাটো আৱশ্যক৷"
52     },
53     {
54       "বাংলা",
55       "(Bengali)",
56       "তথ্য লোড করতে অক্ষম৷ পুনরায় চেষ্টা করতে ট্যাপ করুন৷"
57     },
58     {
59       "English",
60       "(English)",
61       "A Quick Brown Fox Jumps Over The Lazy Dog"
62     },
63     {
64       "Español",
65       "(Spanish)",
66       "No se puede añadir más aplicaciones. Se alcanzó la cantidad máxima."
67     },
68     {
69       "فارسی",
70       "(Persian)",
71       "برای مرتب کردن مجدد صفحه‌ها، باید نوع نمایش را به یک نمای شبکه‌ای قابل تنظیم تغییر دهید."
72     },
73     {
74       "Français",
75       "(French)",
76       "La nouvelle page sera composée des Dynamic Box S Planner, Tâches et S Memo"
77     },
78     {
79       "ગુજરાતી લિપિ",
80       "(Gujarati)",
81       "પૃષ્ઠોને ફરીથી ગોઠવવા માટે, તમારે દૃશ્ય પ્રકારને કસ્ટમાઇઝેશન યોગ્ય ગ્રિડ પર બદલવાની જરૂર છે."
82     },
83     {
84       "हिन्दी",
85       "(Hindi)",
86       "पेज पुनः व्यवस्थित करने के लिए, आपको दृश्य प्रकार को अनुकूलित करने योग्य ग्रिड में बदलना होगा।"
87     },
88     {
89       "Bahasa Indonesia",
90       "(Indonesian)",
91       "Tidak dapat menambahkan aplikasi lagi. Jumlah maksimum aplikasi tercapai."
92     },
93     {
94       "ខេមរភាសា",
95       "(Cambodian)",
96       "ដើម្បី​រៀបចំ​ទំព័រ​ឡើងវិញ អ្នក​ត្រូវ​ប្ដូរ​ប្រភេទ​បង្ហាញ​ទៅ​ក្រឡាចត្រង្គ​ដែល​អាច​ប្ដូរ​តាមបំណង។"
97     },
98     {
99       "ಕನ್ನಡ ",
100       "(Kannada)",
101       "ಪುಟಗಳನ್ನು ಮರುವ್ಯವಸ್ಥಿತವಾಗಿ ಇರಿಸಲು, ನೀವು ವೀಕ್ಷಣೆ ವಿಧವನ್ನು ಗ್ರಾಹಕೀಕರಿಸಬಲ್ಲ ಗ್ರಿಡ್‌ಗೆ ಬದಲಾಯಿಸುವುದು ಅಗತ್ಯವಿದೆ."
102     },
103     {
104       "한국어",
105       "(Korean)",
106       "페이지 순서를 변경하려면 보기 방식을 격자 보기(직접 설정)로 변경하세요."
107     },
108     {
109       "ພາສາລາວ",
110       "(Lao)",
111       "ເພື່ອຈັດລຽງໜ້າຄືນ, ທ່ານຈໍາເປັນຕ້ອງປ່ຽນຊະນິດຂອງມຸມມອງໄປຫາຕາຕະລາງທີ່ກຳນົດເອງໄດ້."
112     },
113     {
114       "മലയാളം",
115       "(Malayalam)",
116       "പേജുകൾ പുനഃക്രമീകരിക്കുന്നതിന്, ഇഷ്ടാനുസൃതമാക്കാവുന്ന ഗ്രിഡിലേക്ക് കാഴ്ചയുടെ തരം നിങ്ങൾ മാറ്റേണ്ടതുണ്ട്."
117     },
118     {
119       "मराठी",
120       "(Marathi)",
121       "पृष्‍ठांची पुनर्रचना करा, आपण सानुकूलित करण्‍यायोग्‍य ग्रिडमध्‍ये व्‍ह्यू प्रकार बदलणे गरजेचे आहे."
122     },
123     {
124       "Bahasa Melayu",
125       "(Malay)",
126       "Tidak boleh menambah aplikasi lagi. Bilangan maksimum aplikasi dicapai."
127     },
128     {
129       "မြန်မာဘာသာ",
130       "(Burmese)",
131       "စာမ်က္ႏွာမ်ား ျပန္စီစဥ္ရန္ အျမင္ပံုစံကို စိတ္ၾကိဳက္လုပ္ႏိုင္ေသာ ဂရစ္ တစ္ခုသို႔ ေျပာင္းဖို႔လိုသည္။"
132     },
133     {
134       "नेपाली",
135       "(Nepali)",
136       "थप अनुप्रयोगहरू थप्न सकिएन। अनुप्रयोगहरूको अधिकतम संख्या पुग्यो।"
137     },
138     {
139       "ଓଡ଼ିଆ",
140       "(Oriya)",
141       "ପରବର୍ତ୍ତୀ ପୃଷ୍ଠା ଦେଖିବା ପାଇଁ ଦୁଇ ଆଙ୍ଗୁଠିରେ ସ୍ୱାଇପ୍ କରନ୍ତୁ।"
142     },
143     {
144       "ਗੁਰਮੁਖੀ",
145       "(Punjabi)",
146       "ਇਹ ਫੋਲਡਰ ਅਤੇ ਇਸ ਵਿੱਚ ਸ਼ਾਮਲ ਸਾਰੇ ਆਈਟਮਾਂ ਨੂੰ ਮਿਟਾ ਦੇਵੇਗਾ।"
147     },
148     {
149       "Português",
150       "(Portuguese)",
151       "Para reorganizar páginas, é necessário alterar o tipo de exibição para uma grade personalizável."
152     },
153     {
154       "සිංහල",
155       "(Sinhala)",
156       "පිටු නැවත පෙළ ගැස්වීම සඳහා ඔබ විසින් දසුන් ප්‍රවර්ගය අභිමතීකෘත්‍ය ජාලයකට වෙනස් කළ යුතුය."
157     },
158     {
159       "தமிழ்",
160       "(Tamil)",
161       "பக்கங்களை மறுஒழுங்குபடுத்தவென காட்சி வகையை தனிப்பயனாக்கத்தக்க கட்டமைப்பிற்கு மாற்ற வேண்டியுள்ளது."
162     },
163     {
164       "తెలుగు",
165       "(Telugu)",
166       "మరిన్ని అప్లికేషన్‌లను జోడించడం సాధ్యం కాలేదు. గరిష్ట అప్లికేషన్‌ల సంఖ్యను చేరుకున్నాయి."
167     },
168     {
169       "ภาษาไทย",
170       "(Thai)",
171       "คุณต้องเปลี่ยนชนิดการแสดง เป็นตารางที่กำหนดเองได้ เพื่อจัดหน้าใหม่"
172     },
173     {
174       "Tagalog",
175       "(Tagalog)",
176       "Hindi makapagdagdag ng extra na linya dahil sa paghihigpit sa espasyo"
177     },
178     {
179       "Türkçe",
180       "(Turkish)",
181       "Sayfaları yeniden düzenlemek için özelleştirilebilir kılavuzun görünüm tipini değiştirmeniz gerekir."
182     },
183     {
184       "اُردُو‎",
185       "(Urdu)",
186       "صفحات کو دوبارہ ترتیب دینے کے لئے، آپ کو منظر کی قسم کو ایک حسب ضرورت گرڈ میں تبدیل کرنا ہوگا۔"
187     },
188     {
189       "tiếng Việt",
190       "(Vietnamese)",
191       "Để sắp xếp lại các trang, bạn cần thay đổi kiểu xem sang dạng lưới tùy chỉnh."
192     },
193     {
194       "漢語",
195       "(Chinese)",
196       "若要重新排列页面,您需要将视图类型更改为可自定义网格。"
197     },
198   };
199
200   const unsigned int NUMBER_OF_LANGUAGES = 31u;
201 } // namespace
202
203 /**
204  * @brief The main class of the demo.
205  */
206 class TextLabelMultiLanguageExample : public ConnectionTracker
207 {
208 public:
209
210   TextLabelMultiLanguageExample( Application& application )
211   : mApplication( application ),
212     mLastPoint( 0.f )
213   {
214     // Connect to the Application's Init signal
215     mApplication.InitSignal().Connect( this, &TextLabelMultiLanguageExample::Create );
216   }
217
218   ~TextLabelMultiLanguageExample()
219   {
220     // Nothing to do here.
221   }
222
223   /**
224    * One-time setup in response to Application InitSignal.
225    */
226   void Create( Application& application )
227   {
228     Stage stage = Stage::GetCurrent();
229
230     stage.KeyEventSignal().Connect(this, &TextLabelMultiLanguageExample::OnKeyEvent);
231
232     mLayout = VerticalLayout::New();
233     mLayout.SetParentOrigin( ParentOrigin::TOP_LEFT );
234     mLayout.SetAnchorPoint( AnchorPoint::TOP_LEFT );
235
236     stage.Add( mLayout );
237
238     for( unsigned int index = 0u; index < NUMBER_OF_LANGUAGES; ++index )
239     {
240       const Language& language = LANGUAGES[index];
241
242       TextLabel label = TextLabel::New();
243       label.SetParentOrigin( ParentOrigin::CENTER );
244
245       label.SetProperty( TextLabel::PROPERTY_MULTI_LINE, true );
246
247       const std::string text = language.languageName + " " + language.languageRomanName + " " + language.text;
248
249       label.SetProperty( TextLabel::PROPERTY_TEXT, text );
250       mLayout.AddLabel( label );
251
252       mLayout.TouchedSignal().Connect( this, &TextLabelMultiLanguageExample::OnTouchEvent );
253     }
254
255     const Vector2& size = Stage::GetCurrent().GetSize();
256     const float height = mLayout.GetHeightForWidth( size.width );
257     mLayout.SetSize( Size( size.width, height ) );
258   }
259
260   bool OnTouchEvent( Actor actor, const TouchEvent& event )
261   {
262     if( 1u == event.GetPointCount() )
263     {
264       const TouchPoint::State state = event.GetPoint(0u).state;
265
266       // Clamp to integer values; this is to reduce flicking due to pixel misalignment
267       const float localPoint = static_cast<float>( static_cast<int>( event.GetPoint( 0 ).local.y ) );
268
269       if( TouchPoint::Down == state )
270       {
271         mLastPoint = localPoint;
272         mAnimation = Animation::New( 0.25f );
273       }
274       else if( TouchPoint::Motion == state )
275       {
276         if( mAnimation )
277         {
278           mAnimation.MoveBy( mLayout, Vector3( 0.f, localPoint - mLastPoint, 0.f ), AlphaFunctions::Linear );
279           mAnimation.Play();
280           mLastPoint = localPoint;
281         }
282       }
283     }
284
285     return true;
286   }
287
288   /**
289    * Main key event handler
290    */
291   void OnKeyEvent(const KeyEvent& event)
292   {
293     if(event.state == KeyEvent::Down)
294     {
295       if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
296       {
297         mApplication.Quit();
298       }
299     }
300   }
301
302 private:
303
304   Application&   mApplication;
305   VerticalLayout mLayout;
306   Animation      mAnimation;
307   float          mLastPoint;
308 };
309
310 void RunTest( Application& application )
311 {
312   TextLabelMultiLanguageExample test( application );
313
314   application.MainLoop();
315 }
316
317 /** Entry point for Linux & Tizen applications */
318 int main( int argc, char **argv )
319 {
320   Application application = Application::New( &argc, &argv );
321
322   RunTest( application );
323
324   return 0;
325 }