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-table-view.h"
22 #include <dali/devel-api/actors/actor-devel.h>
23 #include <dali/devel-api/images/distance-field.h>
24 #include <dali-toolkit/devel-api/controls/control-devel.h>
25 #include <dali-toolkit/devel-api/shader-effects/alpha-discard-effect.h>
26 #include <dali-toolkit/devel-api/shader-effects/distance-field-effect.h>
27 #include <dali-toolkit/dali-toolkit.h>
28 #include <dali-toolkit/devel-api/accessibility-manager/accessibility-manager.h>
29 #include <dali-toolkit/devel-api/controls/table-view/table-view.h>
30 #include <dali-toolkit/devel-api/shader-effects/alpha-discard-effect.h>
31 #include <dali-toolkit/devel-api/shader-effects/distance-field-effect.h>
32 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
33 #include <dali/devel-api/actors/actor-devel.h>
34 #include <dali/devel-api/images/distance-field.h>
38 #include "shared/execute-process.h"
39 #include "shared/utility.h"
40 #include "shared/view.h"
43 using namespace Dali::Toolkit;
45 ///////////////////////////////////////////////////////////////////////////////
49 const std::string LOGO_PATH(DEMO_IMAGE_DIR "Logo-for-demo.png");
51 // Keyboard focus effect constants.
52 const float KEYBOARD_FOCUS_ANIMATION_DURATION = 1.0f; ///< The total duration of the keyboard focus animation
53 const int32_t KEYBOARD_FOCUS_ANIMATION_LOOP_COUNT = 5; ///< The number of loops for the keyboard focus animation
54 const float KEYBOARD_FOCUS_FINAL_SCALE_FLOAT = 1.05f; ///< The final scale of the focus highlight
55 const float KEYBOARD_FOCUS_ANIMATED_SCALE_FLOAT = 1.18f; ///< The scale of the focus highlight during the animation
56 const float KEYBOARD_FOCUS_FINAL_ALPHA = 0.7f; ///< The final alpha of the focus highlight
57 const float KEYBOARD_FOCUS_ANIMATING_ALPHA = 0.0f; ///< The alpha of the focus highlight during the animation
58 const float KEYBOARD_FOCUS_FADE_PERCENTAGE = 0.16f; ///< The duration of the fade (from translucent to the final-alpha) as a percentage of the overall animation duration
59 const Vector3 KEYBOARD_FOCUS_FINAL_SCALE(KEYBOARD_FOCUS_FINAL_SCALE_FLOAT, KEYBOARD_FOCUS_FINAL_SCALE_FLOAT, KEYBOARD_FOCUS_FINAL_SCALE_FLOAT); ///< @see KEYBOARD_FOCUS_START_SCALE_FLOAT
60 const Vector3 FOCUS_INDICATOR_ANIMATING_SCALE(KEYBOARD_FOCUS_ANIMATED_SCALE_FLOAT, KEYBOARD_FOCUS_ANIMATED_SCALE_FLOAT, KEYBOARD_FOCUS_ANIMATED_SCALE_FLOAT); ///< @see KEYBOARD_FOCUS_END_SCALE_FLOAT
61 const float KEYBOARD_FOCUS_MID_KEY_FRAME_TIME = KEYBOARD_FOCUS_ANIMATION_DURATION - (KEYBOARD_FOCUS_ANIMATION_DURATION * KEYBOARD_FOCUS_FADE_PERCENTAGE); ///< Time of the mid key-frame
63 const float TILE_LABEL_PADDING = 8.0f; ///< Border between edge of tile and the example text
64 const float BUTTON_PRESS_ANIMATION_TIME = 0.35f; ///< Time to perform button scale effect.
65 const int EXAMPLES_PER_ROW = 3;
66 const int ROWS_PER_PAGE = 3;
67 const int EXAMPLES_PER_PAGE = EXAMPLES_PER_ROW * ROWS_PER_PAGE;
68 const Vector3 TABLE_RELATIVE_SIZE(0.95f, 0.9f, 0.8f); ///< TableView's relative size to the entire stage. The Y value means sum of the logo and table relative heights.
70 const char* const DEMO_BUILD_DATE = __DATE__ " " __TIME__;
73 * Creates the background image
75 Actor CreateBackground(std::string stylename)
77 Control background = Control::New();
78 background.SetStyleName(stylename);
79 background.SetProperty(Actor::Property::NAME, "BACKGROUND");
80 background.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
81 background.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
82 background.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
87 * Constraint to precalculate values from the scroll-view
88 * and tile positions to pass to the tile shader.
90 struct TileShaderPositionConstraint
92 TileShaderPositionConstraint(float pageWidth, float tileXOffset)
93 : mPageWidth(pageWidth),
94 mTileXOffset(tileXOffset)
98 void operator()(Vector3& position, const PropertyInputContainer& inputs)
100 // Set up position.x as the tiles X offset (0.0 -> 1.0).
101 position.x = mTileXOffset;
102 // Set up position.z as the linear scroll-view X offset (0.0 -> 1.0).
103 position.z = 1.0f * (-fmod(inputs[0]->GetVector2().x, mPageWidth) / mPageWidth);
104 // Set up position.y as a rectified version of the scroll-views X offset.
105 // IE. instead of 0.0 -> 1.0, it moves between 0.0 -> 0.5 -> 0.0 within the same span.
106 if(position.z > 0.5f)
108 position.y = 1.0f - position.z;
112 position.y = position.z;
122 * Creates a popup that shows the version information of the DALi libraries and demo
124 Dali::Toolkit::Popup CreateVersionPopup(Application& application, ConnectionTrackerInterface& connectionTracker)
126 std::ostringstream stream;
127 stream << "DALi Core: " << CORE_MAJOR_VERSION << "." << CORE_MINOR_VERSION << "." << CORE_MICRO_VERSION << std::endl
128 << "(" << CORE_BUILD_DATE << ")\n";
129 stream << "DALi Adaptor: " << ADAPTOR_MAJOR_VERSION << "." << ADAPTOR_MINOR_VERSION << "." << ADAPTOR_MICRO_VERSION << std::endl
130 << "(" << ADAPTOR_BUILD_DATE << ")\n";
131 stream << "DALi Toolkit: " << TOOLKIT_MAJOR_VERSION << "." << TOOLKIT_MINOR_VERSION << "." << TOOLKIT_MICRO_VERSION << std::endl
132 << "(" << TOOLKIT_BUILD_DATE << ")\n";
133 stream << "DALi Demo:"
134 << "\n(" << DEMO_BUILD_DATE << ")\n";
136 Dali::Toolkit::Popup popup = Dali::Toolkit::Popup::New();
138 Toolkit::TextLabel titleActor = Toolkit::TextLabel::New("Version information");
139 titleActor.SetProperty(Actor::Property::NAME, "titleActor");
140 titleActor.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::CENTER);
141 titleActor.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE);
143 Toolkit::TextLabel contentActor = Toolkit::TextLabel::New(stream.str());
144 contentActor.SetProperty(Actor::Property::NAME, "contentActor");
145 contentActor.SetProperty(Toolkit::TextLabel::Property::MULTI_LINE, true);
146 contentActor.SetProperty(Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::CENTER);
147 contentActor.SetProperty(Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE);
148 contentActor.SetProperty(Actor::Property::PADDING, Padding(0.0f, 0.0f, 20.0f, 0.0f));
150 popup.SetTitle(titleActor);
151 popup.SetContent(contentActor);
153 popup.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH);
154 popup.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(0.75f, 1.0f, 1.0f));
155 popup.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT);
157 application.GetWindow().Add(popup);
159 // Hide the popup when touched outside
160 popup.OutsideTouchedSignal().Connect(
164 if(popup && (popup.GetDisplayState() == Toolkit::Popup::SHOWN))
166 popup.SetDisplayState(Popup::HIDDEN);
173 /// Sets up the inner cube effect
174 Dali::Toolkit::ScrollViewEffect SetupInnerPageCubeEffect(const Vector2 windowSize, int totalPages)
176 Dali::Path path = Dali::Path::New();
177 Dali::Property::Array points;
179 points[0] = Vector3(windowSize.x * 0.5, 0.0f, windowSize.x * 0.5f);
180 points[1] = Vector3(0.0f, 0.0f, 0.0f);
181 points[2] = Vector3(-windowSize.x * 0.5f, 0.0f, windowSize.x * 0.5f);
182 path.SetProperty(Path::Property::POINTS, points);
184 Dali::Property::Array controlPoints;
185 controlPoints.Resize(4);
186 controlPoints[0] = Vector3(windowSize.x * 0.5f, 0.0f, windowSize.x * 0.3f);
187 controlPoints[1] = Vector3(windowSize.x * 0.3f, 0.0f, 0.0f);
188 controlPoints[2] = Vector3(-windowSize.x * 0.3f, 0.0f, 0.0f);
189 controlPoints[3] = Vector3(-windowSize.x * 0.5f, 0.0f, windowSize.x * 0.3f);
190 path.SetProperty(Path::Property::CONTROL_POINTS, controlPoints);
192 return ScrollViewPagePathEffect::New(path,
193 Vector3(-1.0f, 0.0f, 0.0f),
194 Toolkit::ScrollView::Property::SCROLL_FINAL_X,
195 Vector3(windowSize.x * TABLE_RELATIVE_SIZE.x, windowSize.y * TABLE_RELATIVE_SIZE.y, 0.0f),
199 /// Sets up the scroll view rulers
200 void SetupScrollViewRulers(ScrollView& scrollView, const uint16_t windowWidth, const float pageWidth, const int totalPages)
202 // Update Ruler info. for the scroll-view
203 Dali::Toolkit::RulerPtr rulerX = new FixedRuler(pageWidth);
204 Dali::Toolkit::RulerPtr rulerY = new DefaultRuler();
205 rulerX->SetDomain(RulerDomain(0.0f, (totalPages + 1) * windowWidth * TABLE_RELATIVE_SIZE.x * 0.5f, true));
207 scrollView.SetRulerX(rulerX);
208 scrollView.SetRulerY(rulerY);
213 DaliTableView::DaliTableView(Application& application)
214 : mApplication(application),
227 mSortAlphabetically(false)
229 application.InitSignal().Connect(this, &DaliTableView::Initialize);
232 void DaliTableView::AddExample(Example example)
234 mExampleList.push_back(example);
237 void DaliTableView::SortAlphabetically(bool sortAlphabetically)
239 mSortAlphabetically = sortAlphabetically;
242 void DaliTableView::Initialize(Application& application)
244 Window window = application.GetWindow();
245 window.KeyEventSignal().Connect(this, &DaliTableView::OnKeyEvent);
246 const Window::WindowSize windowSize = window.GetSize();
249 mRootActor = CreateBackground("LauncherBackground");
250 window.Add(mRootActor);
253 ImageView logo = ImageView::New(LOGO_PATH);
254 logo.SetProperty(Actor::Property::NAME, "LOGO_IMAGE");
255 logo.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER);
256 logo.SetProperty(Actor::Property::PARENT_ORIGIN, Vector3(0.5f, 0.1f, 0.5f));
257 logo.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
258 // The logo should appear on top of everything.
259 logo.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
260 mRootActor.Add(logo);
262 // Show version in a popup when log is tapped
263 mLogoTapDetector = TapGestureDetector::New();
264 mLogoTapDetector.Attach(logo);
265 mLogoTapDetector.DetectedSignal().Connect(this, &DaliTableView::OnLogoTapped);
267 // Scrollview occupying the majority of the screen
268 mScrollView = ScrollView::New();
269 mScrollView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER);
270 mScrollView.SetProperty(Actor::Property::PARENT_ORIGIN, Vector3(0.5f, 1.0f - 0.05f, 0.5f));
271 mScrollView.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
272 mScrollView.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::HEIGHT);
273 mScrollView.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(0.0f, 0.6f, 0.0f));
275 const float buttonsPageMargin = (1.0f - TABLE_RELATIVE_SIZE.x) * 0.5f * windowSize.GetWidth();
276 mScrollView.SetProperty(Actor::Property::PADDING, Padding(buttonsPageMargin, buttonsPageMargin, 0.0f, 0.0f));
278 mScrollView.SetAxisAutoLock(true);
279 mScrollView.ScrollCompletedSignal().Connect(this, &DaliTableView::OnScrollComplete);
280 mScrollView.ScrollStartedSignal().Connect(this, &DaliTableView::OnScrollStart);
281 mScrollView.TouchedSignal().Connect(this, &DaliTableView::OnScrollTouched);
283 mPageWidth = windowSize.GetWidth() * TABLE_RELATIVE_SIZE.x * 0.5f;
285 mBubbleAnimator.Initialize(mRootActor, mScrollView);
287 mRootActor.Add(mScrollView);
289 // Add scroll view effect and setup constraints on pages
290 ApplyScrollViewEffect();
292 // Add pages and tiles
295 // Remove constraints for inner cube effect
296 ApplyCubeEffectToPages();
298 Dali::Window winHandle = application.GetWindow();
300 if(windowSize.GetWidth() <= windowSize.GetHeight())
302 winHandle.AddAvailableOrientation(Dali::WindowOrientation::PORTRAIT);
303 winHandle.RemoveAvailableOrientation(Dali::WindowOrientation::LANDSCAPE);
304 winHandle.AddAvailableOrientation(Dali::WindowOrientation::PORTRAIT_INVERSE);
305 winHandle.RemoveAvailableOrientation(Dali::WindowOrientation::LANDSCAPE_INVERSE);
309 winHandle.AddAvailableOrientation(Dali::WindowOrientation::LANDSCAPE);
310 winHandle.RemoveAvailableOrientation(Dali::WindowOrientation::PORTRAIT);
311 winHandle.AddAvailableOrientation(Dali::WindowOrientation::LANDSCAPE_INVERSE);
312 winHandle.RemoveAvailableOrientation(Dali::WindowOrientation::PORTRAIT_INVERSE);
318 void DaliTableView::CreateFocusEffect()
320 // Hook the required signals to manage the focus.
321 auto keyboardFocusManager = KeyboardFocusManager::Get();
322 keyboardFocusManager.PreFocusChangeSignal().Connect(this, &DaliTableView::OnKeyboardPreFocusChange);
323 keyboardFocusManager.FocusedActorEnterKeySignal().Connect(this, &DaliTableView::OnFocusedActorActivated);
325 // Loop to create both actors for the focus highlight effect.
326 for(unsigned int i = 0; i < FOCUS_ANIMATION_ACTOR_NUMBER; ++i)
328 mFocusEffect[i].actor = ImageView::New();
329 mFocusEffect[i].actor.SetStyleName("FocusActor");
330 mFocusEffect[i].actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
331 mFocusEffect[i].actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
332 mFocusEffect[i].actor.SetProperty(Actor::Property::INHERIT_SCALE, false);
333 mFocusEffect[i].actor.SetProperty(Actor::Property::COLOR_MODE, USE_OWN_COLOR);
335 KeyFrames alphaKeyFrames = KeyFrames::New();
336 alphaKeyFrames.Add(0.0f, KEYBOARD_FOCUS_FINAL_ALPHA);
337 alphaKeyFrames.Add(KEYBOARD_FOCUS_MID_KEY_FRAME_TIME, KEYBOARD_FOCUS_ANIMATING_ALPHA);
338 alphaKeyFrames.Add(KEYBOARD_FOCUS_ANIMATION_DURATION, KEYBOARD_FOCUS_FINAL_ALPHA);
340 KeyFrames scaleKeyFrames = KeyFrames::New();
341 scaleKeyFrames.Add(0.0f, KEYBOARD_FOCUS_FINAL_SCALE);
342 scaleKeyFrames.Add(KEYBOARD_FOCUS_MID_KEY_FRAME_TIME, FOCUS_INDICATOR_ANIMATING_SCALE);
343 scaleKeyFrames.Add(KEYBOARD_FOCUS_ANIMATION_DURATION, KEYBOARD_FOCUS_FINAL_SCALE);
345 mFocusEffect[i].animation = Animation::New(KEYBOARD_FOCUS_ANIMATION_DURATION);
346 mFocusEffect[i].animation.AnimateBetween(Property(mFocusEffect[i].actor, Actor::Property::COLOR_ALPHA), alphaKeyFrames);
347 mFocusEffect[i].animation.AnimateBetween(Property(mFocusEffect[i].actor, Actor::Property::SCALE), scaleKeyFrames);
349 mFocusEffect[i].animation.SetLoopCount(KEYBOARD_FOCUS_ANIMATION_LOOP_COUNT);
352 // Parent the secondary effect from the primary.
353 mFocusEffect[0].actor.Add(mFocusEffect[1].actor);
355 keyboardFocusManager.SetFocusIndicatorActor(mFocusEffect[0].actor);
357 // Connect to the on & off scene signals of the indicator which represents when it is enabled & disabled respectively
358 mFocusEffect[0].actor.OnSceneSignal().Connect(this, &DaliTableView::OnFocusIndicatorEnabled);
359 mFocusEffect[0].actor.OffSceneSignal().Connect(this, &DaliTableView::OnFocusIndicatorDisabled);
362 void DaliTableView::OnFocusIndicatorEnabled(Actor /* actor */)
364 // Play the animation on the 1st glow object.
365 mFocusEffect[0].animation.Play();
367 // Stagger the animation on the 2nd glow object half way through.
368 mFocusEffect[1].animation.PlayFrom(KEYBOARD_FOCUS_ANIMATION_DURATION / 2.0f);
371 void DaliTableView::OnFocusIndicatorDisabled(Dali::Actor /* actor */)
373 // Stop the focus effect animations
374 for(auto i = 0u; i < FOCUS_ANIMATION_ACTOR_NUMBER; ++i)
376 mFocusEffect[i].animation.Stop();
380 void DaliTableView::ApplyCubeEffectToPages()
382 ScrollViewPagePathEffect effect = ScrollViewPagePathEffect::DownCast(mScrollViewEffect);
383 unsigned int pageCount(0);
384 for(std::vector<Actor>::iterator pageIter = mPages.begin(); pageIter != mPages.end(); ++pageIter)
386 Actor page = *pageIter;
387 effect.ApplyToPage(page, pageCount++);
391 void DaliTableView::Populate()
393 const Window::WindowSize windowSize = mApplication.GetWindow().GetSize();
395 mTotalPages = (mExampleList.size() + EXAMPLES_PER_PAGE - 1) / EXAMPLES_PER_PAGE;
397 // Populate ScrollView.
398 if(mExampleList.size() > 0)
400 if(mSortAlphabetically)
402 sort(mExampleList.begin(), mExampleList.end(), [](auto& lhs, auto& rhs)->bool { return lhs.title < rhs.title; } );
405 unsigned int exampleCount = 0;
406 ExampleListConstIter iter = mExampleList.begin();
408 for(int t = 0; t < mTotalPages && iter != mExampleList.end(); t++)
411 TableView page = TableView::New(ROWS_PER_PAGE, EXAMPLES_PER_ROW);
412 page.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
413 page.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
414 page.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
415 mScrollView.Add(page);
417 // Calculate the number of images going across (columns) within a page, according to the screen resolution and dpi.
418 const float margin = 2.0f;
419 const float tileParentMultiplier = 1.0f / EXAMPLES_PER_ROW;
421 for(int row = 0; row < ROWS_PER_PAGE && iter != mExampleList.end(); row++)
423 for(int column = 0; column < EXAMPLES_PER_ROW && iter != mExampleList.end(); column++)
425 const Example& example = (*iter);
427 // Calculate the tiles relative position on the page (between 0 & 1 in each dimension).
428 Vector2 position(static_cast<float>(column) / (EXAMPLES_PER_ROW - 1.0f), static_cast<float>(row) / (EXAMPLES_PER_ROW - 1.0f));
429 Actor tile = CreateTile(example.name, example.title, Vector3(tileParentMultiplier, tileParentMultiplier, 1.0f), position);
430 AccessibilityManager accessibilityManager = AccessibilityManager::Get();
431 accessibilityManager.SetFocusOrder(tile, ++exampleCount);
432 accessibilityManager.SetAccessibilityAttribute(tile, Dali::Toolkit::AccessibilityManager::ACCESSIBILITY_LABEL, example.title);
433 accessibilityManager.SetAccessibilityAttribute(tile, Dali::Toolkit::AccessibilityManager::ACCESSIBILITY_TRAIT, "Tile");
434 accessibilityManager.SetAccessibilityAttribute(tile, Dali::Toolkit::AccessibilityManager::ACCESSIBILITY_HINT, "You can run this example");
436 tile.SetProperty(Actor::Property::PADDING, Padding(margin, margin, margin, margin));
437 page.AddChild(tile, TableView::CellPosition(row, column));
443 mPages.push_back(page);
447 SetupScrollViewRulers(mScrollView, windowSize.GetWidth(), mPageWidth, mTotalPages);
450 Actor DaliTableView::CreateTile(const std::string& name, const std::string& title, const Dali::Vector3& sizeMultiplier, Vector2& position)
452 Toolkit::ImageView focusableTile = ImageView::New();
454 focusableTile.SetStyleName("DemoTile");
455 focusableTile.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
456 focusableTile.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS);
457 focusableTile.SetProperty(Actor::Property::SIZE_MODE_FACTOR, sizeMultiplier);
458 focusableTile.SetProperty(Actor::Property::NAME, name);
460 // Set the tile to be keyboard focusable
461 focusableTile.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
463 // Register a property with the ImageView. This allows us to inject the scroll-view position into the shader.
464 Property::Value value = Vector3(0.0f, 0.0f, 0.0f);
465 Property::Index propertyIndex = focusableTile.RegisterProperty("uCustomPosition", value);
467 // We create a constraint to perform a precalculation on the scroll-view X offset
468 // and pass it to the shader uniform, along with the tile's position.
469 Constraint shaderPosition = Constraint::New<Vector3>(focusableTile, propertyIndex, TileShaderPositionConstraint(mPageWidth, position.x));
470 shaderPosition.AddSource(Source(mScrollView, ScrollView::Property::SCROLL_POSITION));
471 shaderPosition.SetRemoveAction(Constraint::DISCARD);
472 shaderPosition.Apply();
473 //focusableTile.Add( tileContent );
475 // Create an ImageView for the 9-patch border around the tile.
476 ImageView borderImage = ImageView::New();
477 borderImage.SetStyleName("DemoTileBorder");
478 borderImage.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
479 borderImage.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
480 borderImage.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
481 borderImage.SetProperty(Actor::Property::OPACITY, 0.8f);
482 DevelControl::AppendAccessibilityRelation(borderImage, focusableTile, Accessibility::RelationType::CONTROLLED_BY);
483 focusableTile.Add(borderImage);
485 TextLabel label = TextLabel::New();
486 label.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
487 label.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
488 label.SetStyleName("LauncherLabel");
489 label.SetProperty(TextLabel::Property::MULTI_LINE, true);
490 label.SetProperty(TextLabel::Property::TEXT, title);
491 label.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER");
492 label.SetProperty(TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER");
493 label.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
495 // Pad around the label as its size is the same as the 9-patch border. It will overlap it without padding.
496 label.SetProperty(Actor::Property::PADDING, Padding(TILE_LABEL_PADDING, TILE_LABEL_PADDING, TILE_LABEL_PADDING, TILE_LABEL_PADDING));
497 DevelControl::AppendAccessibilityRelation(label, focusableTile, Accessibility::RelationType::CONTROLLED_BY);
498 focusableTile.Add(label);
500 // Connect to the touch events
501 focusableTile.TouchedSignal().Connect(this, &DaliTableView::OnTilePressed);
502 focusableTile.HoveredSignal().Connect(this, &DaliTableView::OnTileHovered);
503 focusableTile.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::PUSH_BUTTON);
504 DevelControl::AccessibilityActivateSignal(focusableTile).Connect(this, [=](){
505 DoTilePress(focusableTile, PointState::DOWN);
506 DoTilePress(focusableTile, PointState::UP);
509 return focusableTile;
512 bool DaliTableView::OnTilePressed(Actor actor, const TouchEvent& event)
514 return DoTilePress(actor, event.GetState(0));
517 bool DaliTableView::DoTilePress(Actor actor, PointState::Type pointState)
519 bool consumed = false;
521 if(PointState::DOWN == pointState)
523 mPressedActor = actor;
527 // A button press is only valid if the Down & Up events
528 // both occurred within the button.
529 if((PointState::UP == pointState) &&
530 (mPressedActor == actor))
532 // ignore Example button presses when scrolling or button animating.
533 if((!mScrolling) && (!mPressedAnimation))
535 std::string name = actor.GetProperty<std::string>(Dali::Actor::Property::NAME);
536 for(Example& example : mExampleList)
538 if(example.name == name)
540 // do nothing, until pressed animation finished.
549 mPressedAnimation = Animation::New(BUTTON_PRESS_ANIMATION_TIME);
550 mPressedAnimation.SetEndAction(Animation::DISCARD);
552 // scale the content actor within the Tile, as to not affect the placement within the Table.
553 Actor content = actor.GetChildAt(0);
554 mPressedAnimation.AnimateTo(Property(content, Actor::Property::SCALE), Vector3(0.7f, 0.7f, 1.0f), AlphaFunction::EASE_IN_OUT, TimePeriod(0.0f, BUTTON_PRESS_ANIMATION_TIME * 0.5f));
555 mPressedAnimation.AnimateTo(Property(content, Actor::Property::SCALE), Vector3::ONE, AlphaFunction::EASE_IN_OUT, TimePeriod(BUTTON_PRESS_ANIMATION_TIME * 0.5f, BUTTON_PRESS_ANIMATION_TIME * 0.5f));
557 // Rotate button on the Y axis when pressed.
558 mPressedAnimation.AnimateBy(Property(content, Actor::Property::ORIENTATION), Quaternion(Degree(0.0f), Degree(180.0f), Degree(0.0f)));
560 mPressedAnimation.Play();
561 mPressedAnimation.FinishedSignal().Connect(this, &DaliTableView::OnPressedAnimationFinished);
567 void DaliTableView::OnPressedAnimationFinished(Dali::Animation& source)
569 mPressedAnimation.Reset();
572 std::string name = mPressedActor.GetProperty<std::string>(Dali::Actor::Property::NAME);
574 ExecuteProcess(name, mApplication);
576 mPressedActor.Reset();
580 void DaliTableView::OnScrollStart(const Dali::Vector2& position)
584 mBubbleAnimator.PlayAnimation();
587 void DaliTableView::OnScrollComplete(const Dali::Vector2& position)
591 // move focus to 1st item of new page
592 AccessibilityManager accessibilityManager = AccessibilityManager::Get();
593 accessibilityManager.SetCurrentFocusActor(mPages[mScrollView.GetCurrentPage()].GetChildAt(0));
596 bool DaliTableView::OnScrollTouched(Actor actor, const TouchEvent& event)
598 if(PointState::DOWN == event.GetState(0))
600 mPressedActor = actor;
606 void DaliTableView::ApplyScrollViewEffect()
608 // Remove old effect if exists.
610 if(mScrollViewEffect)
612 mScrollView.RemoveEffect(mScrollViewEffect);
615 // Just one effect for now
616 mScrollViewEffect = SetupInnerPageCubeEffect(mApplication.GetWindow().GetSize(), mTotalPages);
618 mScrollView.ApplyEffect(mScrollViewEffect);
621 void DaliTableView::OnKeyEvent(const KeyEvent& event)
623 if(event.GetState() == KeyEvent::DOWN)
625 if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK))
627 // If there's a Popup, Hide it if it's contributing to the display in any way (EG. transitioning in or out).
629 if(mVersionPopup && (mVersionPopup.GetDisplayState() != Toolkit::Popup::HIDDEN))
631 mVersionPopup.SetDisplayState(Popup::HIDDEN);
641 Dali::Actor DaliTableView::OnKeyboardPreFocusChange(Dali::Actor current, Dali::Actor proposed, Dali::Toolkit::Control::KeyboardFocus::Direction direction)
643 Actor nextFocusActor = proposed;
645 if(!current && !proposed)
647 // Set the initial focus to the first tile in the current page should be focused.
648 nextFocusActor = mPages[mScrollView.GetCurrentPage()].GetChildAt(0);
652 // ScrollView is being focused but nothing in the current page can be focused further
653 // in the given direction. We should work out which page to scroll to next.
654 int currentPage = mScrollView.GetCurrentPage();
655 int newPage = currentPage;
656 if(direction == Dali::Toolkit::Control::KeyboardFocus::LEFT)
660 else if(direction == Dali::Toolkit::Control::KeyboardFocus::RIGHT)
665 newPage = std::max(0, std::min(mTotalPages - 1, newPage));
666 if(newPage == currentPage)
668 if(direction == Dali::Toolkit::Control::KeyboardFocus::LEFT)
670 newPage = mTotalPages - 1;
672 else if(direction == Dali::Toolkit::Control::KeyboardFocus::RIGHT)
678 // Scroll to the page in the given direction
679 mScrollView.ScrollTo(newPage);
681 if(direction == Dali::Toolkit::Control::KeyboardFocus::LEFT)
683 // Work out the cell position for the last tile
684 int remainingExamples = mExampleList.size() - newPage * EXAMPLES_PER_PAGE;
685 int rowPos = (remainingExamples >= EXAMPLES_PER_PAGE) ? ROWS_PER_PAGE - 1 : ((remainingExamples % EXAMPLES_PER_PAGE + EXAMPLES_PER_ROW) / EXAMPLES_PER_ROW - 1);
686 int colPos = remainingExamples >= EXAMPLES_PER_PAGE ? EXAMPLES_PER_ROW - 1 : (remainingExamples % EXAMPLES_PER_PAGE - rowPos * EXAMPLES_PER_ROW - 1);
688 // Move the focus to the last tile in the new page.
689 nextFocusActor = mPages[newPage].GetChildAt(rowPos * EXAMPLES_PER_ROW + colPos);
693 // Move the focus to the first tile in the new page.
694 nextFocusActor = mPages[newPage].GetChildAt(0);
698 return nextFocusActor;
701 void DaliTableView::OnFocusedActorActivated(Dali::Actor activatedActor)
705 mPressedActor = activatedActor;
707 // Activate the current focused actor;
708 DoTilePress(mPressedActor, PointState::UP);
712 bool DaliTableView::OnTileHovered(Actor actor, const HoverEvent& event)
714 KeyboardFocusManager::Get().SetCurrentFocusActor(actor);
718 void DaliTableView::OnLogoTapped(Dali::Actor actor, const Dali::TapGesture& tap)
720 // Only show if currently fully hidden. If transitioning-out, the transition will not be interrupted.
721 if(!mVersionPopup || (mVersionPopup.GetDisplayState() == Toolkit::Popup::HIDDEN))
725 mVersionPopup = CreateVersionPopup(mApplication, *this);
728 mVersionPopup.SetDisplayState(Popup::SHOWN);