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 switch (e.Key.KeyPressedName)
86 if (cnt1 < 4 && cnt1 > 0)
88 flexContainer.Add(imageViews[cnt1 + 3]);
94 if (cnt1 - 1 < 4 && cnt1 - 1 > 0)
96 View tmp = flexContainer.FindChildByName("t_image" + (cnt1 - 1));
99 flexContainer.Remove(tmp);
106 var vertical = new FlexLayout();
107 vertical.LayoutAnimate = true;
108 vertical.Direction = FlexLayout.FlexDirection.Column;
109 flexContainer.Layout = vertical;
113 var horizon = new FlexLayout();
114 horizon.LayoutAnimate = true;
115 horizon.Direction = FlexLayout.FlexDirection.Row;
116 flexContainer.Layout = horizon;
120 if (flexContainer.LayoutDirection == ViewLayoutDirectionType.LTR) { flexContainer.LayoutDirection = ViewLayoutDirectionType.RTL; }
121 else { flexContainer.LayoutDirection = ViewLayoutDirectionType.LTR; }
125 var tmpLayout = flexContainer.Layout as FlexLayout;
126 if (tmpLayout.WrapType == FlexLayout.FlexWrapType.NoWrap) { tmpLayout.WrapType = FlexLayout.FlexWrapType.Wrap; }
127 else { tmpLayout.WrapType = FlexLayout.FlexWrapType.NoWrap; }
134 static void Main(string[] args)
136 Example layoutSample = new Example();
137 layoutSample.Run(args);