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.
17 using System.ComponentModel;
18 using Tizen.NUI.BaseComponents;
20 namespace Tizen.NUI.Components
23 /// The ContentPage class is a class which is a formatted full screen page.
24 /// ContentPage contains title app bar and content.
26 /// <since_tizen> 9 </since_tizen>
27 public partial class ContentPage : Page
29 private AppBar appBar = null;
30 private View content = null;
33 /// Creates a new instance of a ContentPage.
35 /// <since_tizen> 9 </since_tizen>
36 public ContentPage() : base()
38 Layout = new AbsoluteLayout();
40 // ContentPage fills to parent by default.
41 WidthResizePolicy = ResizePolicyType.FillToParent;
42 HeightResizePolicy = ResizePolicyType.FillToParent;
46 /// Dispose ContentPage and all children on it.
48 /// <param name="type">Dispose type.</param>
49 [EditorBrowsable(EditorBrowsableState.Never)]
50 protected override void Dispose(DisposeTypes type)
57 if (type == DisposeTypes.Explicit)
61 Utility.Dispose(appBar);
66 Utility.Dispose(content);
74 [EditorBrowsable(EditorBrowsableState.Never)]
75 public override void OnInitialize()
79 SetAccessibilityConstructor(Role.PageTab);
83 /// AppBar of ContentPage.
84 /// AppBar is added as a child of ContentPage automatically.
85 /// AppBar is positioned at the top of the Page.
87 /// <since_tizen> 9 </since_tizen>
92 return GetValue(AppBarProperty) as AppBar;
96 SetValue(AppBarProperty, value);
97 NotifyPropertyChanged();
100 private AppBar InternalAppBar
131 /// Content of ContentPage.
132 /// Content is added as a child of ContentPage automatically.
133 /// Content is positioned below AppBar.
134 /// Content is resized to fill the full screen except AppBar.
136 /// <since_tizen> 9 </since_tizen>
141 return GetValue(ContentProperty) as View;
145 SetValue(ContentProperty, value);
146 NotifyPropertyChanged();
149 private View InternalContent
157 if (content == value)
180 [EditorBrowsable(EditorBrowsableState.Never)]
181 public override void OnRelayout(Vector2 size, RelayoutContainer container)
183 base.OnRelayout(size, container);
188 // Calculate appBar and content's positions.
189 private void CalculatePosition()
191 // If ContentPage size has not been set yet, then content size cannot be calculated.
192 if ((Size2D.Width == 0) && (Size2D.Height == 0))
199 int appBarPosX = Position2D.X + Padding.Start + appBar.Margin.Top;
200 int appBarPosY = Position2D.Y + Padding.Top + appBar.Margin.Top;
202 appBar.Position2D = new Position2D(appBarPosX, appBarPosY);
204 if ((appBar.WidthSpecification == LayoutParamPolicies.MatchParent) || (appBar.HeightSpecification == LayoutParamPolicies.MatchParent))
206 int appBarSizeW = appBar.Size2D.Width;
207 int appBarSizeH = appBar.Size2D.Height;
209 if (appBar.WidthSpecification == LayoutParamPolicies.MatchParent)
211 appBarSizeW = Size2D.Width - Padding.Start - Padding.End - appBar.Margin.Start - appBar.Margin.End;
214 if (appBar.HeightSpecification == LayoutParamPolicies.MatchParent)
216 appBarSizeH = Size2D.Height - Padding.Top - Padding.Bottom - appBar.Margin.Top - appBar.Margin.Bottom;
219 appBar.SetSize(new Size2D(appBarSizeW, appBarSizeH));
225 int contentPosX = Position2D.X + Padding.Start + content.Margin.Start;
226 int contentPosY = Position2D.Y + Padding.Top + content.Margin.Top + (appBar?.Size2D.Height ?? 0);
228 content.Position2D = new Position2D(contentPosX, contentPosY);
230 if ((content.WidthSpecification == LayoutParamPolicies.MatchParent) || (content.HeightSpecification == LayoutParamPolicies.MatchParent))
232 int contentSizeW = content.Size2D.Width;
233 int contentSizeH = content.Size2D.Height;
235 if (content.WidthSpecification == LayoutParamPolicies.MatchParent)
237 contentSizeW = Size2D.Width - Padding.Start - Padding.End - content.Margin.Start - content.Margin.End;
240 if (content.HeightSpecification == LayoutParamPolicies.MatchParent)
242 contentSizeH = Size2D.Height - Padding.Top - Padding.Bottom - content.Margin.Top - content.Margin.Bottom - (appBar?.Size2D.Height ?? 0);
245 content.SetSize(new Size2D(contentSizeW, contentSizeH));