2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-toolkit/dali-toolkit.h>
20 #include <dali-toolkit/devel-api/controls/table-view/table-view.h>
24 #include "emoji-strings.h"
27 using namespace Dali::Toolkit;
28 using namespace EmojiStrings;
30 // TODO Need to expose Text::RENDER.....
31 const int ATLAS_RENDERER = 0;
33 // This example shows how to create and display Hello World! using a simple TextActor
35 class EmojiExample : public ConnectionTracker
38 typedef uint32_t SizeType;
40 EmojiExample(Application& application)
41 : mApplication(application),
44 std::cout << "EmoticonController::EmoticonController" << std::endl;
46 // Connect to the Application's Init signal
47 mApplication.InitSignal().Connect(this, &EmojiExample::Create);
52 // Nothing to do here;
55 // The Init signal is received once (only) during the Application lifetime
56 void Create(Application& application)
58 Window window = application.GetWindow();
59 window.SetBackgroundColor(Color::WHITE);
60 window.KeyEventSignal().Connect(this, &EmojiExample::OnKeyEvent);
62 mTableView = Toolkit::TableView::New(NUMBER_OF_EMOJIS, 1);
63 mTableView.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
64 mTableView.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT);
65 mTableView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
66 mTableView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
67 mTableView.TouchedSignal().Connect(this, &EmojiExample::OnTouch);
68 window.Add(mTableView);
70 for(unsigned int index = 0u; index < NUMBER_OF_EMOJIS; ++index)
72 const Emoji& emoji = EMOJIS[index];
73 const std::string text = emoji.mUTF8 + " " + emoji.mDescription;
75 TextLabel label = TextLabel::New(text);
76 label.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER);
77 label.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER);
78 label.SetProperty(TextLabel::Property::MULTI_LINE, true);
80 mTableView.SetFitHeight(index);
81 mTableView.AddChild(label, Toolkit::TableView::CellPosition(index, 0));
85 bool OnTouch(Actor actor, const TouchEvent& event)
87 if(1u == event.GetPointCount())
89 const PointState::Type state = event.GetState(0);
91 // Clamp to integer values; this is to reduce flicking due to pixel misalignment
92 const float localPoint = static_cast<float>(static_cast<int>(event.GetLocalPosition(0).y));
94 if(PointState::DOWN == state)
96 mLastPoint = localPoint;
97 mAnimation = Animation::New(0.25f);
99 else if(PointState::MOTION == state)
103 mAnimation.AnimateBy(Property(mTableView, Actor::Property::POSITION), Vector3(0.f, localPoint - mLastPoint, 0.f), AlphaFunction::LINEAR);
105 mLastPoint = localPoint;
114 * Main key event handler
116 void OnKeyEvent(const KeyEvent& event)
118 if(event.GetState() == KeyEvent::DOWN)
120 if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK))
128 Application& mApplication;
129 TableView mTableView;
130 Animation mAnimation;
134 int DALI_EXPORT_API main(int argc, char** argv)
136 Application application = Application::New(&argc, &argv, DEMO_THEME_PATH);
137 EmojiExample test(application);
138 application.MainLoop();