1 using Tizen.NUI.BaseComponents;
2 using Tizen.NUI.Components;
4 namespace Tizen.NUI.Samples
6 public class SliderSample : IExample
8 private const float MIN_VALUE = 0;
9 private const float MAX_VALUE = 100;
12 private View top_parent, bottom_parent, ver_slider_parent, hori_slider_parent;
13 private TextLabel[] createText = new TextLabel[2];
14 private TextLabel[] inforText = new TextLabel[2];
15 private Slider[] slider_null_style = new Slider[4];
16 private Slider[] slider_style = new Slider[4];
18 public void Activate()
20 Window window = NUIApplication.GetDefaultWindow();
24 Size = new Size(1920, 1080),
25 BackgroundColor = new Color(0.7f, 0.9f, 0.8f, 1.0f),
27 root.Layout = new LinearLayout() { LinearOrientation = LinearLayout.Orientation.Vertical };
30 // Textlabel of Null style construction/Style construction and infoText
33 // Various kinds of Slider
37 private void InitSliders()
39 // Null style construction
40 slider_null_style[0] = CreateByProperty(800, 50, 20, Slider.DirectionType.Horizontal);
41 slider_null_style[1] = CreateByProperty(800, 50, 30, Slider.DirectionType.Horizontal);
42 slider_null_style[1].LowIndicatorTextContent = "SubText";
43 slider_null_style[1].LowIndicatorSize = new Size(100, 40);
44 slider_null_style[2] = CreateByProperty(50, 400, 20, Slider.DirectionType.Vertical);
45 slider_null_style[3] = CreateByProperty(50, 400, 30, Slider.DirectionType.Vertical);
46 slider_null_style[3].LowIndicatorTextContent = "SubText";
47 slider_null_style[3].LowIndicatorSize = new Size(100, 40);
50 SliderStyle st = new SliderStyle
53 Track = new ImageViewStyle
55 BackgroundColor = new Selector<Color>
57 All = new Color(0, 0, 0, 0.1f),
61 Progress = new ImageViewStyle
63 BackgroundColor = new Selector<Color>
65 All = new Color(0.05f, 0.63f, 0.9f, 1),
69 Thumb = new ImageViewStyle
71 Size = new Size(60, 60),
72 ResourceUrl = new Selector<string>
74 Normal = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_slide_handler_normal.png",
75 Pressed = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_slide_handler_press.png",
77 BackgroundImage = new Selector<string>
80 Pressed = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_slide_handler_effect.png",
84 slider_style[0] = CreateByStyle(st, 800, 50, 20, Slider.DirectionType.Horizontal);
85 slider_style[1] = CreateByStyle(st, 800, 50, 30, Slider.DirectionType.Horizontal);
86 slider_style[1].LowIndicatorTextContent = "SubText";
87 slider_style[1].LowIndicatorSize = new Size(100, 40);
88 slider_style[2] = CreateByStyle(st, 50, 400, 20, Slider.DirectionType.Vertical);
89 slider_style[3] = CreateByStyle(st, 50, 400, 30, Slider.DirectionType.Vertical);
90 slider_style[3].LowIndicatorTextContent = "SubText";
91 slider_style[3].LowIndicatorSize = new Size(100, 40);
94 private void CreateTopView()
96 top_parent = new View() { Size = new Size(1920, 240) };
97 top_parent.Layout = new GridLayout() { Rows = 2, GridOrientation = GridLayout.Orientation.Horizontal };
100 for (int i = 0; i < 2; i++)
102 createText[i] = new TextLabel();
103 createText[i].PointSize = 20;
104 createText[i].TextColor = Color.Black;
105 createText[i].Size = new Size(600, 100);
106 createText[i].Margin = new Extents(200, 100, 40, 0);
107 createText[i].BackgroundColor = Color.Magenta;
108 createText[i].HorizontalAlignment = HorizontalAlignment.Center;
109 createText[i].VerticalAlignment = VerticalAlignment.Center;
110 top_parent.Add(createText[i]);
112 inforText[i] = new TextLabel();
113 inforText[i].PointSize = 20;
114 inforText[i].TextColor = Color.Blue;
115 inforText[i].Text = "currentValue = ";
116 inforText[i].BackgroundColor = new Color(0, 0, 0, 0.1f);
117 inforText[i].HorizontalAlignment = HorizontalAlignment.Center;
118 inforText[i].VerticalAlignment = VerticalAlignment.Center;
119 top_parent.Add(inforText[i]);
122 // TextLabel of "Null style construction"
123 createText[0].Text = "Null style constructions";
125 // TextLabel of "Style construction"
126 createText[1].Text = "Style construction";
129 private void CreateBottomView()
131 bottom_parent = new View() { Size = new Size(1920, 840) };
132 bottom_parent.Layout = new LinearLayout() { LinearOrientation = LinearLayout.Orientation.Vertical, CellPadding = new Size2D(0, 0) };
133 root.Add(bottom_parent);
138 // Add Horizontal Slider
139 hori_slider_parent = new View() { Size = new Size(1920, 160) };
140 hori_slider_parent.Layout = new GridLayout() { Rows = 2, GridOrientation = GridLayout.Orientation.Horizontal };
141 bottom_parent.Add(hori_slider_parent);
142 slider_null_style[0].Margin = new Extents(100, 0, 30, 0);
143 hori_slider_parent.Add(slider_null_style[0]);
144 hori_slider_parent.Add(slider_null_style[1]);
145 hori_slider_parent.Add(slider_style[0]);
146 hori_slider_parent.Add(slider_style[1]);
148 // Add vertical Slider
149 ver_slider_parent = new View() { Size = new Size(1920, 680) };
150 ver_slider_parent.Layout = new LinearLayout() { LinearOrientation = LinearLayout.Orientation.Horizontal, LinearAlignment = LinearLayout.Alignment.CenterVertical, CellPadding = new Size2D(200, 0) };
151 bottom_parent.Add(ver_slider_parent);
152 slider_null_style[2].Margin = new Extents(350, 0, 0, 0);
153 slider_style[2].Margin = new Extents(400, 0, 0, 0);
154 ver_slider_parent.Add(slider_null_style[2]);
155 ver_slider_parent.Add(slider_null_style[3]);
156 ver_slider_parent.Add(slider_style[2]);
157 ver_slider_parent.Add(slider_style[3]);
160 public void Deactivate()
164 NUIApplication.GetDefaultWindow().Remove(root);
165 for (int i = 0; i < 2; i++)
167 if (createText[i] != null)
169 createText[i].Dispose();
170 createText[i] = null;
173 if (inforText[i] != null)
175 inforText[i].Dispose();
180 for (int j = 0; j < 4; j++)
182 if (slider_null_style[j] != null)
184 slider_null_style[j].Dispose();
185 slider_null_style[j] = null;
188 if (slider_style[j] != null)
190 slider_style[j].Dispose();
191 slider_style[j] = null;
195 if (top_parent != null)
197 top_parent.Dispose();
201 if (bottom_parent != null)
203 bottom_parent.Dispose();
204 bottom_parent = null;
207 if (ver_slider_parent != null)
209 ver_slider_parent.Dispose();
210 ver_slider_parent = null;
213 if (hori_slider_parent != null)
215 hori_slider_parent.Dispose();
216 hori_slider_parent = null;
223 private Slider CreateByProperty(int w, int h, int curValue, Slider.DirectionType dir)
225 // Setting the property of selector is not supported now, so add these in style first.
226 SliderStyle st = new SliderStyle
228 Thumb = new ImageViewStyle()
230 ResourceUrl = new Selector<string>
232 Normal = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_slide_handler_normal.png",
233 Pressed = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_slide_handler_press.png",
235 BackgroundImage = new Selector<string>
238 Pressed = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_slide_handler_effect.png",
242 Slider source = new Slider(st);
243 source.TrackThickness = 4;
244 source.ThumbSize = new Size(60, 60);
245 source.BgTrackColor = new Color(0, 0, 0, 0.1f);
246 source.SlidedTrackColor = new Color(0.05f, 0.63f, 0.9f, 1);
247 source.Direction = dir;
248 source.Focusable = true;
249 source.MinValue = MIN_VALUE;
250 source.MaxValue = MAX_VALUE;
251 source.StateChangedEvent += OnStateChanged;
252 source.ValueChanged += OnValueChanged;
253 source.SlidingFinished += OnSlidingFinished;
254 source.Size = new Size(w, h);
255 source.CurrentValue = curValue;
259 private Slider CreateByStyle(SliderStyle st, int w, int h, int curValue, Slider.DirectionType dir)
261 // input style in construction
262 Slider source = new Slider(st);
263 source.Direction = dir;
265 source.Focusable = true;
266 source.MinValue = MIN_VALUE;
267 source.MaxValue = MAX_VALUE;
268 source.StateChangedEvent += OnStateChanged;
269 source.ValueChanged += OnValueChanged;
270 source.SlidingFinished += OnSlidingFinished;
271 source.Size = new Size(w, h);
272 source.CurrentValue = curValue;
276 private void OnValueChanged(object sender, SliderValueChangedEventArgs args)
278 Slider source = sender as Slider;
281 if (source == slider_style[0] || source == slider_style[1] || source == slider_style[2] || source == slider_style[3])
283 inforText[1].Text = "currentValue = " + args.CurrentValue;
287 inforText[0].Text = "currentValue = " + args.CurrentValue;
292 private void OnSlidingFinished(object sender, SliderSlidingFinishedEventArgs args)
294 Slider source = sender as Slider;
297 if (source == slider_style[0] || source == slider_style[1] || source == slider_style[2] || source == slider_style[3])
299 inforText[1].Text = "Finished currentValue = " + args.CurrentValue;
303 inforText[0].Text = "Finished currentValue = " + args.CurrentValue;
308 private void OnStateChanged(object sender, Slider.StateChangedArgs args)
310 if (sender is Tizen.NUI.Components.Slider)
312 Tizen.NUI.Components.Slider slider = sender as Tizen.NUI.Components.Slider;