[NUI][API8] Add Constraint base + inhouse ResizePolicyType.KeepSizeFollowingParent...
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / Constraint.cs
1 /*
2  * Copyright(c) 2021 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 using System.ComponentModel;
19 namespace Tizen.NUI
20 {
21     using global::System;
22     using global::System.Runtime.InteropServices;
23
24     /// <summary>
25     /// An abstract base class for Constraints.
26     /// This class only use for inhouse currently.
27     /// 
28     /// This can be used to constrain a property of an object, after animations have been applied.
29     /// Constraints are applied in the following order:
30     ///  - Constraints are applied to on-stage views in a depth-first traversal.
31     ///  - For each view, the constraints are applied in the same order as the calls to Apply().
32     ///  - Constraints are not applied to off-stage views.
33     /// 
34     /// Create a constraint using one of the New method depending on the type of callback functions used.
35     /// 
36     /// Note : This function will called every frame. Maybe reduce performance if you applyed too many constraints.
37     /// 
38     /// TODO : AddSource(ConstraintSource); API need to be implemented.
39     ///   To implement this, we have to bind ConstraintSource.
40     /// TODO : Currently We don't support custom functions.
41     ///   To implement this, we have to bind PropertyInputContainer
42     /// </summary>
43     internal class Constraint : BaseHandle
44     {
45         internal Constraint(IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
46         {
47         }
48
49         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Constraint obj)
50         {
51             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
52         }
53
54         /// <summary>
55         /// Apply current constraint.
56         /// Constraint will work until Remove called.
57         /// </summary>
58         internal void Apply()
59         {
60             Interop.Constraint.Apply(SwigCPtr);
61             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
62         }
63         /// <summary>
64         /// Remove current constraint.
65         /// </summary>
66         internal void Remove()
67         {
68             Interop.Constraint.Remove(SwigCPtr);
69             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
70         }
71
72
73         /// <summary>
74         /// Remove action. Determine the target values action after remove current constriant.
75         /// Default is RemoveActionType.Bake
76         /// </summary>
77         internal RemoveActionType RemoveAction
78         {
79             set => Interop.Constraint.SetRemoveAction(SwigCPtr, (int)value);
80             get => (RemoveActionType) Interop.Constraint.GetRemoveAction(SwigCPtr);
81         }
82         
83         /// <summary>
84         /// Tag number. It will be useful when you want to seperate constraints
85         /// </summary>
86         internal uint Tag
87         {
88             set => Interop.Constraint.SetTag(SwigCPtr, value);
89             get => Interop.Constraint.GetTag(SwigCPtr);
90         }
91
92         /// <summary>
93         /// Get constrainted target object
94         /// </summary>
95         internal BaseHandle GetTargetObject()
96         {
97             BaseHandle handle = new BaseHandle(Interop.Constraint.GetTargetObject(SwigCPtr), true);
98             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
99             return handle;
100         }
101         /// <summary>
102         /// Get constrainted target property index
103         /// </summary>
104         internal int GetTargetPropert()
105         {
106             int index = Interop.Constraint.GetTargetProperty(SwigCPtr);
107             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
108             return index;
109         }
110
111         /// <summary>
112         /// Dispose
113         /// </summary>
114         /// <param name="type"></param>
115         [EditorBrowsable(EditorBrowsableState.Never)]
116         protected override void Dispose(DisposeTypes type)
117         {
118             if(disposed)
119             {
120                 return;
121             }
122             if(type == DisposeTypes.Explicit)
123             {
124                 //Called by User
125                 //Release your own managed resources here.
126                 //You should release all of your own disposable objects here.
127             }
128             base.Dispose(type);
129         }
130
131         /// This will not be public opened.
132         [EditorBrowsable(EditorBrowsableState.Never)]
133         protected override void ReleaseSwigCPtr(HandleRef swigCPtr)
134         {
135             Interop.Constraint.DeleteConstraint(swigCPtr);
136             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
137         }
138         
139         /// <summary>
140         /// Determinate how objects property will be when constraint removed.
141         /// Default is Bake.
142         /// </summary>
143         internal enum RemoveActionType
144         {
145             /// <summary>
146             /// Target objects property will bake when constraint removed.
147             /// </summary>
148             [EditorBrowsable(EditorBrowsableState.Never)]
149             Bake,
150             /// <summary>
151             /// Target objects property will be original value when constraint removed.
152             /// </summary>
153             [EditorBrowsable(EditorBrowsableState.Never)]
154             Discard,
155         }
156     }
157 }