1 using System.Collections.Generic;
2 using Tizen.NUI.BaseComponents;
3 using Tizen.NUI.Components;
5 namespace Tizen.NUI.Samples
7 public class PopupSample : IExample
13 private TextLabel[] createText = new TextLabel[2];
15 private Popup popup = null;
16 private Popup popup2 = null;
17 private TextLabel contentText = null;
18 private TextLabel contentText2 = null;
19 private int index = 0;
20 private int index2 = 0;
21 private Button button = null;
23 private static string[] buttonStyles = new string[]
30 private static Color[] color = new Color[]
32 new Color(0.05f, 0.63f, 0.9f, 1),//#ff0ea1e6
33 new Color(0.14f, 0.77f, 0.28f, 1),//#ff24c447
34 new Color(0.75f, 0.46f, 0.06f, 1),//#ffec7510
35 new Color(0.59f, 0.38f, 0.85f, 1),//#ff9762d9
37 public void Activate()
39 Window window = NUIApplication.GetDefaultWindow();
43 Size = new Size(1920, 1080),
44 BackgroundColor = new Color(0.7f, 0.9f, 0.8f, 1.0f),
50 Size = new Size(1920, 1080),
52 parent1.Layout = new LinearLayout()
54 LinearOrientation = LinearLayout.Orientation.Horizontal,
55 LinearAlignment = LinearLayout.Alignment.Center,
56 CellPadding = new Size(50, 50)
61 Size = new Size(1032, 980),
63 parent2.Layout = new LinearLayout()
65 LinearOrientation = LinearLayout.Orientation.Vertical,
66 LinearAlignment = LinearLayout.Alignment.CenterHorizontal,
67 CellPadding = new Size(400, 400)
70 ///////////////////////////////////////////////Create by Property//////////////////////////////////////////////////////////
71 createText[0] = new TextLabel();
72 createText[0].Text = "Create Popup just by properties";
73 createText[0].WidthSpecification = 500;
74 createText[0].HeightSpecification = 100;
75 parent2.Add(createText[0]);
78 popup.MinimumSize = new Size(1032, 184);
79 popup.Size = new Size(1032, 400);
80 popup.Position = new Position(150, 100);
83 popup.Title.PointSize = 25;
84 popup.Title.Size = new Size(0, 68);
85 popup.Title.PositionUsesPivotPoint = true;
86 popup.Title.ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft;
87 popup.Title.PivotPoint = Tizen.NUI.PivotPoint.TopLeft;
88 popup.Title.HorizontalAlignment = HorizontalAlignment.Begin;
89 popup.Title.VerticalAlignment = VerticalAlignment.Bottom;
90 popup.Title.Position = new Position(64, 52);
91 popup.Title.Text = "Popup Title";
92 popup.Title.Padding = 0;
95 popup.ImageShadow = new ImageShadow(CommonResource.GetFHResourcePath() + "11. Popup/popup_background_shadow.png", new Rectangle(24, 24, 24, 24), extents: new Vector2(48, 48));
98 popup.BackgroundImage = CommonResource.GetFHResourcePath() + "11. Popup/popup_background.png";
99 popup.BackgroundImageBorder = new Rectangle(0, 0, 81, 81);
102 popup.AddButton("Yes");
103 popup.AddButton("Exit");
104 popup.ButtonBackground = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_normal.png";
105 popup.ButtonBackgroundBorder = new Rectangle(5, 5, 5, 5);
106 popup.ButtonOverLayBackgroundColorSelector = new Selector<Color>
108 Normal = new Color(1.0f, 1.0f, 1.0f, 0.5f),
109 Pressed = new Color(0.0f, 0.0f, 0.0f, 0.5f)
111 popup.ButtonImageShadow = new ImageShadow(CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png", new Rectangle(5, 5, 5, 5));
112 popup.ButtonTextColor = color[0];
113 popup.ButtonHeight = 132;
114 popup.PopupButtonClickEvent += PopupButtonClickedEvent;
115 popup.LayoutDirectionChanged += PopupLayoutDirectionChanged;
118 contentText = new TextLabel();
119 contentText.Size = new Size(1032, 100);
120 contentText.PointSize = 20;
121 contentText.HorizontalAlignment = HorizontalAlignment.Begin;
122 contentText.VerticalAlignment = VerticalAlignment.Center;
123 contentText.Text = "Popup ButtonStyle is " + buttonStyles[index];
124 contentText.TextColor = new Color(0,0,222,1);
125 popup.AddContentText(contentText);
127 ///////////////////////////////////////////////Create by Attributes//////////////////////////////////////////////////////////
128 createText[1] = new TextLabel();
129 createText[1].Text = "Create Popup just by Attributes";
130 createText[1].WidthSpecification = 500;
131 createText[1].HeightSpecification = 100;
132 parent2.Add(createText[1]);
134 PopupStyle attrs = new PopupStyle
136 MinimumSize = new Size(1032, 184),
137 BackgroundImage = new Selector<string> { All = CommonResource.GetFHResourcePath() + "11. Popup/popup_background.png" },
138 BackgroundImageBorder = new Selector<Rectangle> { All = new Rectangle(0, 0, 81, 81) },
139 ImageShadow = new ImageShadow(CommonResource.GetFHResourcePath() + "11. Popup/popup_background_shadow.png", new Rectangle(24, 24, 24, 24), extents: new Vector2(48, 48)),
140 Title = new TextLabelStyle
142 PointSize = new Selector<float?> { All = 25 },
143 TextColor = new Selector<Color> { All = Color.Black },
144 Size = new Size(0, 68),
145 PositionUsesPivotPoint = true,
146 ParentOrigin = Tizen.NUI.ParentOrigin.TopLeft,
147 PivotPoint = Tizen.NUI.PivotPoint.TopLeft,
148 HorizontalAlignment = HorizontalAlignment.Begin,
149 VerticalAlignment = VerticalAlignment.Bottom,
150 Position = new Position(64, 52),
151 Text = new Selector<string> { All = "Popup Title" },
153 Buttons = new ButtonStyle
155 PositionUsesPivotPoint = true,
156 ParentOrigin = Tizen.NUI.ParentOrigin.BottomLeft,
157 PivotPoint = Tizen.NUI.PivotPoint.BottomLeft,
158 BackgroundImage = new Selector<string> { All = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_normal.png" },
159 BackgroundImageBorder = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
160 ImageShadow = new ImageShadow(CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png", new Rectangle(5, 5, 5, 5)),
161 Overlay = new ImageViewStyle
163 PositionUsesPivotPoint = true,
164 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
165 PivotPoint = Tizen.NUI.PivotPoint.Center,
166 WidthResizePolicy = ResizePolicyType.FillToParent,
167 HeightResizePolicy = ResizePolicyType.FillToParent,
168 BackgroundColor = new Selector<Color>
170 Normal = new Color(1.0f, 1.0f, 1.0f, 0.5f),
171 Pressed = new Color(0.0f, 0.0f, 0.0f, 0.5f),
174 Text = new TextLabelStyle
176 PositionUsesPivotPoint = true,
177 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
178 PivotPoint = Tizen.NUI.PivotPoint.Center,
179 HorizontalAlignment = HorizontalAlignment.Center,
180 VerticalAlignment = VerticalAlignment.Center,
181 TextColor = new Selector<Color> { All = color[index2] }
186 popup2 = new Popup(attrs);
187 popup2.Size = new Size(1032, 400);
188 popup2.Position = new Position(150, 600);
189 popup2.AddButton("Yes");
190 popup2.AddButton("Exit");
191 popup2.ButtonHeight = 132;
192 popup2.PopupButtonClickEvent += PopupButtonClickedEvent;
193 popup2.LayoutDirectionChanged += Popup2LayoutDirectionChanged;
196 contentText2 = new TextLabel();
197 contentText2.Size = new Size(1032, 100);
198 contentText2.PointSize = 20;
199 contentText2.HorizontalAlignment = HorizontalAlignment.Begin;
200 contentText2.VerticalAlignment = VerticalAlignment.Center;
201 contentText2.Text = "Popup2 ButtonStyle is " + buttonStyles[index];
202 popup2.ContentView.Add(contentText2);
204 button = new Button();
205 button.BackgroundImage = CommonResource.GetTVResourcePath() + "component/c_buttonbasic/c_basic_button_white_bg_normal_9patch.png";
206 button.BackgroundImageBorder = new Rectangle(4, 4, 5, 5);
207 button.WidthSpecification = 580;
208 button.HeightSpecification = 80;
209 button.TextLabel.Text = "LayoutDirection is left to right";
210 button.Clicked += ButtonClicked;
212 parent1.Add(parent2);
217 private void Popup2LayoutDirectionChanged(object sender, View.LayoutDirectionChangedEventArgs e)
219 if (contentText2.HorizontalAlignment == HorizontalAlignment.Begin)
221 contentText2.HorizontalAlignment = HorizontalAlignment.End;
223 else if (contentText2.HorizontalAlignment == HorizontalAlignment.End)
225 contentText2.HorizontalAlignment = HorizontalAlignment.Begin;
229 private void PopupLayoutDirectionChanged(object sender, View.LayoutDirectionChangedEventArgs e)
231 if (contentText.HorizontalAlignment == HorizontalAlignment.Begin)
233 contentText.HorizontalAlignment = HorizontalAlignment.End;
235 else if (contentText.HorizontalAlignment == HorizontalAlignment.End)
237 contentText.HorizontalAlignment = HorizontalAlignment.Begin;
241 private void PopupButtonClickedEvent(object sender, Popup.ButtonClickEventArgs e)
243 Popup obj = sender as Popup;
244 if (obj != null && e.ButtonIndex == 0)
249 index = index % buttonStyles.Length;
250 obj.ButtonTextColor = color[index];
251 contentText.Text = "Popup ButtonStyle is " + buttonStyles[index];
256 index2 = index2 % buttonStyles.Length;
257 obj.ButtonTextColor = color[index2];
258 contentText2.Text = "Popup2 ButtonStyle is " + buttonStyles[index2];
263 private void ButtonClicked(object sender, ClickedEventArgs e)
265 if (popup.LayoutDirection == ViewLayoutDirectionType.LTR)
267 popup.LayoutDirection = ViewLayoutDirectionType.RTL;
268 popup2.LayoutDirection = ViewLayoutDirectionType.RTL;
269 button.TextLabel.Text = "LayoutDirection is right to left";
273 popup.LayoutDirection = ViewLayoutDirectionType.LTR;
274 popup2.LayoutDirection = ViewLayoutDirectionType.LTR;
275 button.TextLabel.Text = "LayoutDirection is left to right";
279 public void Deactivate()
285 if (contentText != null)
287 popup.ContentView.Remove(contentText);
288 contentText.Dispose();
300 if (contentText2 != null)
302 popup2.ContentView.Remove(contentText2);
303 contentText2.Dispose();
313 if (createText[0] != null)
315 root.Remove(createText[0]);
316 createText[0].Dispose();
317 createText[0] = null;
320 if (createText[1] != null)
322 root.Remove(createText[1]);
323 createText[1].Dispose();
324 createText[1] = null;
334 NUIApplication.GetDefaultWindow().Remove(root);