2 * Copyright(c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.ComponentModel;
19 using System.Collections.Generic;
20 using Tizen.NUI.Binding;
21 using Tizen.NUI.BaseComponents;
23 namespace Tizen.NUI.Components
26 /// ButtonGroup is a group of buttons which can be set common property<br />
28 /// <since_tizen> 3 </since_tizen>
29 [EditorBrowsable(EditorBrowsableState.Never)]
30 public class ButtonGroup : BindableObject, global::System.IDisposable
32 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
33 [EditorBrowsable(EditorBrowsableState.Never)]
34 public static readonly BindableProperty ItemheightProperty = BindableProperty.Create(nameof(Itemheight), typeof(float), typeof(ButtonGroup), 0.0f, propertyChanged: (bindable, oldValue, newValue) =>
36 ButtonGroup btGroup = (ButtonGroup)bindable;
37 if (btGroup.itemGroup != null && newValue != null)
39 foreach (Button btn in btGroup.itemGroup)
41 btn.Style.SizeHeight = (float)newValue;
43 btGroup.itemheight = (float)newValue;
46 defaultValueCreator: (bindable) =>
48 ButtonGroup btGroup = (ButtonGroup)bindable;
49 return btGroup.itemheight;
52 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
53 [EditorBrowsable(EditorBrowsableState.Never)]
54 public static readonly BindableProperty ItemPointSizeProperty = BindableProperty.Create(nameof(ItemPointSize), typeof(float), typeof(ButtonGroup), 0.0f, propertyChanged: (bindable, oldValue, newValue) =>
56 ButtonGroup btGroup = (ButtonGroup)bindable;
57 if (btGroup.itemGroup != null && newValue != null)
59 foreach (Button btn in btGroup.itemGroup)
61 btn.Style.Text.PointSize = (float)newValue;
63 btGroup.itemPointSize = (float)newValue;
66 defaultValueCreator: (bindable) =>
68 ButtonGroup btGroup = (ButtonGroup)bindable;
69 return btGroup.itemPointSize;
72 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
73 [EditorBrowsable(EditorBrowsableState.Never)]
74 public static readonly BindableProperty ItemFontFamilyProperty = BindableProperty.Create(nameof(ItemFontFamily), typeof(string), typeof(ButtonGroup), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
76 ButtonGroup btGroup = (ButtonGroup)bindable;
77 if (btGroup.itemGroup != null && newValue != null)
79 foreach (Button btn in btGroup.itemGroup)
81 btn.Style.Text.FontFamily = (string)newValue;
83 btGroup.itemFontFamily = (string)newValue;
86 defaultValueCreator: (bindable) =>
88 ButtonGroup btGroup = (ButtonGroup)bindable;
89 return btGroup.itemFontFamily;
92 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
93 [EditorBrowsable(EditorBrowsableState.Never)]
94 public static readonly BindableProperty ItemTextColorProperty = BindableProperty.Create(nameof(ItemTextColor), typeof(Color), typeof(ButtonGroup), Color.Black, propertyChanged: (bindable, oldValue, newValue) =>
96 ButtonGroup btGroup = (ButtonGroup)bindable;
97 if (btGroup.itemGroup != null && newValue != null)
99 foreach (Button btn in btGroup.itemGroup)
101 btn.Style.Text.TextColor = (Color)newValue;
103 btGroup.itemTextColor = (Color)newValue;
106 defaultValueCreator: (bindable) =>
108 ButtonGroup btGroup = (ButtonGroup)bindable;
109 return btGroup.itemTextColor;
112 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
113 [EditorBrowsable(EditorBrowsableState.Never)]
114 public static readonly BindableProperty ItemTextAlignmentProperty = BindableProperty.Create(nameof(ItemTextAlignment), typeof(HorizontalAlignment), typeof(ButtonGroup), new HorizontalAlignment(), propertyChanged: (bindable, oldValue, newValue) =>
116 ButtonGroup btGroup = (ButtonGroup)bindable;
117 if (btGroup.itemGroup != null && newValue != null)
119 foreach (Button btn in btGroup.itemGroup)
121 btn.Style.Text.HorizontalAlignment = (HorizontalAlignment)newValue;
123 btGroup.itemTextAlignment = (HorizontalAlignment)newValue;
126 defaultValueCreator: (bindable) =>
128 ButtonGroup btGroup = (ButtonGroup)bindable;
129 return btGroup.itemTextAlignment;
132 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
133 [EditorBrowsable(EditorBrowsableState.Never)]
134 public static readonly BindableProperty OverLayBackgroundColorSelectorProperty = BindableProperty.Create(nameof(OverLayBackgroundColorSelector), typeof(Selector<Color>), typeof(ButtonGroup), new Selector<Color>(), propertyChanged: (bindable, oldValue, newValue) =>
136 ButtonGroup btGroup = (ButtonGroup)bindable;
137 if (btGroup.itemGroup != null && newValue != null)
139 foreach (Button btn in btGroup.itemGroup)
141 btn.Style.Overlay.BackgroundColor = (Selector<Color>)newValue;
143 btGroup.overLayBackgroundColorSelector = (Selector<Color>)newValue;
146 defaultValueCreator: (bindable) =>
148 ButtonGroup btGroup = (ButtonGroup)bindable;
149 return btGroup.overLayBackgroundColorSelector;
152 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
153 [EditorBrowsable(EditorBrowsableState.Never)]
154 public static readonly BindableProperty ItemBackgroundImageUrlProperty = BindableProperty.Create(nameof(ItemBackgroundImageUrl), typeof(string), typeof(ButtonGroup), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
156 ButtonGroup btGroup = (ButtonGroup)bindable;
157 if (btGroup.itemGroup != null && newValue != null)
159 foreach (Button btn in btGroup.itemGroup)
161 if (btn.Style.BackgroundImage == null)
163 btn.Style.BackgroundImage = new Selector<string>();
165 btn.Style.BackgroundImage = (string)newValue;
167 btGroup.itemBackgroundImageUrl = (string)newValue;
170 defaultValueCreator: (bindable) =>
172 ButtonGroup btGroup = (ButtonGroup)bindable;
173 return btGroup.itemBackgroundImageUrl;
176 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
177 [EditorBrowsable(EditorBrowsableState.Never)]
178 public static readonly BindableProperty ItemBackgroundBorderProperty = BindableProperty.Create(nameof(ItemBackgroundBorder), typeof(Rectangle), typeof(ButtonGroup), new Rectangle(), propertyChanged: (bindable, oldValue, newValue) =>
180 ButtonGroup btGroup = (ButtonGroup)bindable;
181 if (btGroup.itemGroup != null && newValue != null)
183 foreach (Button btn in btGroup.itemGroup)
185 btn.BackgroundImageBorder = (Rectangle)newValue;
187 btGroup.itemBackgroundBorder = (Rectangle)newValue;
190 defaultValueCreator: (bindable) =>
192 ButtonGroup btGroup = (ButtonGroup)bindable;
193 return btGroup.itemBackgroundBorder;
196 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
197 [EditorBrowsable(EditorBrowsableState.Never)]
198 public static readonly BindableProperty ItemShadowUrlProperty = BindableProperty.Create(nameof(ItemShadowUrl), typeof(string), typeof(ButtonGroup), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
200 ButtonGroup btGroup = (ButtonGroup)bindable;
201 if (btGroup.itemGroup != null && newValue != null)
203 foreach (Button btn in btGroup.itemGroup)
205 if (btn.Style.Shadow.ResourceUrl == null)
207 btn.Style.Shadow.ResourceUrl = new Selector<string>();
209 btn.Style.Shadow.ResourceUrl = (string)newValue;
211 btGroup.itemShadowUrl = (string)newValue;
214 defaultValueCreator: (bindable) =>
216 ButtonGroup btGroup = (ButtonGroup)bindable;
217 return btGroup.itemShadowUrl;
220 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
221 [EditorBrowsable(EditorBrowsableState.Never)]
222 public static readonly BindableProperty ItemShadowBorderProperty = BindableProperty.Create(nameof(ItemShadowBorder), typeof(Rectangle), typeof(ButtonGroup), new Rectangle(), propertyChanged: (bindable, oldValue, newValue) =>
224 ButtonGroup btGroup = (ButtonGroup)bindable;
225 if (btGroup.itemGroup != null && newValue != null)
227 foreach (Button btn in btGroup.itemGroup)
229 btn.Style.Shadow.Border = (Rectangle)newValue;
231 btGroup.itemShadowBorder = (Rectangle)newValue;
234 defaultValueCreator: (bindable) =>
236 ButtonGroup btGroup = (ButtonGroup)bindable;
237 return btGroup.itemShadowBorder;
241 /// Construct an button group.
243 /// <param name="view">root view</param>
244 [EditorBrowsable(EditorBrowsableState.Never)]
245 public ButtonGroup(View view) : base()
247 itemGroup = new List<Button>();
248 if ((root = view) == null)
250 throw new Exception("Root view is null.");
255 /// Get group item number.
257 [EditorBrowsable(EditorBrowsableState.Never)]
262 return itemGroup.Count;
267 /// Check if the button exists.
269 /// <param name="bt">button item</param>
270 /// <returns></returns>
271 [EditorBrowsable(EditorBrowsableState.Never)]
272 public bool Contains(Button bt)
274 return itemGroup.Contains(bt);
278 /// Get button item index.
280 /// <param name="bt">button item</param>
281 /// <returns></returns>
282 [EditorBrowsable(EditorBrowsableState.Never)]
283 public int GetIndex(Button bt)
285 return itemGroup.IndexOf(bt);
289 /// Get item by index.
291 /// <param name="index">item index.</param>
292 /// <returns></returns>
293 [EditorBrowsable(EditorBrowsableState.Never)]
294 public Button GetItem(int index)
296 if (index >= Count || index < 0)
298 throw new Exception("button index error");
300 return itemGroup[index];
304 /// Add item into group.
306 /// <param name="bt">button item.</param>
307 [EditorBrowsable(EditorBrowsableState.Never)]
308 public void AddItem(Button bt)
310 if (itemGroup.Contains(bt))
319 /// The item to removed.
321 /// <param name="bt">button item.</param>
322 [EditorBrowsable(EditorBrowsableState.Never)]
323 public void RemoveItem(Button bt)
325 if (null == bt) return;
326 if (!itemGroup.Contains(bt))
330 itemGroup.Remove(bt);
336 /// Remove item by index.
338 /// <param name="index">item index.</param>
339 [EditorBrowsable(EditorBrowsableState.Never)]
340 public void RemoveItem(int index)
342 if (index >= Count || index < 0)
344 throw new Exception("button index error");
346 Button bt = itemGroup[index];
347 itemGroup.Remove(bt);
353 /// Remove all items.
355 [EditorBrowsable(EditorBrowsableState.Never)]
356 public void RemoveAll()
358 foreach (Button bt in itemGroup)
367 /// Update button by style.
369 /// <param name="btStyle">button style.</param>
370 [EditorBrowsable(EditorBrowsableState.Never)]
371 public void UpdateButton(ButtonStyle btStyle)
373 if (Count == 0) return;
375 int buttonWidth = (int)root.Size.Width / Count;
376 int buttonHeight = (int)itemheight;
377 foreach (Button btnTemp in itemGroup)
379 btnTemp.Size = new Size(buttonWidth, buttonHeight);
383 if (root.LayoutDirection == ViewLayoutDirectionType.RTL)
385 for (int i = Count - 1; i >= 0; i--)
387 itemGroup[i].Style.PositionX = pos;
388 pos += (int)(itemGroup[i].Size.Width);
393 for (int i = 0; i < Count; i++)
395 itemGroup[i].Style.PositionX = pos;
396 pos += (int)(itemGroup[i].Size.Width);
400 if (btStyle == null || btStyle.Text == null || btStyle.Text.TextColor == null) return;
401 ItemTextColor = btStyle.Text.TextColor.All;
405 /// Common height for all of the Items
407 /// <since_tizen> 3 </since_tizen>
408 [EditorBrowsable(EditorBrowsableState.Never)]
409 public float Itemheight
413 return (float)GetValue(ItemheightProperty);
417 SetValue(ItemheightProperty, value);
422 /// Get or set point size of item.
424 [EditorBrowsable(EditorBrowsableState.Never)]
425 public float ItemPointSize
429 return (float)GetValue(ItemPointSizeProperty);
433 SetValue(ItemPointSizeProperty, value);
438 /// Get or set font family of item.
440 [EditorBrowsable(EditorBrowsableState.Never)]
441 public string ItemFontFamily
445 return (string)GetValue(ItemFontFamilyProperty);
449 SetValue(ItemFontFamilyProperty, value);
454 /// Get or set text color of item.
456 [EditorBrowsable(EditorBrowsableState.Never)]
457 public Color ItemTextColor
461 return (Color)GetValue(ItemTextColorProperty);
465 SetValue(ItemTextColorProperty, value);
470 /// Get or set text alignment of item.
472 [EditorBrowsable(EditorBrowsableState.Never)]
473 public HorizontalAlignment ItemTextAlignment
477 return (HorizontalAlignment)GetValue(ItemTextAlignmentProperty);
481 SetValue(ItemTextAlignmentProperty, value);
486 /// Get or set background color of item.
488 [EditorBrowsable(EditorBrowsableState.Never)]
489 public Selector<Color> OverLayBackgroundColorSelector
493 return (Selector<Color>)GetValue(OverLayBackgroundColorSelectorProperty);
497 SetValue(OverLayBackgroundColorSelectorProperty, value);
502 /// The mutually exclusive with "backgroundColor" and "background" type Map.
504 /// <since_tizen> 3 </since_tizen>
505 [EditorBrowsable(EditorBrowsableState.Never)]
506 public string ItemBackgroundImageUrl
510 return (string)GetValue(ItemBackgroundImageUrlProperty);
514 SetValue(ItemBackgroundImageUrlProperty, value);
519 /// Get or set background border of item.
521 [EditorBrowsable(EditorBrowsableState.Never)]
522 public Rectangle ItemBackgroundBorder
526 return (Rectangle)GetValue(ItemBackgroundBorderProperty);
530 SetValue(ItemBackgroundBorderProperty, value);
535 /// Get or set shadow resource of item.
537 [EditorBrowsable(EditorBrowsableState.Never)]
538 public string ItemShadowUrl
542 return (string)GetValue(ItemShadowUrlProperty);
546 SetValue(ItemShadowUrlProperty, value);
551 /// Get or set shadow border of item.
553 [EditorBrowsable(EditorBrowsableState.Never)]
554 public Rectangle ItemShadowBorder
558 return (Rectangle)GetValue(ItemShadowBorderProperty);
562 SetValue(ItemShadowBorderProperty, value);
569 [EditorBrowsable(EditorBrowsableState.Never)]
570 public void Dispose()
572 if (disposed) return;
573 if (itemGroup != null)
581 private List<Button> itemGroup;
582 private View root = null;
583 private bool disposed = false;
584 private float itemheight;
585 private float itemPointSize;
586 private string itemFontFamily;
587 private Color itemTextColor = new Color();
588 private HorizontalAlignment itemTextAlignment;
589 private Selector<Color> overLayBackgroundColorSelector = new Selector<Color>();
590 private string itemBackgroundImageUrl;
591 private Rectangle itemBackgroundBorder = new Rectangle();
592 private string itemShadowUrl;
593 private Rectangle itemShadowBorder = new Rectangle();