2 * Copyright(c) 2020 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.
19 using System.ComponentModel;
20 using Tizen.NUI.BaseComponents;
22 namespace Tizen.NUI.Components
25 /// Dialog class shows a popup content with background scrim.
27 [EditorBrowsable(EditorBrowsableState.Never)]
28 public class Dialog : Control
30 private View popupContent = null;
31 private View scrim = null;
32 private bool enableScrim = true;
35 /// Creates a new instance of Dialog.
37 /// <param name="content">The content to set to Content of Dialog.</param>
38 [EditorBrowsable(EditorBrowsableState.Never)]
39 public Dialog(View content = null) : base()
42 EnableDismissOnScrim = true;
44 //FIXME: Needs to separate GUI implementation codes to style cs file.
45 var scrim = new VisualView();
46 scrim.BackgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.5f);
47 //FIXME: Needs to set proper size to Scrim.
48 scrim.Size = NUIApplication.GetDefaultWindow().Size;
49 scrim.TouchEvent += (object source, TouchEventArgs e) =>
51 if ((EnableDismissOnScrim == true) && (e.Touch.GetState(0) == PointStateType.Up))
53 //TODO: To show hide animation.
64 content.RaiseAbove(scrim);
70 /// Popup content of Dialog. Content is added to Children automatically.
72 [EditorBrowsable(EditorBrowsableState.Never)]
81 if (popupContent == value)
86 if (popupContent != null)
92 if (popupContent == null)
97 popupContent.Relayout += PopupContentRelayout;
99 //FIXME: Needs to separate GUI implementation codes to style cs file.
100 CalculateContentPosition();
106 popupContent.RaiseAbove(Scrim);
111 private void PopupContentRelayout(object sender, EventArgs e)
113 //FIXME: Needs to separate GUI implementation codes to style cs file.
114 CalculateContentPosition();
117 private void CalculateContentPosition()
119 var size = popupContent.Size2D;
120 var parent = GetParent();
123 if ((parent != null) && (parent is View))
125 parentSize = ((View)parent).Size;
129 parentSize = NUIApplication.GetDefaultWindow().Size;
132 popupContent.Position2D = new Position2D((parentSize.Width - size.Width) / 2, (parentSize.Height - size.Height) / 2);
136 /// Indicates to show scrim behind popup content.
138 [EditorBrowsable(EditorBrowsableState.Never)]
139 public bool EnableScrim
147 if (enableScrim == value)
154 if ((Scrim != null) && (enableScrim != Scrim.Visibility))
169 /// Indicates to dismiss popup content by touching on scrim.
171 [EditorBrowsable(EditorBrowsableState.Never)]
172 public bool EnableDismissOnScrim { get; set; }
175 /// Scrim covers background behind popup content.
177 [EditorBrowsable(EditorBrowsableState.Never)]
178 protected internal View Scrim
206 Content.RaiseAbove(scrim);
212 /// Dispose Dialog and all children on it.
214 /// <param name="type">Dispose type.</param>
215 [EditorBrowsable(EditorBrowsableState.Never)]
216 protected override void Dispose(DisposeTypes type)
223 if (type == DisposeTypes.Explicit)
225 if (popupContent != null)
227 popupContent.Relayout -= PopupContentRelayout;
228 Utility.Dispose(popupContent);
233 Utility.Dispose(scrim);