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>
31 #include "shadow-button.h"
36 using namespace Dali::Toolkit;
40 void SetLabelText(Button button, const char* label)
42 button.SetProperty(Toolkit::Button::Property::LABEL, label);
49 const char* TransitionApplication::DEMO_THEME_ONE_PATH(DEMO_STYLE_DIR "style-example-theme-one.json");
50 const char* TransitionApplication::DEMO_THEME_TWO_PATH(DEMO_STYLE_DIR "style-example-theme-two.json");
52 TransitionApplication::TransitionApplication(Application& application)
53 : mApplication(application),
57 mVisualIndex(Property::INVALID_INDEX),
58 mActionIndex(Property::INVALID_INDEX)
60 application.InitSignal().Connect(this, &TransitionApplication::Create);
63 TransitionApplication::~TransitionApplication()
67 void TransitionApplication::Create(Application& application)
69 Window window = application.GetWindow();
70 window.KeyEventSignal().Connect(this, &TransitionApplication::OnKeyEvent);
71 window.SetBackgroundColor(Vector4(0.1f, 0.1f, 0.1f, 1.0f));
74 TableView contentLayout = TableView::New(3, 1);
75 contentLayout.SetProperty(Dali::Actor::Property::NAME, "ContentLayout");
76 contentLayout.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
77 contentLayout.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
78 contentLayout.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
79 contentLayout.SetCellPadding(Vector2(0.0f, 5.0f));
80 contentLayout.SetBackgroundColor(Vector4(0.949, 0.949, 0.949, 1.0));
81 // Assign all rows the size negotiation property of fitting to children
83 window.Add(contentLayout);
85 mTitle = TextLabel::New("Custom Control Transition Example");
86 mTitle.SetProperty(Dali::Actor::Property::NAME, "Title");
87 mTitle.SetStyleName("Title");
88 mTitle.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
89 mTitle.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT);
90 mTitle.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER");
91 contentLayout.Add(mTitle);
92 contentLayout.SetFitHeight(0); // Fill width
94 // Provide some padding around the center cell
95 TableView buttonLayout = TableView::New(3, 3);
96 buttonLayout.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
97 buttonLayout.SetFixedHeight(1, 100);
98 buttonLayout.SetFixedWidth(1, 350);
99 contentLayout.Add(buttonLayout);
101 mShadowButton = ShadowButton::New();
102 mShadowButton.SetProperty(Dali::Actor::Property::NAME, "ShadowButton");
103 mShadowButton.SetActiveState(false);
104 mShadowButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
105 mShadowButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
106 mShadowButton.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
107 mShadowButton.SetProperty(DevelControl::Property::STATE, DevelControl::DISABLED);
108 mShadowButton.SetProperty(DevelControl::Property::SUB_STATE, "UNCHECKED");
110 buttonLayout.AddChild(mShadowButton, TableView::CellPosition(1, 1));
112 TableView actionButtonLayout = TableView::New(1, NUMBER_OF_ACTION_BUTTONS + 1);
113 actionButtonLayout.SetProperty(Dali::Actor::Property::NAME, "ThemeButtonsLayout");
114 actionButtonLayout.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
115 actionButtonLayout.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT);
116 actionButtonLayout.SetFitHeight(0);
118 TextLabel label = TextLabel::New("Action: ");
119 label.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
120 label.SetStyleName("ActionLabel");
121 actionButtonLayout.AddChild(label, TableView::CellPosition(0, 0));
122 actionButtonLayout.SetCellAlignment(TableView::CellPosition(0, 0), HorizontalAlignment::LEFT, VerticalAlignment::CENTER);
124 for(int i = 0; i < NUMBER_OF_ACTION_BUTTONS; ++i)
126 mActionButtons[i] = PushButton::New();
127 mActionButtons[i].SetProperty(Dali::Actor::Property::NAME, "ActionButton");
128 mActionButtons[i].SetStyleName("ActionButton");
129 mActionButtons[i].SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
130 mActionButtons[i].SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT);
131 mActionIndex = mActionButtons[i].RegisterProperty("actionId", i, Property::READ_WRITE);
132 mActionButtons[i].ClickedSignal().Connect(this, &TransitionApplication::OnActionButtonClicked);
133 actionButtonLayout.AddChild(mActionButtons[i], TableView::CellPosition(0, 1 + i));
135 SetLabelText(mActionButtons[0], "Enable");
136 SetLabelText(mActionButtons[1], "Check");
137 mActionButtons[1].SetProperty(Button::Property::DISABLED, true);
139 contentLayout.Add(actionButtonLayout);
140 contentLayout.SetFitHeight(2);
143 bool TransitionApplication::OnActionButtonClicked(Button button)
145 int action = button.GetProperty<int>(mActionIndex);
150 bool activeState = mShadowButton.GetActiveState();
151 mShadowButton.SetActiveState(!activeState);
154 SetLabelText(button, "Enable");
155 mShadowButton.SetProperty(DevelControl::Property::STATE, DevelControl::DISABLED);
159 SetLabelText(button, "Disable");
160 mShadowButton.SetProperty(DevelControl::Property::STATE, DevelControl::NORMAL);
162 mActionButtons[1].SetProperty(Button::Property::DISABLED, activeState);
167 bool checkState = mShadowButton.GetCheckState();
168 mShadowButton.SetCheckState(!checkState);
171 SetLabelText(button, "Check");
172 mShadowButton.SetProperty(DevelControl::Property::SUB_STATE, "UNCHECKED");
176 SetLabelText(button, "Uncheck");
177 mShadowButton.SetProperty(DevelControl::Property::SUB_STATE, "CHECKED");
194 void TransitionApplication::OnKeyEvent(const KeyEvent& keyEvent)
196 static int keyPressed = 0;
198 if(keyEvent.GetState() == KeyEvent::DOWN)
200 if(keyPressed == 0) // Is this the first down event?
202 printf("Key pressed: %s %d\n", keyEvent.GetKeyName().c_str(), keyEvent.GetKeyCode());
204 if(IsKey(keyEvent, DALI_KEY_ESCAPE) || IsKey(keyEvent, DALI_KEY_BACK))
208 else if(keyEvent.GetKeyName().compare("Return") == 0)
214 else if(keyEvent.GetState() == KeyEvent::UP)