2 * Copyright(c) 2019 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.Runtime.InteropServices;
19 using System.ComponentModel;
20 using Tizen.NUI.Binding;
22 namespace Tizen.NUI.BaseComponents
26 /// ImageView is a class for displaying an image resource.<br />
27 /// An instance of ImageView can be created using a URL or an image instance.<br />
29 /// <since_tizen> 3 </since_tizen>
30 public class ImageView : View
32 static ImageView() { }
34 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
35 [EditorBrowsable(EditorBrowsableState.Never)]
36 public static readonly BindableProperty ResourceUrlProperty = BindableProperty.Create(nameof(ImageView.ResourceUrl), typeof(string), typeof(ImageView), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
38 var imageView = (ImageView)bindable;
40 if (newValue is Selector<string> selector)
42 imageView.ResourceUrlSelector = selector;
46 imageView.resourceUrlSelector?.Reset(imageView);
47 imageView.SetResourceUrl((string)newValue);
50 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
52 var imageView = (ImageView)bindable;
55 PropertyMap imageMap = new PropertyMap();
56 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE).Get(imageMap);
57 imageMap.Find(ImageVisualProperty.URL)?.Get(out ret);
61 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
62 [EditorBrowsable(EditorBrowsableState.Never)]
63 public static readonly BindableProperty ImageProperty = BindableProperty.Create(nameof(ImageView.Image), typeof(PropertyMap), typeof(ImageView), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
65 var imageView = (ImageView)bindable;
68 PropertyMap map = (PropertyMap)newValue;
69 if (imageView.IsCreateByXaml)
71 string url = "", alphaMaskURL = "", auxiliaryImageURL = "";
72 string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
73 PropertyValue urlValue = map.Find(NDalic.ImageVisualUrl);
75 if (urlValue != null) ret = urlValue.Get(out url);
76 PropertyMap mmap = new PropertyMap();
77 if (ret && url.StartsWith("*Resource*"))
79 url = url.Replace("*Resource*", resource);
80 mmap.Insert(NDalic.ImageVisualUrl, new PropertyValue(url));
84 PropertyValue alphaMaskUrlValue = map.Find(NDalic.ImageVisualAlphaMaskUrl);
85 if (alphaMaskUrlValue != null) ret = alphaMaskUrlValue.Get(out alphaMaskURL);
86 if (ret && alphaMaskURL.StartsWith("*Resource*"))
88 alphaMaskURL = alphaMaskURL.Replace("*Resource*", resource);
89 mmap.Insert(NDalic.ImageVisualUrl, new PropertyValue(alphaMaskURL));
93 PropertyValue auxiliaryImageURLValue = map.Find(NDalic.ImageVisualAuxiliaryImageUrl);
94 if (auxiliaryImageURLValue != null) ret = auxiliaryImageURLValue.Get(out auxiliaryImageURL);
95 if (ret && auxiliaryImageURL.StartsWith("*Resource*"))
97 auxiliaryImageURL = auxiliaryImageURL.Replace("*Resource*", resource);
98 mmap.Insert(NDalic.ImageVisualAuxiliaryImageUrl, new PropertyValue(auxiliaryImageURL));
103 if (imageView._border == null)
105 Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(map));
109 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
111 var imageView = (ImageView)bindable;
112 if (imageView._border == null)
114 PropertyMap temp = new PropertyMap();
115 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE).Get(temp);
124 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
125 [EditorBrowsable(EditorBrowsableState.Never)]
126 public static readonly BindableProperty PreMultipliedAlphaProperty = BindableProperty.Create(nameof(PreMultipliedAlpha), typeof(bool), typeof(ImageView), false, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
128 var imageView = (ImageView)bindable;
129 if (newValue != null)
131 Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha, new Tizen.NUI.PropertyValue((bool)newValue));
134 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
136 var imageView = (ImageView)bindable;
138 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha).Get(out temp);
142 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
143 [EditorBrowsable(EditorBrowsableState.Never)]
144 public static readonly BindableProperty PixelAreaProperty = BindableProperty.Create(nameof(PixelArea), typeof(RelativeVector4), typeof(ImageView), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
146 var imageView = (ImageView)bindable;
147 if (newValue != null)
149 Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PixelArea, new Tizen.NUI.PropertyValue((RelativeVector4)newValue));
152 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
154 var imageView = (ImageView)bindable;
155 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
156 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PixelArea).Get(temp);
157 RelativeVector4 relativeTemp = new RelativeVector4(temp.X, temp.Y, temp.Z, temp.W);
161 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
162 [EditorBrowsable(EditorBrowsableState.Never)]
163 public static readonly BindableProperty BorderProperty = BindableProperty.Create(nameof(Border), typeof(Rectangle), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
165 var imageView = (ImageView)bindable;
166 imageView.borderSelector?.Reset(imageView);
168 if (newValue is Selector<Rectangle> selector)
170 if (selector.HasAll()) imageView.SetBorder(selector.All);
171 else imageView.borderSelector = new TriggerableSelector<Rectangle>(imageView, selector, imageView.SetBorder, true);
175 imageView.SetBorder((Rectangle)newValue);
178 defaultValueCreator: (bindable) =>
180 var imageView = (ImageView)bindable;
181 return imageView._border;
184 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
185 [EditorBrowsable(EditorBrowsableState.Never)]
186 public static readonly BindableProperty BorderOnlyProperty = BindableProperty.Create(nameof(BorderOnly), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
188 var imageView = (ImageView)bindable;
189 if (newValue != null)
191 imageView.UpdateImage(NpatchImageVisualProperty.BorderOnly, new PropertyValue((bool)newValue));
194 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
196 var imageView = (ImageView)bindable;
198 PropertyMap imageMap = new PropertyMap();
199 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE).Get(imageMap);
200 imageMap.Find(ImageVisualProperty.BorderOnly)?.Get(out ret);
204 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
205 [EditorBrowsable(EditorBrowsableState.Never)]
206 public static readonly BindableProperty SynchronosLoadingProperty = BindableProperty.Create(nameof(SynchronousLoading), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
208 var imageView = (ImageView)bindable;
209 if (newValue != null)
211 imageView._synchronousLoading = (bool)newValue;
212 imageView.UpdateImage(NpatchImageVisualProperty.SynchronousLoading, new PropertyValue((bool)newValue));
215 defaultValueCreator: (bindable) =>
217 var imageView = (ImageView)bindable;
218 return imageView._synchronousLoading;
221 /// This will be public opened in tizen_7.0 after ACR done. Before ACR, need to be hidden as inhouse API.
222 [EditorBrowsable(EditorBrowsableState.Never)]
223 public static readonly BindableProperty SynchronousLoadingProperty = BindableProperty.Create(nameof(SynchronousLoading), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
225 var imageView = (ImageView)bindable;
226 if (newValue != null)
228 imageView._synchronousLoading = (bool)newValue;
229 imageView.UpdateImage(NpatchImageVisualProperty.SynchronousLoading, new PropertyValue((bool)newValue));
232 defaultValueCreator: (bindable) =>
234 var imageView = (ImageView)bindable;
235 return imageView._synchronousLoading;
238 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
239 [EditorBrowsable(EditorBrowsableState.Never)]
240 public static readonly BindableProperty OrientationCorrectionProperty = BindableProperty.Create(nameof(OrientationCorrection), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
242 var imageView = (ImageView)bindable;
243 if (newValue != null)
245 imageView.UpdateImage(ImageVisualProperty.OrientationCorrection, new PropertyValue((bool)newValue));
248 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
250 var imageView = (ImageView)bindable;
253 PropertyMap imageMap = new PropertyMap();
254 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE).Get(imageMap);
255 imageMap?.Find(ImageVisualProperty.OrientationCorrection)?.Get(out ret);
260 private EventHandler<ResourceReadyEventArgs> _resourceReadyEventHandler;
261 private ResourceReadyEventCallbackType _resourceReadyEventCallback;
262 private EventHandler<ResourceLoadedEventArgs> _resourceLoadedEventHandler;
263 private _resourceLoadedCallbackType _resourceLoadedCallback;
265 private Rectangle _border;
266 private string _resourceUrl = "";
267 private bool _synchronousLoading = false;
268 private string _alphaMaskUrl = null;
269 private int _desired_width = -1;
270 private int _desired_height = -1;
271 private bool _cropToMask = false;
272 private VisualFittingModeType _fittingMode = VisualFittingModeType.Fill;
273 private TriggerableSelector<string> resourceUrlSelector;
274 private TriggerableSelector<Rectangle> borderSelector;
277 /// Creates an initialized ImageView.
279 /// <since_tizen> 3 </since_tizen>
280 public ImageView() : this(Interop.ImageView.New(), true)
282 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
285 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
286 [EditorBrowsable(EditorBrowsableState.Never)]
287 public ImageView(ViewStyle viewStyle) : this(Interop.ImageView.New(), true, viewStyle)
292 /// Creates an initialized ImageView with setting the status of shown or hidden.
294 /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
295 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
296 [EditorBrowsable(EditorBrowsableState.Never)]
297 public ImageView(bool shown) : this(Interop.ImageView.New(), true)
299 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
304 /// Creates an initialized ImageView from a URL to an image resource.<br />
305 /// If the string is empty, ImageView will not display anything.<br />
307 /// <param name="url">The URL of the image resource to display.</param>
308 /// <since_tizen> 3 </since_tizen>
309 public ImageView(string url) : this(Interop.ImageView.New(url), true)
312 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
317 /// Creates an initialized ImageView from a URL to an image resource with setting shown or hidden.
319 /// <param name="url">The URL of the image resource to display.</param>
320 /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
321 /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
322 [EditorBrowsable(EditorBrowsableState.Never)]
323 public ImageView(string url, bool shown) : this(Interop.ImageView.New(url), true)
326 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
330 internal ImageView(string url, Uint16Pair size, bool shown = true) : this(Interop.ImageView.New(url, Uint16Pair.getCPtr(size)), true)
333 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
341 internal ImageView(global::System.IntPtr cPtr, bool cMemoryOwn, ViewStyle viewStyle, bool shown = true) : base(cPtr, cMemoryOwn, viewStyle)
349 internal ImageView(global::System.IntPtr cPtr, bool cMemoryOwn, bool shown = true) : base(cPtr, cMemoryOwn, null)
357 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
358 private delegate void ResourceReadyEventCallbackType(IntPtr data);
359 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
360 private delegate void _resourceLoadedCallbackType(IntPtr view);
363 /// An event for ResourceReady signal which can be used to subscribe or unsubscribe the event handler.<br />
364 /// This signal is emitted after all resources required by a control are loaded and ready.<br />
365 /// Most resources are only loaded when the control is placed on the stage.<br />
367 /// <since_tizen> 3 </since_tizen>
368 public event EventHandler<ResourceReadyEventArgs> ResourceReady
372 if (_resourceReadyEventHandler == null)
374 _resourceReadyEventCallback = OnResourceReady;
375 ViewResourceReadySignal resourceReadySignal = ResourceReadySignal(this);
376 resourceReadySignal?.Connect(_resourceReadyEventCallback);
377 resourceReadySignal?.Dispose();
380 _resourceReadyEventHandler += value;
385 _resourceReadyEventHandler -= value;
387 ViewResourceReadySignal resourceReadySignal = ResourceReadySignal(this);
388 if (_resourceReadyEventHandler == null && resourceReadySignal?.Empty() == false)
390 resourceReadySignal?.Disconnect(_resourceReadyEventCallback);
392 resourceReadySignal?.Dispose();
396 internal event EventHandler<ResourceLoadedEventArgs> ResourceLoaded
400 if (_resourceLoadedEventHandler == null)
402 _resourceLoadedCallback = OnResourceLoaded;
403 ViewResourceReadySignal resourceReadySignal = this.ResourceReadySignal(this);
404 resourceReadySignal?.Connect(_resourceLoadedCallback);
405 resourceReadySignal?.Dispose();
408 _resourceLoadedEventHandler += value;
412 _resourceLoadedEventHandler -= value;
413 ViewResourceReadySignal resourceReadySignal = this.ResourceReadySignal(this);
414 if (_resourceLoadedEventHandler == null && resourceReadySignal?.Empty() == false)
416 resourceReadySignal?.Disconnect(_resourceLoadedCallback);
418 resourceReadySignal?.Dispose();
423 /// Enumeration for LoadingStatus of image.
425 /// <since_tizen> 5 </since_tizen>
426 public enum LoadingStatusType
429 /// Loading preparing status.
431 /// <since_tizen> 5 </since_tizen>
434 /// Loading ready status.
436 /// <since_tizen> 5 </since_tizen>
439 /// Loading failed status.
441 /// <since_tizen> 5 </since_tizen>
446 /// ImageView ResourceUrl, type string.
447 /// This is one of mandatory property. Even if not set or null set, it sets empty string ("") internally.
448 /// When it is set as null, it gives empty string ("") to be read.
450 /// <since_tizen> 3 </since_tizen>
451 public string ResourceUrl
455 return (string)GetValue(ResourceUrlProperty);
459 SetValue(ResourceUrlProperty, value);
460 NotifyPropertyChanged();
465 /// This will be deprecated, please use Image instead. <br />
466 /// ImageView ImageMap, type PropertyMap: string if it is a URL, map otherwise.
468 /// <since_tizen> 3 </since_tizen>
469 [Obsolete("Please do not use! This will be deprecated! Please use Image property instead!")]
470 [EditorBrowsable(EditorBrowsableState.Never)]
471 public PropertyMap ImageMap
477 PropertyMap returnValue = new PropertyMap();
478 PropertyValue image = GetProperty(ImageView.Property.IMAGE);
479 image?.Get(returnValue);
492 PropertyValue setValue = new Tizen.NUI.PropertyValue(value);
493 SetProperty(ImageView.Property.IMAGE, setValue);
494 NotifyPropertyChanged();
501 /// ImageView Image, type PropertyMap: string if it is a URL, map otherwise.
504 /// This PropertyMap use a <see cref="ImageVisualProperty"/>. <br />
505 /// See <see cref="ImageVisualProperty"/> for a detailed description. <br />
506 /// you can also use <see cref="Visual.Property"/>. <br />
507 /// See <see cref="Visual.Property"/> for a detailed description. <br />
510 /// The following example demonstrates how to use the Image property.
512 /// PropertyMap map = new PropertyMap();
513 /// map.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image));
514 /// map.Insert(ImageVisualProperty.AlphaMaskURL, new PropertyValue(url));
515 /// map.Insert(ImageVisualProperty.FittingMode, new PropertyValue((int)FittingModeType.ScaleToFill);
516 /// imageview.Image = map;
519 /// <since_tizen> 4 </since_tizen>
520 public PropertyMap Image
526 return (PropertyMap)GetValue(ImageProperty);
537 SetValue(ImageProperty, value);
538 NotifyPropertyChanged();
544 /// ImageView PreMultipliedAlpha, type Boolean.<br />
545 /// Image must be initialized.<br />
547 /// <since_tizen> 3 </since_tizen>
548 public bool PreMultipliedAlpha
552 return (bool)GetValue(PreMultipliedAlphaProperty);
556 SetValue(PreMultipliedAlphaProperty, value);
557 NotifyPropertyChanged();
562 /// ImageView PixelArea, type Vector4 (Animatable property).<br />
563 /// Pixel area is a relative value with the whole image area as [0.0, 0.0, 1.0, 1.0].<br />
566 /// The property cascade chaining set is possible. For example, this (imageView.PixelArea.X = 0.1f;) is possible.
568 /// <since_tizen> 3 </since_tizen>
569 public RelativeVector4 PixelArea
573 RelativeVector4 temp = (RelativeVector4)GetValue(PixelAreaProperty);
574 return new RelativeVector4(OnPixelAreaChanged, temp.X, temp.Y, temp.Z, temp.W);
578 SetValue(PixelAreaProperty, value);
579 NotifyPropertyChanged();
584 /// The border of the image in the order: left, right, bottom, top.<br />
585 /// If set, ImageMap will be ignored.<br />
586 /// For N-Patch images only.<br />
590 /// The property cascade chaining set is possible. For example, this (imageView.Border.X = 1;) is possible.
592 /// <since_tizen> 3 </since_tizen>
593 public Rectangle Border
597 Rectangle temp = (Rectangle)GetValue(BorderProperty);
604 return new Rectangle(OnBorderChanged, temp.X, temp.Y, temp.Width, temp.Height);
609 SetValue(BorderProperty, value);
610 NotifyPropertyChanged();
615 /// Gets or sets whether to draw the borders only (if true).<br />
616 /// If not specified, the default is false.<br />
617 /// For N-Patch images only.<br />
620 /// <since_tizen> 3 </since_tizen>
621 public bool BorderOnly
625 return (bool)GetValue(BorderOnlyProperty);
629 SetValue(BorderOnlyProperty, value);
630 NotifyPropertyChanged();
635 /// Gets or sets whether to synchronous loading the resourceurl of image.<br />
637 /// <since_tizen> 3 </since_tizen>
638 [Obsolete("Deprecated since API level 9 and will be removed in API level 11. Please use SynchronousLoading instead!")]
639 public bool SynchronosLoading
643 return SynchronousLoading;
647 SynchronousLoading = value;
652 /// Gets or sets whether the image of the ResourceUrl property will be loaded synchronously.<br />
655 /// Changing this property make this ImageView load image synchronously at the next loading
656 /// by following operation: <see cref="Reload"/>, <see cref="SetImage(string)"/>,
657 /// and by some properties those cause reloading: <see cref="ResourceUrl"/>, <see cref="PreMultipliedAlpha"/> and etc.
659 /// <since_tizen> 9 </since_tizen>
660 public bool SynchronousLoading
664 return (bool)GetValue(SynchronousLoadingProperty);
668 SetValue(SynchronousLoadingProperty, value);
669 NotifyPropertyChanged();
674 /// Gets or sets whether to automatically correct the orientation of an image.<br />
676 /// <since_tizen> 5 </since_tizen>
677 public bool OrientationCorrection
681 return (bool)GetValue(OrientationCorrectionProperty);
685 SetValue(OrientationCorrectionProperty, value);
686 NotifyPropertyChanged();
691 /// Gets the loading state of the visual resource.
693 /// <since_tizen> 5 </since_tizen>
694 public ImageView.LoadingStatusType LoadingStatus
698 return (ImageView.LoadingStatusType)Interop.View.GetVisualResourceStatus(SwigCPtr, (int)Property.IMAGE);
703 /// Downcasts a handle to imageView handle.
705 /// <exception cref="ArgumentNullException"> Thrown when handle is null. </exception>
706 /// Please do not use! this will be deprecated!
707 /// Instead please use as keyword.
708 /// <since_tizen> 3 </since_tizen>
709 [Obsolete("Please do not use! This will be deprecated! Please use as keyword instead! " +
711 "BaseHandle handle = new ImageView(imagePath); " +
712 "ImageView image = handle as ImageView")]
713 [EditorBrowsable(EditorBrowsableState.Never)]
714 public static ImageView DownCast(BaseHandle handle)
718 throw new ArgumentNullException(nameof(handle));
720 ImageView ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as ImageView;
721 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
726 /// Sets this ImageView from the given URL.<br />
727 /// If the URL is empty, ImageView will not display anything.<br />
729 /// <param name="url">The URL to the image resource to display.</param>
730 /// <exception cref="ArgumentNullException"> Thrown when url is null. </exception>
731 /// <since_tizen> 3 </since_tizen>
732 public void SetImage(string url)
736 throw new ArgumentNullException(nameof(url));
739 if (url.Contains(".json"))
741 Tizen.Log.Fatal("NUI", "[ERROR] Please DO NOT set lottie file in ImageView! This is temporary checking, will be removed soon!");
745 Interop.ImageView.SetImage(SwigCPtr, url);
746 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
752 /// Queries if all resources required by a control are loaded and ready.<br />
753 /// Most resources are only loaded when the control is placed on the stage.<br />
754 /// True if the resources are loaded and ready, false otherwise.<br />
756 /// <since_tizen> 3 </since_tizen>
757 public new bool IsResourceReady()
759 bool ret = Interop.View.IsResourceReady(SwigCPtr);
760 if (NDalicPINVOKE.SWIGPendingException.Pending)
761 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
766 /// Forcefully reloads the image. All the visuals using this image will reload to the latest image.
768 /// <since_tizen> 5 </since_tizen>
771 PropertyValue attributes = new PropertyValue(0);
772 this.DoAction(ImageView.Property.IMAGE, ActionReload, attributes);
773 attributes?.Dispose();
777 /// Plays the animated GIF. This is also the default playback mode.
779 /// <since_tizen> 5 </since_tizen>
782 PropertyValue attributes = new PropertyValue(0);
783 this.DoAction(ImageView.Property.IMAGE, ActionPlay, attributes);
784 attributes?.Dispose();
788 /// Pauses the animated GIF.
790 /// <since_tizen> 5 </since_tizen>
793 PropertyValue attributes = new PropertyValue(0);
794 this.DoAction(ImageView.Property.IMAGE, ActionPause, attributes);
795 attributes?.Dispose();
799 /// Stops the animated GIF.
801 /// <since_tizen> 5 </since_tizen>
804 PropertyValue attributes = new PropertyValue(0);
805 this.DoAction(ImageView.Property.IMAGE, ActionStop, attributes);
806 attributes?.Dispose();
810 /// Gets or sets the URL of the alpha mask.<br />
813 /// <since_tizen> 6</since_tizen>
814 [EditorBrowsable(EditorBrowsableState.Never)]
815 public string AlphaMaskURL
820 PropertyMap imageMap = new PropertyMap();
821 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
822 image?.Get(imageMap);
823 PropertyValue maskUrl = imageMap?.Find(ImageVisualProperty.AlphaMaskURL);
824 maskUrl?.Get(out ret);
840 _alphaMaskUrl = value;
842 PropertyValue setValue = new PropertyValue(value);
843 UpdateImage(ImageVisualProperty.AlphaMaskURL, setValue);
850 /// Whether to crop image to mask or scale mask to fit image.
852 /// <since_tizen> 6 </since_tizen>
853 public bool CropToMask
857 bool ret = _cropToMask;
858 PropertyMap imageMap = new PropertyMap();
859 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
860 image?.Get(imageMap);
861 PropertyValue cropUrl = imageMap?.Find(ImageVisualProperty.CropToMask);
862 cropUrl?.Get(out ret);
874 PropertyValue setValue = new PropertyValue(value);
875 UpdateImage(ImageVisualProperty.CropToMask, setValue);
881 /// Actions property value for Reload image.
883 private int ActionReload { get; set; } = Interop.ImageView.ImageVisualActionReloadGet();
886 /// Actions property value to Play animated images.
887 /// This property can be redefined by child class if it use different value.
889 [EditorBrowsable(EditorBrowsableState.Never)]
890 protected int ActionPlay { get; set; } = Interop.AnimatedImageView.AnimatedImageVisualActionPlayGet();
893 /// Actions property value to Pause animated images.
894 /// This property can be redefined by child class if it use different value.
896 [EditorBrowsable(EditorBrowsableState.Never)]
897 protected int ActionPause { get; set; } = Interop.AnimatedImageView.AnimatedImageVisualActionPauseGet();
900 /// Actions property value to Stop animated images.
901 /// This property can be redefined by child class if it use different value.
903 [EditorBrowsable(EditorBrowsableState.Never)]
904 protected int ActionStop { get; set; } = Interop.AnimatedImageView.AnimatedImageVisualActionStopGet();
906 internal VisualFittingModeType ConvertFittingModetoVisualFittingMode(FittingModeType value)
910 case FittingModeType.ShrinkToFit:
911 return VisualFittingModeType.FitKeepAspectRatio;
912 case FittingModeType.ScaleToFill:
913 return VisualFittingModeType.OverFitKeepAspectRatio;
914 case FittingModeType.Center:
915 return VisualFittingModeType.Center;
916 case FittingModeType.Fill:
917 return VisualFittingModeType.Fill;
918 case FittingModeType.FitHeight:
919 return VisualFittingModeType.FitHeight;
920 case FittingModeType.FitWidth:
921 return VisualFittingModeType.FitWidth;
923 return VisualFittingModeType.Fill;
927 internal FittingModeType ConvertVisualFittingModetoFittingMode(VisualFittingModeType value)
931 case VisualFittingModeType.FitKeepAspectRatio:
932 return FittingModeType.ShrinkToFit;
933 case VisualFittingModeType.OverFitKeepAspectRatio:
934 return FittingModeType.ScaleToFill;
935 case VisualFittingModeType.Center:
936 return FittingModeType.Center;
937 case VisualFittingModeType.Fill:
938 return FittingModeType.Fill;
939 case VisualFittingModeType.FitHeight:
940 return FittingModeType.FitHeight;
941 case VisualFittingModeType.FitWidth:
942 return FittingModeType.FitWidth;
944 return FittingModeType.ShrinkToFit;
948 internal override LayoutItem CreateDefaultLayout()
950 return new ImageLayout();
954 /// Gets or sets fitting options used when resizing images to fit.<br />
955 /// If not supplied, the default is FittingModeType.Fill.<br />
956 /// For normal quad images only.<br />
959 /// <since_tizen> 6 </since_tizen>
960 [EditorBrowsable(EditorBrowsableState.Never)]
961 public FittingModeType FittingMode
965 int ret = (int)_fittingMode;
966 PropertyMap imageMap = new PropertyMap();
967 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
968 image?.Get(imageMap);
969 PropertyValue fittingMode = imageMap?.Find(Visual.Property.VisualFittingMode);
970 fittingMode?.Get(out ret);
971 _fittingMode = (VisualFittingModeType)ret;
975 fittingMode?.Dispose();
977 return ConvertVisualFittingModetoFittingMode((VisualFittingModeType)ret);
981 VisualFittingModeType ret = ConvertFittingModetoVisualFittingMode(value);
982 PropertyValue setValue = new PropertyValue((int)ret);
983 if(_fittingMode != ret)
986 UpdateImage(Visual.Property.VisualFittingMode, setValue);
995 /// Gets or sets the desired image width.<br />
996 /// If not specified, the actual image width is used.<br />
997 /// For normal quad images only.<br />
1000 /// <since_tizen> 6 </since_tizen>
1001 [EditorBrowsable(EditorBrowsableState.Never)]
1002 public int DesiredWidth
1006 PropertyMap imageMap = new PropertyMap();
1007 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
1008 image?.Get(imageMap);
1009 PropertyValue desireWidth = imageMap?.Find(ImageVisualProperty.DesiredWidth);
1010 desireWidth?.Get(out _desired_width);
1012 imageMap?.Dispose();
1014 desireWidth?.Dispose();
1016 return _desired_width;
1020 if (_desired_width != value)
1022 _desired_width = value;
1023 UpdateImage(0, null);
1029 /// Gets or sets the desired image height.<br />
1030 /// If not specified, the actual image height is used.<br />
1031 /// For normal quad images only.<br />
1034 /// <since_tizen> 6 </since_tizen>
1035 [EditorBrowsable(EditorBrowsableState.Never)]
1036 public int DesiredHeight
1040 PropertyMap imageMap = new PropertyMap();
1041 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
1042 image?.Get(imageMap);
1043 PropertyValue desireheight = imageMap?.Find(ImageVisualProperty.DesiredHeight);
1044 desireheight?.Get(out _desired_height);
1046 imageMap?.Dispose();
1048 desireheight?.Dispose();
1050 return _desired_height;
1054 if (_desired_height != value)
1056 _desired_height = value;
1057 UpdateImage(0, null);
1063 /// Gets or sets ReleasePolicy for image.<br />
1064 /// If not supplied, the default is ReleasePolicyType.Detached.<br />
1066 [EditorBrowsable(EditorBrowsableState.Never)]
1067 public ReleasePolicyType ReleasePolicy
1071 int ret = (int)ReleasePolicyType.Detached;
1072 PropertyMap imageMap = new PropertyMap();
1073 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
1074 image?.Get(imageMap);
1075 PropertyValue releasePoli = imageMap?.Find(ImageVisualProperty.ReleasePolicy);
1076 releasePoli?.Get(out ret);
1078 imageMap?.Dispose();
1080 releasePoli?.Dispose();
1082 return (ReleasePolicyType)ret;
1086 PropertyValue setValue = new PropertyValue((int)value);
1087 UpdateImage(ImageVisualProperty.ReleasePolicy, setValue);
1088 setValue?.Dispose();
1093 /// Gets or sets the wrap mode for the u coordinate.<br />
1094 /// It decides how the texture should be sampled when the u coordinate exceeds the range of 0.0 to 1.0.<br />
1095 /// If not specified, the default is WrapModeType.Default(CLAMP).<br />
1096 /// For normal quad images only.<br />
1099 /// <since_tizen> 6 </since_tizen>
1100 [EditorBrowsable(EditorBrowsableState.Never)]
1101 public WrapModeType WrapModeU
1105 int ret = (int)WrapModeType.Default;
1106 PropertyMap imageMap = new PropertyMap();
1107 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
1108 image?.Get(imageMap);
1109 PropertyValue warpModeU = imageMap?.Find(ImageVisualProperty.WrapModeU);
1110 warpModeU?.Get(out ret);
1112 imageMap?.Dispose();
1114 warpModeU?.Dispose();
1116 return (WrapModeType)ret;
1120 PropertyValue setValue = new PropertyValue((int)value);
1121 UpdateImage(ImageVisualProperty.WrapModeU, setValue);
1122 setValue?.Dispose();
1127 /// Gets or sets the wrap mode for the v coordinate.<br />
1128 /// It decides how the texture should be sampled when the v coordinate exceeds the range of 0.0 to 1.0.<br />
1129 /// The first two elements indicate the top-left position of the area, and the last two elements are the areas of the width and the height respectively.<br />
1130 /// If not specified, the default is WrapModeType.Default(CLAMP).<br />
1131 /// For normal quad images only.
1134 /// <since_tizen> 6 </since_tizen>
1135 [EditorBrowsable(EditorBrowsableState.Never)]
1136 public WrapModeType WrapModeV
1140 int ret = (int)WrapModeType.Default;
1141 PropertyMap imageMap = new PropertyMap();
1142 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
1143 image?.Get(imageMap);
1144 PropertyValue wrapModeV = imageMap?.Find(ImageVisualProperty.WrapModeV);
1145 wrapModeV?.Get(out ret);
1147 imageMap?.Dispose();
1149 wrapModeV?.Dispose();
1151 return (WrapModeType)ret;
1155 PropertyValue setValue = new PropertyValue((int)value);
1156 UpdateImage(ImageVisualProperty.WrapModeV, setValue);
1157 setValue?.Dispose();
1162 /// Gets or sets the mode to adjust view size to preserve the aspect ratio of the image resource.
1165 /// This is false by default.
1166 /// If this is set to be true, then the width or height value, which is not set by user explicitly, can be changed automatically
1167 /// to preserve the aspect ratio of the image resource.
1168 /// AdjustViewSize works only if ImageView is added to a View having Layout.
1169 /// e.g. If the image resource size is (100, 100), then the ImageView requests size (100, 100) to its parent layout by default.
1170 /// If the ImageView's HeightSpecification is 50 and AdjustViewSize is true, then the ImageView requests size (50, 50) instead of (100, 50).
1172 /// <since_tizen> 9 </since_tizen>
1173 public bool AdjustViewSize { get; set; } = false;
1175 internal Selector<string> ResourceUrlSelector
1177 get => GetSelector<string>(resourceUrlSelector, ImageView.ResourceUrlProperty);
1180 resourceUrlSelector?.Reset(this);
1181 if (value == null) return;
1183 if (value.HasAll()) SetResourceUrl(value.All);
1184 else resourceUrlSelector = new TriggerableSelector<string>(this, value, SetResourceUrl, true);
1189 /// Get attributes, it is abstract function and must be override.
1191 [EditorBrowsable(EditorBrowsableState.Never)]
1192 protected override ViewStyle CreateViewStyle()
1194 return new ImageViewStyle();
1197 internal void SetImage(string url, Uint16Pair size)
1199 if (url.Contains(".json"))
1201 Tizen.Log.Fatal("NUI", "[ERROR] Please DO NOT set lottie file in ImageView! This is temporary checking, will be removed soon!");
1205 Interop.ImageView.SetImage(SwigCPtr, url, Uint16Pair.getCPtr(size));
1206 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1211 internal ViewResourceReadySignal ResourceReadySignal(View view)
1213 ViewResourceReadySignal ret = new ViewResourceReadySignal(Interop.View.ResourceReadySignal(View.getCPtr(view)), false);
1214 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1218 internal override void ApplyCornerRadius()
1220 base.ApplyCornerRadius();
1222 UpdateImage(0, null);
1225 internal override void ApplyBorderline()
1227 base.ApplyBorderline();
1229 // Apply borderline to IMAGE.
1230 if (backgroundExtraData != null)
1232 var borderlineColor = backgroundExtraData.BorderlineColor == null ? new PropertyValue(Color.Black) : new PropertyValue(backgroundExtraData.BorderlineColor);
1234 // Apply to the image visual
1235 PropertyMap imageMap = new PropertyMap();
1236 PropertyValue imageValue = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
1237 if (imageValue.Get(imageMap) && !imageMap.Empty())
1239 imageMap[Visual.Property.BorderlineWidth] = new PropertyValue(backgroundExtraData.BorderlineWidth);
1240 imageMap[Visual.Property.BorderlineColor] = borderlineColor;
1241 imageMap[Visual.Property.BorderlineOffset] = new PropertyValue(backgroundExtraData.BorderlineOffset);
1242 var temp = new PropertyValue(imageMap);
1243 Tizen.NUI.Object.SetProperty(SwigCPtr, ImageView.Property.IMAGE, temp);
1247 imageValue.Dispose();
1248 borderlineColor.Dispose();
1251 UpdateImage(0, null);
1254 internal ResourceLoadingStatusType GetResourceStatus()
1256 return (ResourceLoadingStatusType)Interop.View.GetVisualResourceStatus(this.SwigCPtr, Property.IMAGE);
1260 /// you can override it to clean-up your own resources.
1262 /// <param name="type">DisposeTypes</param>
1263 /// <since_tizen> 3 </since_tizen>
1264 protected override void Dispose(DisposeTypes type)
1271 if (type == DisposeTypes.Explicit)
1274 //Release your own managed resources here.
1275 //You should release all of your own disposable objects here.
1278 borderSelector?.Reset(this);
1279 resourceUrlSelector?.Reset(this);
1285 /// This will not be public opened.
1286 [EditorBrowsable(EditorBrowsableState.Never)]
1287 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
1289 Interop.ImageView.DeleteImageView(swigCPtr);
1292 // Callback for View ResourceReady signal
1293 private void OnResourceReady(IntPtr data)
1295 ResourceReadyEventArgs e = new ResourceReadyEventArgs();
1298 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
1301 if (_resourceReadyEventHandler != null)
1303 _resourceReadyEventHandler(this, e);
1307 private void SetResourceUrl(string value)
1309 value = (value == null ? "" : value);
1310 if (value.StartsWith("*Resource*"))
1312 string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
1313 value = value.Replace("*Resource*", resource);
1315 _resourceUrl = value;
1316 UpdateImage(ImageVisualProperty.URL, new PropertyValue(value));
1319 private void SetBorder(Rectangle value)
1325 _border = new Rectangle(value);
1326 UpdateImage(NpatchImageVisualProperty.Border, new PropertyValue(_border));
1329 private void UpdateImageMap(PropertyMap fromMap)
1331 PropertyMap imageMap = new PropertyMap();
1333 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
1334 image?.Get(imageMap);
1335 imageMap?.Merge(fromMap);
1336 PropertyValue setValue = new PropertyValue(imageMap);
1337 SetProperty(ImageView.Property.IMAGE, setValue);
1339 imageMap?.Dispose();
1341 setValue?.Dispose();
1344 private void UpdateImage(int key, PropertyValue value)
1346 PropertyMap imageMap = new PropertyMap();
1348 if (_alphaMaskUrl != null)
1350 PropertyValue alphaMaskUrl = new PropertyValue(_alphaMaskUrl);
1351 imageMap?.Insert(ImageVisualProperty.AlphaMaskURL, alphaMaskUrl);
1352 alphaMaskUrl?.Dispose();
1355 if(key != ImageVisualProperty.CropToMask)
1357 PropertyValue cropToMask = new PropertyValue(_cropToMask);
1358 imageMap?.Insert(ImageVisualProperty.CropToMask, cropToMask);
1359 cropToMask?.Dispose();
1362 if (string.IsNullOrEmpty(_resourceUrl))
1364 PropertyValue resourceUrl = new PropertyValue(_resourceUrl);
1365 imageMap?.Insert(ImageVisualProperty.URL, resourceUrl);
1366 PropertyValue setValue = new PropertyValue(imageMap);
1367 SetProperty(ImageView.Property.IMAGE, setValue);
1368 resourceUrl?.Dispose();
1369 setValue?.Dispose();
1373 if (_border == null)
1375 PropertyValue image = new PropertyValue((int)Visual.Type.Image);
1376 imageMap?.Insert(Visual.Property.Type, image);
1381 PropertyValue nPatch = new PropertyValue((int)Visual.Type.NPatch);
1382 imageMap?.Insert(Visual.Property.Type, nPatch);
1384 PropertyValue border = new PropertyValue(_border);
1385 imageMap?.Insert(NpatchImageVisualProperty.Border, border);
1389 if(key != Visual.Property.VisualFittingMode && _fittingMode != VisualFittingModeType.Fill)
1391 PropertyValue fittingMode = new PropertyValue((int)_fittingMode);
1392 imageMap?.Insert(Visual.Property.VisualFittingMode, fittingMode);
1393 fittingMode?.Dispose();
1396 PropertyValue synchronousLoading = new PropertyValue(_synchronousLoading);
1397 imageMap?.Insert(NpatchImageVisualProperty.SynchronousLoading, synchronousLoading);
1398 synchronousLoading?.Dispose();
1400 if (backgroundExtraData != null && backgroundExtraData.CornerRadius != null)
1402 using (var cornerRadius = new PropertyValue(backgroundExtraData.CornerRadius))
1403 using (var cornerRadiusPolicy = new PropertyValue((int)backgroundExtraData.CornerRadiusPolicy))
1405 imageMap.Insert(Visual.Property.CornerRadius, cornerRadius);
1406 imageMap.Insert(Visual.Property.CornerRadiusPolicy, new PropertyValue((int)(backgroundExtraData.CornerRadiusPolicy)));
1410 if (backgroundExtraData != null && backgroundExtraData.BorderlineWidth > 0.0f)
1412 using (var borderlineWidth = new PropertyValue(backgroundExtraData.BorderlineWidth))
1413 using (var borderlineColor = new PropertyValue(backgroundExtraData.BorderlineColor))
1414 using (var borderlineOffset = new PropertyValue(backgroundExtraData.BorderlineOffset))
1416 imageMap.Insert(Visual.Property.BorderlineWidth, borderlineWidth);
1417 imageMap.Insert(Visual.Property.BorderlineColor, borderlineColor);
1418 imageMap.Insert(Visual.Property.BorderlineOffset, borderlineOffset);
1424 imageMap?.Insert(key, value);
1427 // Do Fitting Buffer when desired dimension is set
1428 if (_desired_width != -1 && _desired_height != -1)
1430 if (_resourceUrl != null)
1432 Size2D imageSize = ImageLoader.GetOriginalImageSize(_resourceUrl, true);
1433 if( imageSize.Height > 0 && imageSize.Width > 0 && _desired_width > 0 && _desired_height > 0 )
1435 int adjustedDesiredWidth, adjustedDesiredHeight;
1436 float aspectOfDesiredSize = (float)_desired_height / (float)_desired_width;
1437 float aspectOfImageSize = (float)imageSize.Height / (float)imageSize.Width;
1438 if (aspectOfImageSize > aspectOfDesiredSize)
1440 adjustedDesiredWidth = _desired_width;
1441 adjustedDesiredHeight = imageSize.Height * _desired_width / imageSize.Width;
1445 adjustedDesiredWidth = imageSize.Width * _desired_height / imageSize.Height;
1446 adjustedDesiredHeight = _desired_height;
1449 PropertyValue returnWidth = new PropertyValue(adjustedDesiredWidth);
1450 imageMap?.Insert(ImageVisualProperty.DesiredWidth, returnWidth);
1451 returnWidth?.Dispose();
1452 PropertyValue returnHeight = new PropertyValue(adjustedDesiredHeight);
1453 imageMap?.Insert(ImageVisualProperty.DesiredHeight, returnHeight);
1454 returnHeight?.Dispose();
1455 PropertyValue scaleToFit = new PropertyValue((int)FittingModeType.ScaleToFill);
1456 imageMap?.Insert(ImageVisualProperty.FittingMode, scaleToFit);
1457 scaleToFit?.Dispose();
1461 Tizen.Log.Fatal("NUI", "[ERROR] Can't use DesiredSize when ImageLoading is failed.");
1463 imageSize?.Dispose();
1467 UpdateImageMap(imageMap);
1469 imageMap?.Dispose();
1474 private void OnResourceLoaded(IntPtr view)
1476 ResourceLoadedEventArgs e = new ResourceLoadedEventArgs();
1477 e.Status = (ResourceLoadingStatusType)Interop.View.GetVisualResourceStatus(this.SwigCPtr, Property.IMAGE);
1479 if (_resourceLoadedEventHandler != null)
1481 _resourceLoadedEventHandler(this, e);
1486 /// Event arguments of resource ready.
1488 /// <since_tizen> 3 </since_tizen>
1489 public class ResourceReadyEventArgs : EventArgs
1494 /// The view whose resource is ready.
1496 /// <since_tizen> 3 </since_tizen>
1510 internal class ResourceLoadedEventArgs : EventArgs
1512 private ResourceLoadingStatusType status = ResourceLoadingStatusType.Invalid;
1513 public ResourceLoadingStatusType Status
1526 internal new class Property
1528 internal static readonly int IMAGE = Interop.ImageView.ImageGet();
1529 internal static readonly int PreMultipliedAlpha = Interop.ImageView.PreMultipliedAlphaGet();
1530 internal static readonly int PixelArea = Interop.ImageView.PixelAreaGet();
1533 private enum ImageType
1536 /// For Normal Image.
1541 /// For normal image, with synchronous loading and orientation correction property
1546 /// For nine-patch image
1551 private void OnBorderChanged(int x, int y, int width, int height)
1553 Border = new Rectangle(x, y, width, height);
1555 private void OnPixelAreaChanged(float x, float y, float z, float w)
1557 PixelArea = new RelativeVector4(x, y, z, w);
1560 private class ImageLayout : LayoutItem
1563 /// Gets or sets the mode to adjust view size to preserve the aspect ratio of the image resource.
1564 /// If this is set to be true, then the width or height, which is not set by user explicitly, can be adjusted to preserve the aspect ratio of the image resource.
1566 [EditorBrowsable(EditorBrowsableState.Never)]
1567 public bool AdjustViewSize
1571 return (Owner as ImageView)?.AdjustViewSize ?? false;
1575 if (Owner is ImageView imageView)
1577 imageView.AdjustViewSize = value;
1583 [EditorBrowsable(EditorBrowsableState.Never)]
1584 protected override void OnMeasure(MeasureSpecification widthMeasureSpec, MeasureSpecification heightMeasureSpec)
1586 // To not change the view size by DALi
1587 Owner.WidthResizePolicy = ResizePolicyType.Fixed;
1588 Owner.HeightResizePolicy = ResizePolicyType.Fixed;
1590 float specWidth = widthMeasureSpec.Size.AsDecimal();
1591 float specHeight = heightMeasureSpec.Size.AsDecimal();
1592 float naturalWidth = Owner.NaturalSize.Width;
1593 float naturalHeight = Owner.NaturalSize.Height;
1594 float minWidth = Owner.MinimumSize.Width;
1595 float maxWidth = Owner.MaximumSize.Width;
1596 float minHeight = Owner.MinimumSize.Height;
1597 float maxHeight = Owner.MaximumSize.Height;
1598 float aspectRatio = (naturalWidth > 0) ? (naturalHeight / naturalWidth) : 0;
1600 // Assume that the new width and height are given from the view's suggested size by default.
1601 float newWidth = Math.Min(Math.Max(naturalWidth, minWidth), (maxWidth < 0 ? Int32.MaxValue : maxWidth));
1602 float newHeight = Math.Min(Math.Max(naturalHeight, minHeight), (maxHeight < 0 ? Int32.MaxValue : maxHeight));
1604 // The width and height measure specs are going to be used to set measured size.
1605 // Mark that the measure specs are changed by default to update measure specs later.
1606 bool widthSpecChanged = true;
1607 bool heightSpecChanged = true;
1609 if (widthMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly)
1611 newWidth = specWidth;
1612 widthSpecChanged = false;
1614 if (heightMeasureSpec.Mode != MeasureSpecification.ModeType.Exactly)
1616 if ((AdjustViewSize) && (aspectRatio > 0))
1618 newHeight = newWidth * aspectRatio;
1623 if (heightMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly)
1625 newHeight = specHeight;
1626 heightSpecChanged = false;
1628 if (widthMeasureSpec.Mode != MeasureSpecification.ModeType.Exactly)
1630 if ((AdjustViewSize) && (aspectRatio > 0))
1632 newWidth = newHeight / aspectRatio;
1637 if (widthSpecChanged)
1639 widthMeasureSpec = new MeasureSpecification(new LayoutLength(newWidth), MeasureSpecification.ModeType.Exactly);
1642 if (heightSpecChanged)
1644 heightMeasureSpec = new MeasureSpecification(new LayoutLength(newHeight), MeasureSpecification.ModeType.Exactly);
1647 MeasuredSize.StateType childWidthState = MeasuredSize.StateType.MeasuredSizeOK;
1648 MeasuredSize.StateType childHeightState = MeasuredSize.StateType.MeasuredSizeOK;
1650 SetMeasuredDimensions(ResolveSizeAndState(new LayoutLength(newWidth), widthMeasureSpec, childWidthState),
1651 ResolveSizeAndState(new LayoutLength(newHeight), heightMeasureSpec, childHeightState));