Formatting API
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / controls / scrollable / scroll-view / scroll-view-constraints.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // INTERNAL INCLUDES
19
20 #include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view-constraints.h>
21 #include <dali/public-api/common/constants.h>
22 #include <dali/public-api/math/math-utils.h>
23 #include <dali/public-api/object/property-input.h>
24
25 using namespace Dali;
26
27 namespace Dali
28 {
29 namespace Toolkit
30 {
31 void MoveActorConstraint(Vector3& current, const PropertyInputContainer& inputs)
32 {
33   current += Vector3(inputs[0]->GetVector2());
34 }
35
36 void WrapActorConstraint(Vector3& position, const PropertyInputContainer& inputs)
37 {
38   bool wrap = inputs[5]->GetBoolean();
39
40   if(wrap)
41   {
42     const Vector2& min = inputs[3]->GetVector2();
43     const Vector2& max = inputs[4]->GetVector2();
44
45     const Vector3& anchor = inputs[1]->GetVector3();
46     const Vector3  scale  = inputs[0]->GetVector3();
47     const Vector3  size   = inputs[2]->GetVector3();
48
49     if(fabsf(min.x - max.x) > Math::MACHINE_EPSILON_1)
50     {
51       // WRAP X (based on the position of the right side)
52       float offsetX = (1.0f - anchor.x) * size.x * scale.x;
53       position.x    = WrapInDomain(position.x + offsetX, min.x, max.x) - offsetX;
54     }
55
56     if(fabsf(min.y - max.y) > Math::MACHINE_EPSILON_1)
57     {
58       // WRAP Y (based on the position of the bottom side)
59       float offsetY = (1.0f - anchor.y) * size.y * scale.y;
60       position.y    = WrapInDomain(position.y + offsetY, min.y, max.y) - offsetY;
61     }
62   }
63 }
64
65 } // namespace Toolkit
66
67 } // namespace Dali