[NUI] Minimize size is set too large. and code clean
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / BorderWindowTest.cs
1
2 using System;
3 using Tizen.NUI;
4 using Tizen.NUI.BaseComponents;
5 using Tizen.NUI.Components;
6 using System.Collections.Generic;
7
8
9 namespace Tizen.NUI.Samples
10 {
11   public class BorderWindowTest : IExample
12   {
13     private Window win;
14     private Window subWindowOne = null;
15     private Window subWindowTwo = null;
16     private static readonly string imagePath = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "/images/Dali/CubeTransitionEffect/";
17
18
19     class CustomBorder : DefaultBorder
20     {
21       private int width = 500;
22       private bool hide = false;
23       private View rootView;
24       private View borderView;
25       private TextLabel title;
26
27       public CustomBorder() : base()
28       {
29         BorderHeight = 60;
30       }
31
32       public override void CreateBorderView(View rootView)
33       {
34           this.rootView = rootView;
35           rootView.CornerRadius = new Vector4(0.03f, 0.03f, 0.03f, 0.03f);
36           rootView.CornerRadiusPolicy = VisualTransformPolicyType.Relative;
37
38           borderView = new View()
39           {
40               Layout = new LinearLayout()
41               {
42                   LinearAlignment = LinearLayout.Alignment.End,
43                   LinearOrientation = LinearLayout.Orientation.Horizontal,
44               },
45               WidthSpecification = LayoutParamPolicies.MatchParent,
46               HeightSpecification = LayoutParamPolicies.MatchParent,
47           };
48           title = new TextLabel()
49           {
50             Text = "CustomBorder",
51             Size = new Size(300, 50),
52             Position = new Position(60, 0),
53             PositionUsesPivotPoint = true,
54             PivotPoint = PivotPoint.BottomLeft,
55             ParentOrigin = ParentOrigin.BottomLeft,
56           };
57
58           var minimalizeIcon = new Button()
59           {
60               Text = "m",
61               PositionUsesPivotPoint = true,
62               PivotPoint = PivotPoint.BottomLeft,
63               ParentOrigin = ParentOrigin.BottomLeft,
64               Size = new Size(50, 50),
65           };
66
67           var maximalizeIcon = new Button()
68           {
69               Text = "M",
70               PositionUsesPivotPoint = true,
71               PivotPoint = PivotPoint.BottomLeft,
72               ParentOrigin = ParentOrigin.BottomLeft,
73               Size = new Size(50, 50),
74           };
75
76           var closeIcon = new Button()
77           {
78               Text = "C",
79               PositionUsesPivotPoint = true,
80               PivotPoint = PivotPoint.BottomLeft,
81               ParentOrigin = ParentOrigin.BottomLeft,
82               Size = new Size(50, 50),
83           };
84
85
86           var leftPadding = new View()
87           {
88               PositionUsesPivotPoint = true,
89               PivotPoint = PivotPoint.BottomLeft,
90               ParentOrigin = ParentOrigin.BottomLeft,
91               Size = new Size(50, 50),
92           };
93
94           var rightPadding = new View()
95           {
96               PositionUsesPivotPoint = true,
97               PivotPoint = PivotPoint.BottomLeft,
98               ParentOrigin = ParentOrigin.BottomLeft,
99               Size = new Size(50, 50),
100           };
101
102           rootView.Add(leftPadding);
103           rootView.Add(title);
104           borderView.Add(minimalizeIcon);
105           borderView.Add(maximalizeIcon);
106           borderView.Add(closeIcon);
107           borderView.Add(rightPadding);
108           rootView.Add(borderView);
109
110           minimalizeIcon.TouchEvent += OnMinimizeIconTouched;
111           maximalizeIcon.TouchEvent += OnMaximizeIconTouched;
112           closeIcon.TouchEvent += OnCloseIconTouched;
113           leftPadding.TouchEvent += OnLeftCornerIconTouched;
114           rightPadding.TouchEvent += OnRightCornerIconTouched;
115       }
116
117       public override void OnCreated(View rootView)
118       {
119         base.OnCreated(rootView);
120       }
121
122       public override bool  OnCloseIconTouched(object sender, View.TouchEventArgs e)
123       {
124         base.OnCloseIconTouched(sender, e);
125         return true;
126       }
127
128       public override bool  OnMinimizeIconTouched(object sender, View.TouchEventArgs e)
129       {
130         base.OnMinimizeIconTouched(sender, e);
131         return true;
132       }
133
134       public override void OnResized(int width, int height)
135       {
136         if (rootView != null)
137         {
138           if (this.width > width && hide == false)
139           {
140             title.Hide();
141             hide = true;
142           }
143           else if (this.width < width && hide == true)
144           {
145             title.Show();
146             hide = false;
147           }
148           base.OnResized(width, height);
149         }
150       }
151
152     }
153
154     void CreateSubWindowOne()
155     {
156       if (subWindowOne == null)
157       {
158         subWindowOne = new Window("subwin1", null, new Rectangle(20, 20, 800, 800), false);
159
160         var root = new ImageView()
161         {
162           WidthResizePolicy = ResizePolicyType.FillToParent,
163           HeightResizePolicy = ResizePolicyType.FillToParent,
164           ResourceUrl = imagePath + "gallery-large-9.jpg",
165           CornerRadius = new Vector4(0.03f, 0.03f, 0.03f, 0.03f),
166           CornerRadiusPolicy = VisualTransformPolicyType.Relative,
167         };
168         subWindowOne.Add(root);
169
170         TextLabel text = new TextLabel("Hello Tizen NUI World");
171         text.HorizontalAlignment = HorizontalAlignment.Center;
172         text.VerticalAlignment = VerticalAlignment.Center;
173         text.TextColor = Color.CornflowerBlue;
174         text.HeightResizePolicy = ResizePolicyType.FillToParent;
175         text.WidthResizePolicy = ResizePolicyType.FillToParent;
176         root.Add(text);
177
178         Animation animation = new Animation(2000);
179         animation.AnimateTo(text, "Orientation", new Rotation(new Radian(new Degree(180.0f)), PositionAxis.X), 0, 500);
180         animation.AnimateTo(text, "Orientation", new Rotation(new Radian(new Degree(0.0f)), PositionAxis.X), 500, 1000);
181         animation.Looping = true;
182         animation.Play();
183       }
184       else
185       {
186         subWindowOne.Minimize(false);
187       }
188     }
189
190     void CreateSubWindowTwo()
191     {
192       if (subWindowTwo == null)
193       {
194         IBorderInterface customBorder = new CustomBorder();
195         subWindowTwo = new Window("subwin1", customBorder, new Rectangle(60, 20, 800, 800), false);
196
197         subWindowTwo.BackgroundColor = Color.Red;
198
199         var root = new View(){
200           Layout = new LinearLayout()
201           {
202               LinearAlignment = LinearLayout.Alignment.CenterHorizontal,
203           },
204           WidthResizePolicy = ResizePolicyType.FillToParent,
205           HeightResizePolicy = ResizePolicyType.FillToParent,
206           BackgroundColor = Color.Yellow,
207         };
208
209         var image = new ImageView()
210         {
211           Size = new Size(300, 300),
212           ResourceUrl = imagePath + "gallery-large-5.jpg",
213           CornerRadius = new Vector4(0.03f, 0.03f, 0, 0),
214           CornerRadiusPolicy = VisualTransformPolicyType.Relative,
215         };
216         root.Add(image);
217         subWindowTwo.Add(root);
218       }
219       else
220       {
221         subWindowTwo.Minimize(false);
222       }
223     }
224
225
226
227     void Initialize()
228     {
229         win = NUIApplication.GetDefaultWindow();
230         var root = new ImageView()
231         {
232           WidthResizePolicy = ResizePolicyType.FillToParent,
233           HeightResizePolicy = ResizePolicyType.FillToParent,
234           ResourceUrl = imagePath + "gallery-large-14.jpg",
235           Layout = new LinearLayout()
236           {
237               LinearAlignment = LinearLayout.Alignment.CenterHorizontal,
238               LinearOrientation = LinearLayout.Orientation.Horizontal,
239               CellPadding = new Size(10, 10),
240           }
241
242
243         };
244         win.Add(root);
245
246         var imageViewA = new ImageView()
247         {
248           PositionUsesPivotPoint = true,
249           PivotPoint = PivotPoint.BottomLeft,
250           ParentOrigin = ParentOrigin.BottomLeft,
251           Size = new Size(150, 150),
252           ResourceUrl = imagePath + "gallery-large-9.jpg",
253           CornerRadius = 0.3f,
254           CornerRadiusPolicy = VisualTransformPolicyType.Relative,
255         };
256         root.Add(imageViewA);
257         imageViewA.TouchEvent += (s, e) =>
258         {
259           if (e.Touch.GetState(0) == PointStateType.Up)
260           {
261             CreateSubWindowOne();
262           }
263           return true;
264         };
265
266         var imageViewB = new ImageView()
267         {
268           PositionUsesPivotPoint = true,
269           PivotPoint = PivotPoint.BottomLeft,
270           ParentOrigin = ParentOrigin.BottomLeft,
271           Size = new Size(150, 150),
272           ResourceUrl = imagePath + "gallery-large-5.jpg",
273           CornerRadius = 0.3f,
274           CornerRadiusPolicy = VisualTransformPolicyType.Relative,
275         };
276         root.Add(imageViewB);
277         imageViewB.TouchEvent += (s, e) =>
278         {
279           if (e.Touch.GetState(0) == PointStateType.Up)
280           {
281             CreateSubWindowTwo();
282           }
283           return true;
284         };
285     }
286
287     public void Activate()
288     {
289       Initialize();
290     }
291
292     public void Deactivate()
293     {
294     }
295
296
297   }
298 }