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 Tizen.NUI.Binding;
21 namespace Tizen.NUI.BaseComponents
24 /// The base class for Children attributes in Components.
26 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
27 [EditorBrowsable(EditorBrowsableState.Never)]
28 public partial class ViewStyle : BindableObject, IDisposable
30 private bool disposed = false;
31 private bool? focusable;
32 private bool? positionUsesPivotPoint;
33 private Position parentOrigin;
34 private Position pivotPoint;
35 private Position position;
36 private Rotation orientation;
37 private DrawModeType? drawMode;
38 private Vector3 sizeModeFactor;
39 private ResizePolicyType? widthResizePolicy;
40 private ResizePolicyType? heightResizePolicy;
41 private bool? widthForHeight;
42 private bool? heightForWidth;
43 private Extents padding;
44 private Size2D minimumSize;
45 private Size2D maximumSize;
46 private ClippingModeType? clippingMode;
48 private Extents margin;
49 private bool? themeChangeSensitive;
50 private float? cornerRadius;
52 private Selector<ImageShadow> imageShadow;
53 private Selector<Shadow> boxShadow;
54 private Selector<string> backgroundImageSelector;
55 private Selector<float?> opacitySelector;
56 private Selector<Color> backgroundColorSelector;
57 private Selector<Rectangle> backgroundImageBorderSelector;
58 private Selector<Color> colorSelector;
59 private VisualTransformPolicyType? cornerRadiusPolicy;
61 static ViewStyle() { }
63 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
64 [EditorBrowsable(EditorBrowsableState.Never)]
65 public ViewStyle() { }
67 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
68 [EditorBrowsable(EditorBrowsableState.Never)]
69 public ViewStyle(ViewStyle viewAttributes)
71 CopyFrom(viewAttributes);
74 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
75 [EditorBrowsable(EditorBrowsableState.Never)]
76 public Selector<string> BackgroundImage
80 Selector<string> image = (Selector<string>)GetValue(BackgroundImageSelectorProperty);
81 return (null != image) ? image : backgroundImageSelector = new Selector<string>();
83 set => SetValue(BackgroundImageSelectorProperty, value);
86 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
87 [EditorBrowsable(EditorBrowsableState.Never)]
88 public bool? Focusable
90 get => (bool?)GetValue(FocusableProperty);
91 set => SetValue(FocusableProperty, value);
94 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
95 [Obsolete("Deprecated. Please use Size instead.")]
96 [EditorBrowsable(EditorBrowsableState.Never)]
99 get => (Size2D)GetValue(Size2DProperty);
100 set => SetValue(Size2DProperty, value);
103 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
104 [EditorBrowsable(EditorBrowsableState.Never)]
105 public Selector<float?> Opacity
109 Selector<float?> opacity = (Selector<float?>)GetValue(OpacitySelectorProperty);
110 return (null != opacity) ? opacity : opacitySelector = new Selector<float?>();
112 set => SetValue(OpacitySelectorProperty, value);
115 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
116 [Obsolete("Deprecated. Please use Position instead.")]
117 [EditorBrowsable(EditorBrowsableState.Never)]
118 public Position2D Position2D
120 get => (Position2D)GetValue(Position2DProperty);
121 set => SetValue(Position2DProperty, value);
124 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
125 [EditorBrowsable(EditorBrowsableState.Never)]
126 public bool? PositionUsesPivotPoint
128 get => (bool?)GetValue(PositionUsesPivotPointProperty);
129 set => SetValue(PositionUsesPivotPointProperty, value);
132 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
133 [EditorBrowsable(EditorBrowsableState.Never)]
134 public Position ParentOrigin
136 get => (Position)GetValue(ParentOriginProperty);
137 set => SetValue(ParentOriginProperty, value);
140 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
141 [EditorBrowsable(EditorBrowsableState.Never)]
142 public Position PivotPoint
144 get => (Position)GetValue(PivotPointProperty);
145 set => SetValue(PivotPointProperty, value);
148 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
149 [EditorBrowsable(EditorBrowsableState.Never)]
150 public float? SizeWidth
152 get => (float?)GetValue(SizeWidthProperty);
153 set => SetValue(SizeWidthProperty, value);
156 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
157 [EditorBrowsable(EditorBrowsableState.Never)]
158 public float? SizeHeight
160 get => (float?)GetValue(SizeHeightProperty);
161 set => SetValue(SizeHeightProperty, value);
164 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
165 [EditorBrowsable(EditorBrowsableState.Never)]
166 public Position Position
168 get => (Position)GetValue(PositionProperty);
169 set => SetValue(PositionProperty, value);
172 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
173 [EditorBrowsable(EditorBrowsableState.Never)]
174 public float? PositionX
176 get => (float?)GetValue(PositionXProperty);
177 set => SetValue(PositionXProperty, value);
180 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
181 [EditorBrowsable(EditorBrowsableState.Never)]
182 public float? PositionY
184 get => (float?)GetValue(PositionYProperty);
185 set => SetValue(PositionYProperty, value);
188 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
189 [EditorBrowsable(EditorBrowsableState.Never)]
190 public Rotation Orientation
192 get => (Rotation)GetValue(OrientationProperty);
193 set => SetValue(OrientationProperty, value);
196 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
197 [EditorBrowsable(EditorBrowsableState.Never)]
198 public DrawModeType? DrawMode
200 get => (DrawModeType?)GetValue(DrawModeProperty);
201 set => SetValue(DrawModeProperty, value);
204 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
205 [EditorBrowsable(EditorBrowsableState.Never)]
206 public Vector3 SizeModeFactor
208 get => (Vector3)GetValue(SizeModeFactorProperty);
209 set => SetValue(SizeModeFactorProperty, value);
212 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
213 [EditorBrowsable(EditorBrowsableState.Never)]
214 public ResizePolicyType? WidthResizePolicy
216 get => (ResizePolicyType?)GetValue(WidthResizePolicyProperty);
217 set => SetValue(WidthResizePolicyProperty, value);
220 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
221 [EditorBrowsable(EditorBrowsableState.Never)]
222 public ResizePolicyType? HeightResizePolicy
224 get => (ResizePolicyType?)GetValue(HeightResizePolicyProperty);
225 set => SetValue(HeightResizePolicyProperty, value);
228 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
229 [EditorBrowsable(EditorBrowsableState.Never)]
230 public bool? WidthForHeight
232 get => (bool?)GetValue(WidthForHeightProperty);
233 set => SetValue(WidthForHeightProperty, value);
236 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
237 [EditorBrowsable(EditorBrowsableState.Never)]
238 public bool? HeightForWidth
240 get => (bool?)GetValue(HeightForWidthProperty);
241 set => SetValue(HeightForWidthProperty, value);
244 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
245 [EditorBrowsable(EditorBrowsableState.Never)]
246 public Extents Padding
248 get => (Extents)GetValue(PaddingProperty) ?? (padding = new Extents());
249 set => SetValue(PaddingProperty, value);
252 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
253 [EditorBrowsable(EditorBrowsableState.Never)]
254 public Size2D MinimumSize
256 get => (Size2D)GetValue(MinimumSizeProperty);
257 set => SetValue(MinimumSizeProperty, value);
260 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
261 [EditorBrowsable(EditorBrowsableState.Never)]
262 public Size2D MaximumSize
264 get => (Size2D)GetValue(MaximumSizeProperty);
265 set => SetValue(MaximumSizeProperty, value);
268 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
269 [EditorBrowsable(EditorBrowsableState.Never)]
270 public ClippingModeType? ClippingMode
272 get => (ClippingModeType?)GetValue(ClippingModeProperty);
273 set => SetValue(ClippingModeProperty, value);
276 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
277 [EditorBrowsable(EditorBrowsableState.Never)]
280 get => (Size)GetValue(SizeProperty);
281 set => SetValue(SizeProperty, value);
284 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
285 [EditorBrowsable(EditorBrowsableState.Never)]
286 public Extents Margin
288 get => (Extents)GetValue(MarginProperty) ?? (margin = new Extents());
289 set => SetValue(MarginProperty, value);
292 /// <summary> View BackgroundColor </summary>
293 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
294 [EditorBrowsable(EditorBrowsableState.Never)]
295 public Selector<Color> BackgroundColor
299 Selector<Color> color = (Selector<Color>)GetValue(BackgroundColorSelectorProperty);
300 return (null != color) ? color : backgroundColorSelector = new Selector<Color>();
302 set => SetValue(BackgroundColorSelectorProperty, value);
308 [EditorBrowsable(EditorBrowsableState.Never)]
309 public Selector<Color> Color
311 get => (Selector<Color>)GetValue(ColorSelectorProperty) ?? (colorSelector = new Selector<Color>());
312 set => SetValue(ColorSelectorProperty, value);
315 /// <summary>View BackgroundBorder</summary>
316 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
317 [EditorBrowsable(EditorBrowsableState.Never)]
318 public Selector<Rectangle> BackgroundImageBorder
322 Selector<Rectangle> border = (Selector<Rectangle>)GetValue(BackgroundImageBorderSelectorProperty);
323 return (null != border) ? border : backgroundImageBorderSelector = new Selector<Rectangle>();
325 set => SetValue(BackgroundImageBorderSelectorProperty, value);
329 /// Describes a shadow as an image for a View.
330 /// It is null by default.
333 /// If BoxShadow is not null, the ImageShadow value will be ignored.
335 [EditorBrowsable(EditorBrowsableState.Never)]
336 public Selector<ImageShadow> ImageShadow
338 get => (Selector<ImageShadow>)GetValue(ImageShadowSelectorProperty);
339 set => SetValue(ImageShadowSelectorProperty, value);
343 /// Describes a box shaped shadow drawing for a View.
344 /// It is null by default.
346 [EditorBrowsable(EditorBrowsableState.Never)]
347 public Selector<Shadow> BoxShadow
349 get => (Selector<Shadow>)GetValue(BoxShadowSelectorProperty);
350 set => SetValue(BoxShadowSelectorProperty, value);
354 /// The radius for the rounded corners of the View
356 [EditorBrowsable(EditorBrowsableState.Never)]
357 public float? CornerRadius
359 get => (float?)GetValue(CornerRadiusProperty);
360 set => SetValue(CornerRadiusProperty, value);
364 /// Whether the CornerRadius property value is relative (percentage [0.0f to 1.0f] of the view size) or absolute (in world units).
365 /// It is absolute by default.
366 /// When the policy is relative, the corner radius is relative to the smaller of the view's width and height.
368 [EditorBrowsable(EditorBrowsableState.Never)]
369 public VisualTransformPolicyType? CornerRadiusPolicy
371 get => (VisualTransformPolicyType?)GetValue(CornerRadiusPolicyProperty);
372 set => SetValue(CornerRadiusPolicyProperty, value);
376 /// The ThemeChangeSensitive value of the View.
378 [EditorBrowsable(EditorBrowsableState.Never)]
379 public bool? ThemeChangeSensitive
381 get => (bool?)GetValue(ThemeChangeSensitiveProperty);
382 set => SetValue(ThemeChangeSensitiveProperty, value);
387 /// Allow null properties when merging it into other Theme.
388 /// If the value is true, the null properties reset target properties of the other ViewStyle with same key when merge.
389 /// It is used in <seealso cref="Theme.Merge(string)"/>, <seealso cref="Theme.Merge(Theme)"/>.
390 /// It is also used in <seealso cref="Theme.GetStyle(string)"/> when the Theme has a parent and needs to merge.
391 /// Please note that it is false by default.
393 [EditorBrowsable(EditorBrowsableState.Never)]
394 public bool SolidNull { get; set; } = false;
397 /// Set style's bindable properties from the view.
399 /// <param name="view">The view that includes property data.</param>
400 [EditorBrowsable(EditorBrowsableState.Never)]
401 public virtual void CopyPropertiesFromView(View view)
403 if (view == null) return;
405 BindableProperty.GetBindablePropertysOfType(GetType(), out var styleProperties);
406 BindableProperty.GetBindablePropertysOfType(view.GetType(), out var viewProperties);
409 if (styleProperties == null || viewProperties == null) return;
411 foreach (var stylePropertyItem in styleProperties)
413 viewProperties.TryGetValue(stylePropertyItem.Key, out var viewProperty);
415 if (viewProperty == null) continue;
417 SetValue(stylePropertyItem.Value, view.GetValue(viewProperty));
421 /// <summary>Create a cloned ViewStyle.</summary>
422 [EditorBrowsable(EditorBrowsableState.Never)]
423 public ViewStyle Clone()
425 var cloned = CreateInstance();
426 cloned.CopyFrom(this);
431 /// <summary>Create a cloned ViewStyle.</summary>
432 [EditorBrowsable(EditorBrowsableState.Never)]
433 public void Merge(ViewStyle other)
435 AllowNullCopy = other?.SolidNull ?? false;
437 AllowNullCopy = false;
441 /// Release instance.
443 [EditorBrowsable(EditorBrowsableState.Never)]
444 public void Dispose()
447 global::System.GC.SuppressFinalize(this);
451 /// Release instance.
453 [EditorBrowsable(EditorBrowsableState.Never)]
454 protected virtual void Dispose(bool disposing)
463 // Dispose managed state (managed objects).
465 maximumSize?.Dispose();
466 minimumSize?.Dispose();
467 orientation?.Dispose();
469 parentOrigin?.Dispose();
470 pivotPoint?.Dispose();
473 sizeModeFactor?.Dispose();
479 internal ViewStyle CreateInstance()
481 return (ViewStyle)Activator.CreateInstance(GetType());