2 using System.Threading;
4 using Tizen.NUI.BaseComponents;
6 namespace NUIFlexLayoutSample
10 public static string resources = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
11 public static readonly string[] s_images = new string[]
13 resources + "images/application-icon-101.png",
14 resources + "images/application-icon-102.png",
15 resources + "images/application-icon-103.png",
16 resources + "images/application-icon-104.png",
17 resources + "images/image-1.jpg",
18 resources + "images/image-2.jpg",
19 resources + "images/image-3.jpg",
23 class Example : NUIApplication
25 public Example() : base()
27 Console.WriteLine("Example()!");
30 protected override void OnCreate()
37 const int MAX_CHILDREN = 7;
38 ImageView[] imageViews = new ImageView[MAX_CHILDREN];
39 private void Initialize()
41 Console.WriteLine("Initialize()!");
42 Window window = Window.Instance;
43 window.BackgroundColor = Color.Green;
45 flexContainer = new View();
46 flexContainer.PositionUsesPivotPoint = true;
47 flexContainer.PivotPoint = PivotPoint.Center;
48 flexContainer.ParentOrigin = ParentOrigin.Center;
49 flexContainer.BackgroundColor = Color.Yellow;
51 for (int index = 0; index < MAX_CHILDREN - 3; index++)
53 imageViews[index] = new ImageView(Images.s_images[index]);
54 imageViews[index].WidthSpecificationFixed = 100;
55 imageViews[index].HeightSpecificationFixed = 100;
56 flexContainer.Add(imageViews[index]);
58 for (int index = MAX_CHILDREN - 3; index < MAX_CHILDREN; index++)
60 imageViews[index] = new ImageView(Images.s_images[index]);
61 imageViews[index].WidthSpecificationFixed = 200;
62 imageViews[index].HeightSpecificationFixed = 200;
63 imageViews[index].Name = "t_image" + (index - 3);
66 var layout = new FlexLayout();
67 layout.LayoutAnimate = true;
68 layout.Direction = FlexLayout.FlexDirection.ColumnReverse;
69 flexContainer.WidthSpecificationFixed = 500;
70 flexContainer.HeightSpecificationFixed = 500;
71 flexContainer.Layout = layout;
73 window.Add(flexContainer);
74 window.KeyEvent += OnKeyEvent;
78 private void OnKeyEvent(object source, Window.KeyEventArgs e)
80 if (e.Key.State == Key.StateType.Down)
82 Console.WriteLine($"key pressed name={e.Key.KeyPressedName}");
83 var tmpLayout = flexContainer.Layout as FlexLayout;
86 switch (e.Key.KeyPressedName)
89 if (cnt1 < 4 && cnt1 > 0)
91 flexContainer.Add(imageViews[cnt1 + 3]);
97 if (cnt1 - 1 < 4 && cnt1 - 1 > 0)
99 View tmp = flexContainer.FindChildByName("t_image" + (cnt1 - 1));
102 flexContainer.Remove(tmp);
109 var vertical = new FlexLayout();
110 vertical.LayoutAnimate = true;
111 vertical.Direction = FlexLayout.FlexDirection.Column;
112 flexContainer.Layout = vertical;
116 var horizon = new FlexLayout();
117 horizon.LayoutAnimate = true;
118 horizon.Direction = FlexLayout.FlexDirection.Row;
119 flexContainer.Layout = horizon;
123 if (flexContainer.LayoutDirection == ViewLayoutDirectionType.LTR) { flexContainer.LayoutDirection = ViewLayoutDirectionType.RTL; }
124 else { flexContainer.LayoutDirection = ViewLayoutDirectionType.LTR; }
129 tmpLayout.Direction = (FlexLayout.FlexDirection)dir;
133 var justi = cnt2 % 5;
134 tmpLayout.Justification = (FlexLayout.FlexJustification)justi;
139 tmpLayout.WrapType = (FlexLayout.FlexWrapType)wrap;
143 var align = cnt2 % 5;
144 tmpLayout.ItemsAlignment = (FlexLayout.AlignmentType)align;
152 static void _Main(string[] args)
154 Example layoutSample = new Example();
155 layoutSample.Run(args);