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;
42 const char* ICON_IMAGE( DEMO_IMAGE_DIR "application-icon-13.png" );
44 SimpleVisualsApplication::SimpleVisualsApplication( Application& application )
45 : mApplication( application ),
48 application.InitSignal().Connect( this, &SimpleVisualsApplication::Create );
51 Dali::Actor SimpleVisualsApplication::OnKeyboardPreFocusChange( Dali::Actor current, Dali::Actor proposed, Dali::Toolkit::Control::KeyboardFocus::Direction direction )
53 Actor nextFocusActor = proposed;
55 if( !current && !proposed )
57 // Set the initial focus to the first tile in the current page should be focused.
58 nextFocusActor = mMyControl;
62 if ( current == mMyControl )
64 nextFocusActor = mMyControl2;
68 nextFocusActor = mMyControl;
72 return nextFocusActor;
76 void SimpleVisualsApplication::OnKeyEvent( const KeyEvent& keyEvent )
78 static int keyPressed = 0;
80 if( keyEvent.GetState() == KeyEvent::DOWN)
82 if( keyPressed == 0 ) // Is this the first down event?
84 printf("Key pressed: %s %d\n", keyEvent.GetKeyName().c_str(), keyEvent.GetKeyCode() );
86 if( IsKey( keyEvent, DALI_KEY_ESCAPE) || IsKey( keyEvent, DALI_KEY_BACK ) )
90 else if( keyEvent.GetKeyName().compare("Return") == 0 )
96 else if( keyEvent.GetState() == KeyEvent::UP )
102 void SimpleVisualsApplication::Create( Application& application )
104 Window window = application.GetWindow();
105 window.SetBackgroundColor( Vector4( 0.1f, 0.1f, 0.1f, 1.0f ) );
107 // Connect to key events so can quit application
108 window.KeyEventSignal().Connect(this, &SimpleVisualsApplication::OnKeyEvent);
110 // Create a table view to parent the 2 MyControls
111 TableView contentLayout = TableView::New( 2, 2 );
112 contentLayout.SetProperty( Dali::Actor::Property::NAME,"ContentLayout");
113 contentLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
114 contentLayout.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::HEIGHT );
115 contentLayout.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 1.0f, .5f, 1.0f ) );
116 contentLayout.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
117 contentLayout.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
118 contentLayout.SetCellPadding( Vector2( 50.0f, 15.0f ) );
119 contentLayout.SetBackgroundColor( Vector4(0.949, 0.949, 0.949, 1.0) );
121 // Listen to focus change so can see Visual change from NORMAL to FOCUSED state
122 KeyboardFocusManager::Get().PreFocusChangeSignal().Connect( this, &SimpleVisualsApplication::OnKeyboardPreFocusChange );
124 window.Add( contentLayout );
126 // Create 2 MyControls and add to table view.
127 mMyControl = MyControl::New();
128 mMyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
129 mMyControl.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
131 mMyControl2 = MyControl::New();
132 mMyControl2.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
133 mMyControl2.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
135 contentLayout.AddChild( mMyControl2, TableView::CellPosition(0, 0) );
136 contentLayout.AddChild( mMyControl, TableView::CellPosition(0, 1) );