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 <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
29 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
30 #include "shadow-button.h"
37 using namespace Dali::Toolkit;
42 void SetLabelText( Button button, const char* label )
44 button.SetProperty( Toolkit::Button::Property::LABEL, label );
52 const char* TransitionApplication::DEMO_THEME_ONE_PATH( DEMO_STYLE_DIR "style-example-theme-one.json" );
53 const char* TransitionApplication::DEMO_THEME_TWO_PATH( DEMO_STYLE_DIR "style-example-theme-two.json" );
56 TransitionApplication::TransitionApplication( Application& application )
57 : mApplication( application ),
61 mVisualIndex( Property::INVALID_INDEX ),
62 mActionIndex( Property::INVALID_INDEX )
64 application.InitSignal().Connect( this, &TransitionApplication::Create );
67 TransitionApplication::~TransitionApplication()
71 void TransitionApplication::Create( Application& application )
73 Stage stage = Stage::GetCurrent();
74 stage.KeyEventSignal().Connect(this, &TransitionApplication::OnKeyEvent);
75 stage.SetBackgroundColor( Vector4( 0.1f, 0.1f, 0.1f, 1.0f ) );
77 // Hide the indicator bar
78 application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE );
81 TableView contentLayout = TableView::New( 3, 1 );
82 contentLayout.SetName("ContentLayout");
83 contentLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
84 contentLayout.SetAnchorPoint( AnchorPoint::TOP_LEFT );
85 contentLayout.SetParentOrigin( ParentOrigin::TOP_LEFT );
86 contentLayout.SetCellPadding( Vector2( 0.0f, 5.0f ) );
87 contentLayout.SetBackgroundColor( Vector4(0.949, 0.949, 0.949, 1.0) );
88 // Assign all rows the size negotiation property of fitting to children
90 stage.Add( contentLayout );
92 mTitle = TextLabel::New( "Custom Control Transition Example" );
93 mTitle.SetName( "Title" );
94 mTitle.SetStyleName("Title");
95 mTitle.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
96 mTitle.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
97 mTitle.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
98 contentLayout.Add( mTitle );
99 contentLayout.SetFitHeight(0); // Fill width
101 // Provide some padding around the center cell
102 TableView buttonLayout = TableView::New( 3, 3 );
103 buttonLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
104 buttonLayout.SetFixedHeight(1, 100 );
105 buttonLayout.SetFixedWidth(1, 350 );
106 contentLayout.Add( buttonLayout );
108 mShadowButton = ShadowButton::New();
109 mShadowButton.SetName("ShadowButton");
110 mShadowButton.SetActiveState( false );
111 mShadowButton.SetAnchorPoint( AnchorPoint::CENTER );
112 mShadowButton.SetParentOrigin( ParentOrigin::CENTER );
113 mShadowButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
114 mShadowButton.SetProperty( DevelControl::Property::STATE, DevelControl::DISABLED );
115 mShadowButton.SetProperty( DevelControl::Property::SUB_STATE, "UNCHECKED" );
117 buttonLayout.AddChild( mShadowButton, TableView::CellPosition(1, 1) );
119 TableView actionButtonLayout = TableView::New( 1, NUMBER_OF_ACTION_BUTTONS+1 );
120 actionButtonLayout.SetName("ThemeButtonsLayout");
121 actionButtonLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
122 actionButtonLayout.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT );
123 actionButtonLayout.SetFitHeight( 0 );
125 TextLabel label = TextLabel::New( "Action: ");
126 label.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
127 label.SetStyleName("ActionLabel");
128 actionButtonLayout.AddChild( label, TableView::CellPosition( 0, 0 ) );
129 actionButtonLayout.SetCellAlignment( TableView::CellPosition( 0, 0 ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
131 for( int i=0; i<NUMBER_OF_ACTION_BUTTONS; ++i )
133 mActionButtons[i] = PushButton::New();
134 mActionButtons[i].SetName("ActionButton");
135 mActionButtons[i].SetStyleName("ActionButton");
136 mActionButtons[i].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
137 mActionButtons[i].SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
138 mActionIndex = mActionButtons[i].RegisterProperty( "actionId", i, Property::READ_WRITE );
139 mActionButtons[i].ClickedSignal().Connect( this, &TransitionApplication::OnActionButtonClicked );
140 actionButtonLayout.AddChild( mActionButtons[i], TableView::CellPosition( 0, 1+i ) );
142 SetLabelText( mActionButtons[0], "Enable" );
143 SetLabelText( mActionButtons[1], "Check" );
144 mActionButtons[1].SetProperty( Button::Property::DISABLED, true );
146 contentLayout.Add( actionButtonLayout );
147 contentLayout.SetFitHeight(2);
150 bool TransitionApplication::OnActionButtonClicked( Button button )
152 int action = button.GetProperty<int>( mActionIndex );
157 bool activeState = mShadowButton.GetActiveState();
158 mShadowButton.SetActiveState( ! activeState );
161 SetLabelText( button, "Enable" );
162 mShadowButton.SetProperty( DevelControl::Property::STATE, DevelControl::DISABLED );
166 SetLabelText( button, "Disable" );
167 mShadowButton.SetProperty( DevelControl::Property::STATE, DevelControl::NORMAL );
169 mActionButtons[1].SetProperty( Button::Property::DISABLED, activeState );
174 bool checkState = mShadowButton.GetCheckState();
175 mShadowButton.SetCheckState( ! checkState );
178 SetLabelText( button, "Check" );
179 mShadowButton.SetProperty( DevelControl::Property::SUB_STATE, "UNCHECKED" );
183 SetLabelText( button, "Uncheck" );
184 mShadowButton.SetProperty( DevelControl::Property::SUB_STATE, "CHECKED" );
201 void TransitionApplication::OnKeyEvent( const KeyEvent& keyEvent )
203 static int keyPressed = 0;
205 if( keyEvent.state == KeyEvent::Down)
207 if( keyPressed == 0 ) // Is this the first down event?
209 printf("Key pressed: %s %d\n", keyEvent.keyPressedName.c_str(), keyEvent.keyCode );
211 if( IsKey( keyEvent, DALI_KEY_ESCAPE) || IsKey( keyEvent, DALI_KEY_BACK ) )
215 else if( keyEvent.keyPressedName.compare("Return") == 0 )
221 else if( keyEvent.state == KeyEvent::Up )