2 * Copyright (c) 2017 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 * @file transition-application.cpp
19 * @brief Application class for showing stylable transitions
23 #include "transition-application.h"
26 #include <dali-toolkit/dali-toolkit.h>
27 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
28 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
29 #include "shadow-button.h"
36 using namespace Dali::Toolkit;
41 void SetLabelText( Button button, const char* label )
43 button.SetProperty( Toolkit::Button::Property::LABEL, label );
51 const char* TransitionApplication::DEMO_THEME_ONE_PATH( DEMO_STYLE_DIR "style-example-theme-one.json" );
52 const char* TransitionApplication::DEMO_THEME_TWO_PATH( DEMO_STYLE_DIR "style-example-theme-two.json" );
55 TransitionApplication::TransitionApplication( Application& application )
56 : mApplication( application ),
60 mActionIndex( Property::INVALID_INDEX )
62 application.InitSignal().Connect( this, &TransitionApplication::Create );
65 TransitionApplication::~TransitionApplication()
69 void TransitionApplication::Create( Application& application )
71 Stage stage = Stage::GetCurrent();
72 stage.KeyEventSignal().Connect(this, &TransitionApplication::OnKeyEvent);
73 stage.SetBackgroundColor( Vector4( 0.1f, 0.1f, 0.1f, 1.0f ) );
75 // Hide the indicator bar
76 application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE );
79 TableView contentLayout = TableView::New( 3, 1 );
80 contentLayout.SetName("ContentLayout");
81 contentLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
82 contentLayout.SetAnchorPoint( AnchorPoint::TOP_LEFT );
83 contentLayout.SetParentOrigin( ParentOrigin::TOP_LEFT );
84 contentLayout.SetCellPadding( Vector2( 0.0f, 5.0f ) );
85 contentLayout.SetBackgroundColor( Vector4(0.949, 0.949, 0.949, 1.0) );
86 // Assign all rows the size negotiation property of fitting to children
88 stage.Add( contentLayout );
90 mTitle = TextLabel::New( "Custom Control Transition Example" );
91 mTitle.SetName( "Title" );
92 mTitle.SetStyleName("Title");
93 mTitle.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
94 mTitle.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
95 mTitle.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
96 contentLayout.Add( mTitle );
97 contentLayout.SetFitHeight(0); // Fill width
99 // Provide some padding around the center cell
100 TableView buttonLayout = TableView::New( 3, 3 );
101 buttonLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
102 buttonLayout.SetFixedHeight(1, 100 );
103 buttonLayout.SetFixedWidth(1, 350 );
104 contentLayout.Add( buttonLayout );
106 mShadowButton = ShadowButton::New();
107 mShadowButton.SetName("ShadowButton");
108 mShadowButton.SetActiveState( false );
109 mShadowButton.SetAnchorPoint( AnchorPoint::CENTER );
110 mShadowButton.SetParentOrigin( ParentOrigin::CENTER );
111 mShadowButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
112 buttonLayout.AddChild( mShadowButton, TableView::CellPosition(1, 1) );
114 TableView actionButtonLayout = TableView::New( 1, NUMBER_OF_ACTION_BUTTONS+1 );
115 actionButtonLayout.SetName("ThemeButtonsLayout");
116 actionButtonLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
117 actionButtonLayout.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT );
118 actionButtonLayout.SetFitHeight( 0 );
120 TextLabel label = TextLabel::New( "Action: ");
121 label.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
122 label.SetStyleName("ActionLabel");
123 actionButtonLayout.AddChild( label, TableView::CellPosition( 0, 0 ) );
124 actionButtonLayout.SetCellAlignment( TableView::CellPosition( 0, 0 ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
126 for( int i=0; i<NUMBER_OF_ACTION_BUTTONS; ++i )
128 mActionButtons[i] = PushButton::New();
129 mActionButtons[i].SetName("ActionButton");
130 mActionButtons[i].SetStyleName("ActionButton");
131 mActionButtons[i].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
132 mActionButtons[i].SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
133 mActionIndex = mActionButtons[i].RegisterProperty( "actionId", i, Property::READ_WRITE );
134 mActionButtons[i].ClickedSignal().Connect( this, &TransitionApplication::OnActionButtonClicked );
135 actionButtonLayout.AddChild( mActionButtons[i], TableView::CellPosition( 0, 1+i ) );
137 SetLabelText( mActionButtons[0], "Activate" );
138 SetLabelText( mActionButtons[1], "Check" );
139 mActionButtons[1].SetProperty( Button::Property::DISABLED, true );
141 contentLayout.Add( actionButtonLayout );
142 contentLayout.SetFitHeight(2);
145 bool TransitionApplication::OnActionButtonClicked( Button button )
147 int action = button.GetProperty<int>( mActionIndex );
152 bool activeState = mShadowButton.GetActiveState();
153 mShadowButton.SetActiveState( ! activeState );
156 SetLabelText( button, "Activate" );
160 SetLabelText( button, "Deactivate" );
162 mActionButtons[1].SetProperty( Button::Property::DISABLED, activeState );
167 bool checkState = mShadowButton.GetCheckState();
168 mShadowButton.SetCheckState( ! checkState );
171 SetLabelText( button, "Check" );
175 SetLabelText( button, "Uncheck" );
192 void TransitionApplication::OnKeyEvent( const KeyEvent& keyEvent )
194 static int keyPressed = 0;
196 if( keyEvent.state == KeyEvent::Down)
198 if( keyPressed == 0 ) // Is this the first down event?
200 printf("Key pressed: %s %d\n", keyEvent.keyPressedName.c_str(), keyEvent.keyCode );
202 if( IsKey( keyEvent, DALI_KEY_ESCAPE) || IsKey( keyEvent, DALI_KEY_BACK ) )
206 else if( keyEvent.keyPressedName.compare("Return") == 0 )
212 else if( keyEvent.state == KeyEvent::Up )