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/controls/control-devel.h>
28 #include "shadow-button.h"
35 using namespace Dali::Toolkit;
40 void SetLabelText( Button button, const char* label )
42 button.SetProperty( Toolkit::Button::Property::LABEL, label );
50 const char* TransitionApplication::DEMO_THEME_ONE_PATH( DEMO_STYLE_DIR "style-example-theme-one.json" );
51 const char* TransitionApplication::DEMO_THEME_TWO_PATH( DEMO_STYLE_DIR "style-example-theme-two.json" );
54 TransitionApplication::TransitionApplication( Application& application )
55 : mApplication( application ),
59 mVisualIndex( Property::INVALID_INDEX ),
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 mShadowButton.SetProperty( DevelControl::Property::STATE, DevelControl::DISABLED );
113 mShadowButton.SetProperty( DevelControl::Property::SUB_STATE, "UNCHECKED" );
115 buttonLayout.AddChild( mShadowButton, TableView::CellPosition(1, 1) );
117 TableView actionButtonLayout = TableView::New( 1, NUMBER_OF_ACTION_BUTTONS+1 );
118 actionButtonLayout.SetName("ThemeButtonsLayout");
119 actionButtonLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
120 actionButtonLayout.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT );
121 actionButtonLayout.SetFitHeight( 0 );
123 TextLabel label = TextLabel::New( "Action: ");
124 label.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
125 label.SetStyleName("ActionLabel");
126 actionButtonLayout.AddChild( label, TableView::CellPosition( 0, 0 ) );
127 actionButtonLayout.SetCellAlignment( TableView::CellPosition( 0, 0 ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
129 for( int i=0; i<NUMBER_OF_ACTION_BUTTONS; ++i )
131 mActionButtons[i] = PushButton::New();
132 mActionButtons[i].SetName("ActionButton");
133 mActionButtons[i].SetStyleName("ActionButton");
134 mActionButtons[i].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
135 mActionButtons[i].SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
136 mActionIndex = mActionButtons[i].RegisterProperty( "actionId", i, Property::READ_WRITE );
137 mActionButtons[i].ClickedSignal().Connect( this, &TransitionApplication::OnActionButtonClicked );
138 actionButtonLayout.AddChild( mActionButtons[i], TableView::CellPosition( 0, 1+i ) );
140 SetLabelText( mActionButtons[0], "Enable" );
141 SetLabelText( mActionButtons[1], "Check" );
142 mActionButtons[1].SetProperty( Button::Property::DISABLED, true );
144 contentLayout.Add( actionButtonLayout );
145 contentLayout.SetFitHeight(2);
148 bool TransitionApplication::OnActionButtonClicked( Button button )
150 int action = button.GetProperty<int>( mActionIndex );
155 bool activeState = mShadowButton.GetActiveState();
156 mShadowButton.SetActiveState( ! activeState );
159 SetLabelText( button, "Enable" );
160 mShadowButton.SetProperty( DevelControl::Property::STATE, DevelControl::DISABLED );
164 SetLabelText( button, "Disable" );
165 mShadowButton.SetProperty( DevelControl::Property::STATE, DevelControl::NORMAL );
167 mActionButtons[1].SetProperty( Button::Property::DISABLED, activeState );
172 bool checkState = mShadowButton.GetCheckState();
173 mShadowButton.SetCheckState( ! checkState );
176 SetLabelText( button, "Check" );
177 mShadowButton.SetProperty( DevelControl::Property::SUB_STATE, "UNCHECKED" );
181 SetLabelText( button, "Uncheck" );
182 mShadowButton.SetProperty( DevelControl::Property::SUB_STATE, "CHECKED" );
199 void TransitionApplication::OnKeyEvent( const KeyEvent& keyEvent )
201 static int keyPressed = 0;
203 if( keyEvent.state == KeyEvent::Down)
205 if( keyPressed == 0 ) // Is this the first down event?
207 printf("Key pressed: %s %d\n", keyEvent.keyPressedName.c_str(), keyEvent.keyCode );
209 if( IsKey( keyEvent, DALI_KEY_ESCAPE) || IsKey( keyEvent, DALI_KEY_BACK ) )
213 else if( keyEvent.keyPressedName.compare("Return") == 0 )
219 else if( keyEvent.state == KeyEvent::Up )