2 using Tizen.NUI.BaseComponents;
4 using Tizen.NUI.Components;
7 namespace Tizen.NUI.Samples
9 public class ScrollableFocusAllChildrenSample : IExample
14 private string GetChildText(View parent)
18 foreach(View child in parent.Children)
20 if (child is TextLabel label)
22 return $"{label.Text}";
30 private string GetLabelText(int i)
45 public void Activate()
48 Random rnd = new Random();
49 Window window = NUIApplication.GetDefaultWindow();
53 BackgroundColor = Color.White,
54 WidthSpecification = LayoutParamPolicies.MatchParent,
55 HeightSpecification = LayoutParamPolicies.MatchParent,
56 Layout = new LinearLayout()
58 LinearOrientation = LinearLayout.Orientation.Vertical,
59 HorizontalAlignment = HorizontalAlignment.Center,
60 CellPadding = new Size(10, 10),
65 var focusInfo = new TextLabel()
67 BackgroundColor = Color.Yellow,
68 TextColor = Color.Red,
69 Text = "Prev:[N/A] Current:[N/A]"
73 FocusManager.Instance.EnableDefaultAlgorithm(true);
74 FocusManager.Instance.FocusChanged += (object s, FocusManager.FocusChangedEventArgs e) =>
76 string prev = "[N/A]";
78 if (e.Previous != null)
80 var prevView = e.Previous;
81 prev = $"{prevView.Name}[{prevView.ID}]{GetChildText(prevView)}";
84 if (e.Current != null)
86 var curView = e.Current;
87 cur = $"{curView.Name}[{curView.ID}]{GetChildText(curView)}";
90 focusInfo.Text = $"Prev:{prev} Current:{cur}";
91 Console.WriteLine($"Focus Changed Prev:{prev} => Current:{cur}");
94 var top = new Button()
97 FocusableInTouch = true,
102 var verticalScrollView = new ScrollableBase()
104 ScrollingDirection = ScrollableBase.Direction.Vertical,
105 WidthSpecification = LayoutParamPolicies.MatchParent,
106 HeightSpecification = LayoutParamPolicies.MatchParent,
107 BackgroundColor = Color.Gray,
108 Layout = new LinearLayout
110 LinearOrientation = LinearLayout.Orientation.Vertical,
111 HorizontalAlignment = HorizontalAlignment.Center,
112 CellPadding = new Size2D(10, 30),
115 root.Add(verticalScrollView);
117 for (int i = 0; i < SCROLLMAX; i++)
119 var colorItem = new View()
121 WidthSpecification = LayoutParamPolicies.MatchParent,
122 HeightSpecification = LayoutParamPolicies.WrapContent,
123 BackgroundColor = new Color((float)rnd.Next(256)/256f, (float)rnd.Next(256)/256f, (float)rnd.Next(256)/256f, 1),
125 FocusableInTouch = true,
126 Layout = new LinearLayout
128 LinearOrientation = LinearLayout.Orientation.Horizontal,
129 VerticalAlignment = VerticalAlignment.Center,
130 CellPadding = new Size2D(10, 10),
133 var label = new TextLabel()
135 Text = GetLabelText(i),
138 colorItem.Add(label);
139 verticalScrollView.Add(colorItem);
142 var middle = new Button()
145 FocusableInTouch = true,
150 var horizontalLayout = new View()
152 BackgroundColor = Color.White,
153 WidthSpecification = LayoutParamPolicies.MatchParent,
154 HeightSpecification = LayoutParamPolicies.MatchParent,
155 Layout = new LinearLayout()
157 LinearOrientation = LinearLayout.Orientation.Horizontal,
158 VerticalAlignment = VerticalAlignment.Center,
159 CellPadding = new Size(10, 10),
162 root.Add(horizontalLayout);
164 var leftIcon = new RadioButton()
166 WidthSpecification = 50,
167 HeightSpecification = 50,
169 FocusableInTouch = true,
171 horizontalLayout.Add(leftIcon);
173 var horizontalScrollView = new ScrollableBase()
175 ScrollingDirection = ScrollableBase.Direction.Horizontal,
176 WidthSpecification = LayoutParamPolicies.MatchParent,
177 HeightSpecification = LayoutParamPolicies.MatchParent,
178 BackgroundColor = Color.Gray,
179 Layout = new LinearLayout
181 LinearOrientation = LinearLayout.Orientation.Horizontal,
182 VerticalAlignment = VerticalAlignment.Center,
183 CellPadding = new Size2D(30, 10),
186 horizontalLayout.Add(horizontalScrollView);
188 for (int i = 0; i < SCROLLMAX; i++)
190 var colorItem = new View()
192 WidthSpecification = LayoutParamPolicies.WrapContent,
193 HeightSpecification = LayoutParamPolicies.MatchParent,
194 BackgroundColor = new Color((float)rnd.Next(256)/256f, (float)rnd.Next(256)/256f, (float)rnd.Next(256)/256f, 1),
196 FocusableInTouch = true,
197 Layout = new LinearLayout
199 LinearOrientation = LinearLayout.Orientation.Vertical,
200 HorizontalAlignment = HorizontalAlignment.Center,
201 CellPadding = new Size2D(10, 10),
204 var label = new TextLabel()
206 Text = GetLabelText(i),
209 colorItem.Add(label);
210 horizontalScrollView.Add(colorItem);
213 var rightIcon = new RadioButton()
215 WidthSpecification = 50,
216 HeightSpecification = 50,
218 FocusableInTouch = true,
220 horizontalLayout.Add(rightIcon);
222 var bottom = new Button()
225 FocusableInTouch = true,
231 public void Deactivate()
235 NUIApplication.GetDefaultWindow().Remove(root);