2 * Copyright(c) 2021 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 using System.ComponentModel;
19 using System.Collections.Generic;
20 using Tizen.NUI.Binding;
22 namespace Tizen.NUI.BaseComponents
25 /// The base class for Children attributes in Components.
27 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
28 [EditorBrowsable(EditorBrowsableState.Never)]
29 public partial class ViewStyle : BindableObject, IDisposable
31 private bool disposed = false;
32 private bool? focusable;
33 private bool? positionUsesPivotPoint;
34 private Position parentOrigin;
35 private Position pivotPoint;
36 private Position position;
37 private Rotation orientation;
38 private DrawModeType? drawMode;
39 private Vector3 sizeModeFactor;
40 private ResizePolicyType? widthResizePolicy;
41 private ResizePolicyType? heightResizePolicy;
42 private bool? widthForHeight;
43 private bool? heightForWidth;
44 private Extents padding;
45 private Size2D minimumSize;
46 private Size2D maximumSize;
47 private ClippingModeType? clippingMode;
49 private Extents margin;
50 private bool? themeChangeSensitive;
51 private float? cornerRadius;
53 private Selector<ImageShadow> imageShadow;
54 private Selector<Shadow> boxShadow;
55 private Selector<string> backgroundImageSelector;
56 private Selector<float?> opacitySelector;
57 private Selector<Color> backgroundColorSelector;
58 private Selector<Rectangle> backgroundImageBorderSelector;
59 private Selector<Color> colorSelector;
60 private VisualTransformPolicyType? cornerRadiusPolicy;
62 static ViewStyle() { }
64 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
65 [EditorBrowsable(EditorBrowsableState.Never)]
66 public ViewStyle() { }
68 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
69 [EditorBrowsable(EditorBrowsableState.Never)]
70 public ViewStyle(ViewStyle viewAttributes)
72 CopyFrom(viewAttributes);
75 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
76 [EditorBrowsable(EditorBrowsableState.Never)]
77 public Selector<string> BackgroundImage
81 Selector<string> image = (Selector<string>)GetValue(BackgroundImageSelectorProperty);
82 return (null != image) ? image : backgroundImageSelector = new Selector<string>();
84 set => SetValue(BackgroundImageSelectorProperty, value);
87 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
88 [EditorBrowsable(EditorBrowsableState.Never)]
89 public bool? Focusable
91 get => (bool?)GetValue(FocusableProperty);
92 set => SetValue(FocusableProperty, value);
95 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
96 [Obsolete("Deprecated. Please use Size instead.")]
97 [EditorBrowsable(EditorBrowsableState.Never)]
100 get => (Size2D)GetValue(Size2DProperty);
101 set => SetValue(Size2DProperty, value);
104 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
105 [EditorBrowsable(EditorBrowsableState.Never)]
106 public Selector<float?> Opacity
110 Selector<float?> opacity = (Selector<float?>)GetValue(OpacitySelectorProperty);
111 return (null != opacity) ? opacity : opacitySelector = new Selector<float?>();
113 set => SetValue(OpacitySelectorProperty, value);
116 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
117 [Obsolete("Deprecated. Please use Position instead.")]
118 [EditorBrowsable(EditorBrowsableState.Never)]
119 public Position2D Position2D
121 get => (Position2D)GetValue(Position2DProperty);
122 set => SetValue(Position2DProperty, value);
125 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
126 [EditorBrowsable(EditorBrowsableState.Never)]
127 public bool? PositionUsesPivotPoint
129 get => (bool?)GetValue(PositionUsesPivotPointProperty);
130 set => SetValue(PositionUsesPivotPointProperty, value);
133 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
134 [EditorBrowsable(EditorBrowsableState.Never)]
135 public Position ParentOrigin
137 get => (Position)GetValue(ParentOriginProperty);
138 set => SetValue(ParentOriginProperty, value);
141 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
142 [EditorBrowsable(EditorBrowsableState.Never)]
143 public Position PivotPoint
145 get => (Position)GetValue(PivotPointProperty);
146 set => SetValue(PivotPointProperty, value);
149 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
150 [EditorBrowsable(EditorBrowsableState.Never)]
151 public float? SizeWidth
153 get => (float?)GetValue(SizeWidthProperty);
154 set => SetValue(SizeWidthProperty, value);
157 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
158 [EditorBrowsable(EditorBrowsableState.Never)]
159 public float? SizeHeight
161 get => (float?)GetValue(SizeHeightProperty);
162 set => SetValue(SizeHeightProperty, value);
165 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
166 [EditorBrowsable(EditorBrowsableState.Never)]
167 public Position Position
169 get => (Position)GetValue(PositionProperty);
170 set => SetValue(PositionProperty, value);
173 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
174 [EditorBrowsable(EditorBrowsableState.Never)]
175 public float? PositionX
177 get => (float?)GetValue(PositionXProperty);
178 set => SetValue(PositionXProperty, value);
181 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
182 [EditorBrowsable(EditorBrowsableState.Never)]
183 public float? PositionY
185 get => (float?)GetValue(PositionYProperty);
186 set => SetValue(PositionYProperty, value);
189 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
190 [EditorBrowsable(EditorBrowsableState.Never)]
191 public Rotation Orientation
193 get => (Rotation)GetValue(OrientationProperty);
194 set => SetValue(OrientationProperty, value);
197 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
198 [EditorBrowsable(EditorBrowsableState.Never)]
199 public DrawModeType? DrawMode
201 get => (DrawModeType?)GetValue(DrawModeProperty);
202 set => SetValue(DrawModeProperty, value);
205 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
206 [EditorBrowsable(EditorBrowsableState.Never)]
207 public Vector3 SizeModeFactor
209 get => (Vector3)GetValue(SizeModeFactorProperty);
210 set => SetValue(SizeModeFactorProperty, value);
213 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
214 [EditorBrowsable(EditorBrowsableState.Never)]
215 public ResizePolicyType? WidthResizePolicy
217 get => (ResizePolicyType?)GetValue(WidthResizePolicyProperty);
218 set => SetValue(WidthResizePolicyProperty, value);
221 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
222 [EditorBrowsable(EditorBrowsableState.Never)]
223 public ResizePolicyType? HeightResizePolicy
225 get => (ResizePolicyType?)GetValue(HeightResizePolicyProperty);
226 set => SetValue(HeightResizePolicyProperty, value);
229 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
230 [EditorBrowsable(EditorBrowsableState.Never)]
231 public bool? WidthForHeight
233 get => (bool?)GetValue(WidthForHeightProperty);
234 set => SetValue(WidthForHeightProperty, value);
237 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
238 [EditorBrowsable(EditorBrowsableState.Never)]
239 public bool? HeightForWidth
241 get => (bool?)GetValue(HeightForWidthProperty);
242 set => SetValue(HeightForWidthProperty, value);
245 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
246 [EditorBrowsable(EditorBrowsableState.Never)]
247 public Extents Padding
249 get => (Extents)GetValue(PaddingProperty) ?? (padding = new Extents());
250 set => SetValue(PaddingProperty, value);
253 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
254 [EditorBrowsable(EditorBrowsableState.Never)]
255 public Size2D MinimumSize
257 get => (Size2D)GetValue(MinimumSizeProperty);
258 set => SetValue(MinimumSizeProperty, value);
261 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
262 [EditorBrowsable(EditorBrowsableState.Never)]
263 public Size2D MaximumSize
265 get => (Size2D)GetValue(MaximumSizeProperty);
266 set => SetValue(MaximumSizeProperty, value);
269 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
270 [EditorBrowsable(EditorBrowsableState.Never)]
271 public ClippingModeType? ClippingMode
273 get => (ClippingModeType?)GetValue(ClippingModeProperty);
274 set => SetValue(ClippingModeProperty, value);
277 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
278 [EditorBrowsable(EditorBrowsableState.Never)]
281 get => (Size)GetValue(SizeProperty);
282 set => SetValue(SizeProperty, value);
285 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
286 [EditorBrowsable(EditorBrowsableState.Never)]
287 public Extents Margin
289 get => (Extents)GetValue(MarginProperty) ?? (margin = new Extents());
290 set => SetValue(MarginProperty, value);
293 /// <summary> View BackgroundColor </summary>
294 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
295 [EditorBrowsable(EditorBrowsableState.Never)]
296 public Selector<Color> BackgroundColor
300 Selector<Color> color = (Selector<Color>)GetValue(BackgroundColorSelectorProperty);
301 return (null != color) ? color : backgroundColorSelector = new Selector<Color>();
303 set => SetValue(BackgroundColorSelectorProperty, value);
309 [EditorBrowsable(EditorBrowsableState.Never)]
310 public Selector<Color> Color
312 get => (Selector<Color>)GetValue(ColorSelectorProperty) ?? (colorSelector = new Selector<Color>());
313 set => SetValue(ColorSelectorProperty, value);
316 /// <summary>View BackgroundBorder</summary>
317 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
318 [EditorBrowsable(EditorBrowsableState.Never)]
319 public Selector<Rectangle> BackgroundImageBorder
323 Selector<Rectangle> border = (Selector<Rectangle>)GetValue(BackgroundImageBorderSelectorProperty);
324 return (null != border) ? border : backgroundImageBorderSelector = new Selector<Rectangle>();
326 set => SetValue(BackgroundImageBorderSelectorProperty, value);
330 /// Describes a shadow as an image for a View.
331 /// It is null by default.
334 /// If BoxShadow is not null, the ImageShadow value will be ignored.
336 [EditorBrowsable(EditorBrowsableState.Never)]
337 public Selector<ImageShadow> ImageShadow
339 get => (Selector<ImageShadow>)GetValue(ImageShadowSelectorProperty);
340 set => SetValue(ImageShadowSelectorProperty, value);
344 /// Describes a box shaped shadow drawing for a View.
345 /// It is null by default.
347 [EditorBrowsable(EditorBrowsableState.Never)]
348 public Selector<Shadow> BoxShadow
350 get => (Selector<Shadow>)GetValue(BoxShadowSelectorProperty);
351 set => SetValue(BoxShadowSelectorProperty, value);
355 /// The radius for the rounded corners of the View
357 [EditorBrowsable(EditorBrowsableState.Never)]
358 public float? CornerRadius
360 get => (float?)GetValue(CornerRadiusProperty);
361 set => SetValue(CornerRadiusProperty, value);
365 /// Whether the CornerRadius property value is relative (percentage [0.0f to 1.0f] of the view size) or absolute (in world units).
366 /// It is absolute by default.
367 /// When the policy is relative, the corner radius is relative to the smaller of the view's width and height.
369 [EditorBrowsable(EditorBrowsableState.Never)]
370 public VisualTransformPolicyType? CornerRadiusPolicy
372 get => (VisualTransformPolicyType?)GetValue(CornerRadiusPolicyProperty);
373 set => SetValue(CornerRadiusPolicyProperty, value);
377 /// The ThemeChangeSensitive value of the View.
379 [EditorBrowsable(EditorBrowsableState.Never)]
380 public bool? ThemeChangeSensitive
382 get => (bool?)GetValue(ThemeChangeSensitiveProperty);
383 set => SetValue(ThemeChangeSensitiveProperty, value);
388 /// Allow null properties when merging it into other Theme.
389 /// If the value is true, the null properties reset target properties of the other ViewStyle with same key when merge.
390 /// It is used in <seealso cref="Theme.Merge(string)"/>, <seealso cref="Theme.Merge(Theme)"/>.
391 /// It is also used in <seealso cref="Theme.GetStyle(string)"/> when the Theme has a parent and needs to merge.
392 /// Please note that it is false by default.
394 [EditorBrowsable(EditorBrowsableState.Never)]
395 public bool SolidNull { get; set; } = false;
398 /// HashSet of dirty properties. Internal use only.
400 internal HashSet<BindableProperty> DirtyProperties { get; private set; }
403 /// Set style's bindable properties from the view.
405 /// <param name="view">The view that includes property data.</param>
406 [EditorBrowsable(EditorBrowsableState.Never)]
407 public virtual void CopyPropertiesFromView(View view)
409 if (view == null) return;
411 BindableProperty.GetBindablePropertysOfType(GetType(), out var styleProperties);
412 BindableProperty.GetBindablePropertysOfType(view.GetType(), out var viewProperties);
415 if (styleProperties == null || viewProperties == null) return;
417 foreach (var stylePropertyItem in styleProperties)
419 viewProperties.TryGetValue(stylePropertyItem.Key, out var viewProperty);
421 if (viewProperty == null) continue;
423 SetValue(stylePropertyItem.Value, view.GetValue(viewProperty));
427 /// <summary>Create a cloned ViewStyle.</summary>
428 [EditorBrowsable(EditorBrowsableState.Never)]
429 public ViewStyle Clone()
431 var cloned = CreateInstance();
432 cloned.CopyFrom(this);
437 /// <summary>Create a cloned ViewStyle.</summary>
438 [EditorBrowsable(EditorBrowsableState.Never)]
439 public void Merge(ViewStyle other)
445 /// Release instance.
447 [EditorBrowsable(EditorBrowsableState.Never)]
448 public void Dispose()
451 global::System.GC.SuppressFinalize(this);
454 /// <summary>Copy properties of other ViewStyle to this.</summary>
455 /// <param name="other">The other BindableProperty merge to this.</param>
456 [EditorBrowsable(EditorBrowsableState.Never)]
457 public override void CopyFrom(BindableObject other)
459 var source = other as ViewStyle;
461 if (source == null || source.DirtyProperties == null || source.DirtyProperties.Count == 0)
466 BindableProperty.GetBindablePropertysOfType(GetType(), out var thisBindableProperties);
468 if (thisBindableProperties == null)
473 foreach (var sourceProperty in source.DirtyProperties)
475 var sourceValue = source.GetValue(sourceProperty);
477 if (sourceValue == null)
482 thisBindableProperties.TryGetValue(sourceProperty.PropertyName, out var destinationProperty);
484 if (destinationProperty != null)
486 SetValue(destinationProperty, sourceValue);
492 /// Release instance.
494 [EditorBrowsable(EditorBrowsableState.Never)]
495 protected virtual void Dispose(bool disposing)
504 // Dispose managed state (managed objects).
506 maximumSize?.Dispose();
507 minimumSize?.Dispose();
508 orientation?.Dispose();
510 parentOrigin?.Dispose();
511 pivotPoint?.Dispose();
514 sizeModeFactor?.Dispose();
521 /// Method that is called when a bound property is changed.
523 [EditorBrowsable(EditorBrowsableState.Never)]
524 protected override void OnPropertyChangedWithData(BindableProperty property)
526 base.OnPropertyChangedWithData(property);
528 if (property != null)
530 (DirtyProperties ?? (DirtyProperties = new HashSet<BindableProperty>())).Add(property);
534 internal ViewStyle CreateInstance()
536 return (ViewStyle)Activator.CreateInstance(GetType());