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 * @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/controls/table-view/table-view.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 mVisualIndex( Property::INVALID_INDEX ),
61 mActionIndex( Property::INVALID_INDEX )
63 application.InitSignal().Connect( this, &TransitionApplication::Create );
66 TransitionApplication::~TransitionApplication()
70 void TransitionApplication::Create( Application& application )
72 Window window = application.GetWindow();
73 window.KeyEventSignal().Connect(this, &TransitionApplication::OnKeyEvent);
74 window.SetBackgroundColor( Vector4( 0.1f, 0.1f, 0.1f, 1.0f ) );
77 TableView contentLayout = TableView::New( 3, 1 );
78 contentLayout.SetProperty( Dali::Actor::Property::NAME,"ContentLayout");
79 contentLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
80 contentLayout.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
81 contentLayout.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
82 contentLayout.SetCellPadding( Vector2( 0.0f, 5.0f ) );
83 contentLayout.SetBackgroundColor( Vector4(0.949, 0.949, 0.949, 1.0) );
84 // Assign all rows the size negotiation property of fitting to children
86 window.Add( contentLayout );
88 mTitle = TextLabel::New( "Custom Control Transition Example" );
89 mTitle.SetProperty( Dali::Actor::Property::NAME, "Title" );
90 mTitle.SetStyleName("Title");
91 mTitle.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
92 mTitle.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
93 mTitle.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
94 contentLayout.Add( mTitle );
95 contentLayout.SetFitHeight(0); // Fill width
97 // Provide some padding around the center cell
98 TableView buttonLayout = TableView::New( 3, 3 );
99 buttonLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
100 buttonLayout.SetFixedHeight(1, 100 );
101 buttonLayout.SetFixedWidth(1, 350 );
102 contentLayout.Add( buttonLayout );
104 mShadowButton = ShadowButton::New();
105 mShadowButton.SetProperty( Dali::Actor::Property::NAME,"ShadowButton");
106 mShadowButton.SetActiveState( false );
107 mShadowButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
108 mShadowButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
109 mShadowButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
110 mShadowButton.SetProperty( DevelControl::Property::STATE, DevelControl::DISABLED );
111 mShadowButton.SetProperty( DevelControl::Property::SUB_STATE, "UNCHECKED" );
113 buttonLayout.AddChild( mShadowButton, TableView::CellPosition(1, 1) );
115 TableView actionButtonLayout = TableView::New( 1, NUMBER_OF_ACTION_BUTTONS+1 );
116 actionButtonLayout.SetProperty( Dali::Actor::Property::NAME,"ThemeButtonsLayout");
117 actionButtonLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
118 actionButtonLayout.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT );
119 actionButtonLayout.SetFitHeight( 0 );
121 TextLabel label = TextLabel::New( "Action: ");
122 label.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
123 label.SetStyleName("ActionLabel");
124 actionButtonLayout.AddChild( label, TableView::CellPosition( 0, 0 ) );
125 actionButtonLayout.SetCellAlignment( TableView::CellPosition( 0, 0 ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
127 for( int i=0; i<NUMBER_OF_ACTION_BUTTONS; ++i )
129 mActionButtons[i] = PushButton::New();
130 mActionButtons[i].SetProperty( Dali::Actor::Property::NAME,"ActionButton");
131 mActionButtons[i].SetStyleName("ActionButton");
132 mActionButtons[i].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
133 mActionButtons[i].SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
134 mActionIndex = mActionButtons[i].RegisterProperty( "actionId", i, Property::READ_WRITE );
135 mActionButtons[i].ClickedSignal().Connect( this, &TransitionApplication::OnActionButtonClicked );
136 actionButtonLayout.AddChild( mActionButtons[i], TableView::CellPosition( 0, 1+i ) );
138 SetLabelText( mActionButtons[0], "Enable" );
139 SetLabelText( mActionButtons[1], "Check" );
140 mActionButtons[1].SetProperty( Button::Property::DISABLED, true );
142 contentLayout.Add( actionButtonLayout );
143 contentLayout.SetFitHeight(2);
146 bool TransitionApplication::OnActionButtonClicked( Button button )
148 int action = button.GetProperty<int>( mActionIndex );
153 bool activeState = mShadowButton.GetActiveState();
154 mShadowButton.SetActiveState( ! activeState );
157 SetLabelText( button, "Enable" );
158 mShadowButton.SetProperty( DevelControl::Property::STATE, DevelControl::DISABLED );
162 SetLabelText( button, "Disable" );
163 mShadowButton.SetProperty( DevelControl::Property::STATE, DevelControl::NORMAL );
165 mActionButtons[1].SetProperty( Button::Property::DISABLED, activeState );
170 bool checkState = mShadowButton.GetCheckState();
171 mShadowButton.SetCheckState( ! checkState );
174 SetLabelText( button, "Check" );
175 mShadowButton.SetProperty( DevelControl::Property::SUB_STATE, "UNCHECKED" );
179 SetLabelText( button, "Uncheck" );
180 mShadowButton.SetProperty( DevelControl::Property::SUB_STATE, "CHECKED" );
197 void TransitionApplication::OnKeyEvent( const KeyEvent& keyEvent )
199 static int keyPressed = 0;
201 if( keyEvent.GetState() == KeyEvent::DOWN)
203 if( keyPressed == 0 ) // Is this the first down event?
205 printf("Key pressed: %s %d\n", keyEvent.GetKeyName().c_str(), keyEvent.GetKeyCode() );
207 if( IsKey( keyEvent, DALI_KEY_ESCAPE) || IsKey( keyEvent, DALI_KEY_BACK ) )
211 else if( keyEvent.GetKeyName().compare("Return") == 0 )
217 else if( keyEvent.GetState() == KeyEvent::UP )