2 using Tizen.NUI.BaseComponents;
3 using Tizen.NUI.Components;
6 namespace Tizen.NUI.Samples
10 public class SiblingOrderTest : IExample
16 const string t = "NUITEST";
17 const int W1 = 700, H1 = 800;
18 const int W2 = 230, H2 = 150;
19 public void Activate()
21 win = NUIApplication.GetDefaultWindow();
24 v.Size = new Size(W1, H1);
25 v.Position = new Position(10, 10);
26 v.BackgroundColor = new Color(0.8f, 0.8f, 0.8f, 1.0f);
31 Size = new Size(700, 100),
32 Position = new Position(10, H1 + 20),
33 Text = "add new child",
35 b1.Clicked += B1_Clicked;
40 Size = new Size(700, 100),
41 Position = new Position(10, H1 + 20 + 120),
42 Text = "refresh sibling order",
44 b2.Clicked += B2_Clicked;
49 Size = new Size(700, 100),
50 Position = new Position(10, H1 + 20 + 120 + 120),
51 Text = "place children to fit parent",
53 b3.Clicked += B3_Clicked;
56 text = new TextLabel()
58 Size = new Size(700, 100),
59 Position = new Position(10, H1 + 20 + 120 + 120 + 120),
60 Text = "push buttons above",
61 BackgroundColor = Color.Yellow,
67 private void B1_Clicked(object sender, ClickedEventArgs e)
69 string n = "CH" + (v.ChildCount + 1);
70 var ch = new TextLabel();
71 Random r = new Random();
72 int so = r.Next(0, (int)v.ChildCount);
74 ch.Size = new Size(W2, H2);
75 ch.Position = new Position(100, 900);
76 ch.BackgroundColor = new Color((float)r.NextDouble(), (float)r.NextDouble(), (float)r.NextDouble(), 0.5f);
80 // SiblingOrder can set the order of mine in the sibling list owned by parent.
81 // the lower value of SiblingOrder means it goes lower to the bottom so that it will be covered by higher valued siblings.
82 // (Vise versa, if SiblingOrder goes to high, the object will be up to the top which can be said as a screen.)
83 //if new added sibling has same value with previously existed sibling, the existed siblings, which have higer value than new sibling, will get +1 and will be rearranged.
84 // (this means the new added sibling will be placed right under the old sibling that has same SiblingOrder value)
85 //Therefore, SiblingOrder will be automatically set as parent's ChildCount + 1 when child itself is added to parent by "Add()".
87 ch.Text = ch.Name + " SO=" + ch.SiblingOrder;
89 var a = new Animation(500);
90 var targetposition = GetPositionFromSiblingOrder(ch.SiblingOrder);
91 a.AnimateTo(ch, "position", new Position((targetposition.X + W2 / 2), (targetposition.Y + H2 / 2), 0));
93 a.Finished += A_Finished;
96 private void B2_Clicked(object sender, ClickedEventArgs e)
98 for(int i=0; i < v.ChildCount; i++)
100 var ch = v.GetChildAt((uint)i) as TextLabel;
103 ch.Text = ch.Name + " SO=" + ch.SiblingOrder;
108 private void B3_Clicked(object sender, ClickedEventArgs e)
110 for (int i = 0; i < v.ChildCount; i++)
112 var ch = v.GetChildAt((uint)i);
113 var ani = new Animation(500);
114 ani.AnimateTo(ch, "position", GetPositionFromSiblingOrder(i), new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOut));
119 private void A_Finished(object sender, EventArgs e)
121 var text = win.GetDefaultLayer().FindChildByName("status") as TextLabel;
124 int i = (int)v.ChildCount;
125 text.Text = $"child {i} (CH{i}) is just added!";
129 Position GetPositionFromSiblingOrder(int so)
131 int px = (so % (W1 / W2)) * W2;
132 int py = (so / (W1 / W2)) * H2;
133 return new Position(px, py, 0);
136 public void Deactivate()
138 b1.Clicked -= B1_Clicked;
139 b2.Clicked -= B2_Clicked;
140 b3.Clicked -= B3_Clicked;