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.
18 #include "my-control.h"
21 #include <dali-toolkit/dali-toolkit.h>
22 #include <dali-toolkit/devel-api/controls/table-view/table-view.h>
23 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
24 #include <dali/integration-api/events/touch-event-integ.h>
29 #include "simple-visuals-application.h"
32 using namespace Dali::Toolkit;
40 const char* ICON_IMAGE(DEMO_IMAGE_DIR "application-icon-13.png");
42 SimpleVisualsApplication::SimpleVisualsApplication(Application& application)
43 : mApplication(application),
46 application.InitSignal().Connect(this, &SimpleVisualsApplication::Create);
49 Dali::Actor SimpleVisualsApplication::OnKeyboardPreFocusChange(Dali::Actor current, Dali::Actor proposed, Dali::Toolkit::Control::KeyboardFocus::Direction direction)
51 Actor nextFocusActor = proposed;
53 if(!current && !proposed)
55 // Set the initial focus to the first tile in the current page should be focused.
56 nextFocusActor = mMyControl;
60 if(current == mMyControl)
62 nextFocusActor = mMyControl2;
66 nextFocusActor = mMyControl;
70 return nextFocusActor;
73 void SimpleVisualsApplication::OnKeyEvent(const KeyEvent& keyEvent)
75 static int keyPressed = 0;
77 if(keyEvent.GetState() == KeyEvent::DOWN)
79 if(keyPressed == 0) // Is this the first down event?
81 printf("Key pressed: %s %d\n", keyEvent.GetKeyName().c_str(), keyEvent.GetKeyCode());
83 if(IsKey(keyEvent, DALI_KEY_ESCAPE) || IsKey(keyEvent, DALI_KEY_BACK))
87 else if(keyEvent.GetKeyName().compare("Return") == 0)
93 else if(keyEvent.GetState() == KeyEvent::UP)
99 void SimpleVisualsApplication::Create(Application& application)
101 Window window = application.GetWindow();
102 window.SetBackgroundColor(Vector4(0.1f, 0.1f, 0.1f, 1.0f));
104 // Connect to key events so can quit application
105 window.KeyEventSignal().Connect(this, &SimpleVisualsApplication::OnKeyEvent);
107 // Create a table view to parent the 2 MyControls
108 TableView contentLayout = TableView::New(2, 2);
109 contentLayout.SetProperty(Dali::Actor::Property::NAME, "ContentLayout");
110 contentLayout.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
111 contentLayout.SetResizePolicy(ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::HEIGHT);
112 contentLayout.SetProperty(Actor::Property::SIZE_MODE_FACTOR, Vector3(1.0f, .5f, 1.0f));
113 contentLayout.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
114 contentLayout.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
115 contentLayout.SetCellPadding(Vector2(50.0f, 15.0f));
116 contentLayout.SetBackgroundColor(Vector4(0.949, 0.949, 0.949, 1.0));
118 // Listen to focus change so can see Visual change from NORMAL to FOCUSED state
119 KeyboardFocusManager::Get().PreFocusChangeSignal().Connect(this, &SimpleVisualsApplication::OnKeyboardPreFocusChange);
121 window.Add(contentLayout);
123 // Create 2 MyControls and add to table view.
124 mMyControl = MyControl::New();
125 mMyControl.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
126 mMyControl.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
128 mMyControl2 = MyControl::New();
129 mMyControl2.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
130 mMyControl2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
132 contentLayout.AddChild(mMyControl2, TableView::CellPosition(0, 0));
133 contentLayout.AddChild(mMyControl, TableView::CellPosition(0, 1));