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;
240 [EditorBrowsable(EditorBrowsableState.Never)]
241 public ButtonGroup(View view) : base()
243 itemGroup = new List<Button>();
244 if ((root = view) == null)
246 throw new Exception("Root view is null.");
250 [EditorBrowsable(EditorBrowsableState.Never)]
255 return itemGroup.Count;
259 [EditorBrowsable(EditorBrowsableState.Never)]
260 public bool Contains(Button bt)
262 return itemGroup.Contains(bt);
265 [EditorBrowsable(EditorBrowsableState.Never)]
266 public int GetIndex(Button bt)
268 return itemGroup.IndexOf(bt);
271 [EditorBrowsable(EditorBrowsableState.Never)]
272 public Button GetItem(int index)
274 if (index >= Count || index < 0)
276 throw new Exception("button index error");
278 return itemGroup[index];
281 [EditorBrowsable(EditorBrowsableState.Never)]
282 public void AddItem(Button bt)
284 if (itemGroup.Contains(bt))
292 [EditorBrowsable(EditorBrowsableState.Never)]
293 public void RemoveItem(Button bt)
295 if (!itemGroup.Contains(bt))
299 itemGroup.Remove(bt);
304 [EditorBrowsable(EditorBrowsableState.Never)]
305 public void RemoveItem(int index)
307 if (index >= Count || index < 0)
309 throw new Exception("button index error");
311 Button bt = itemGroup[index];
312 itemGroup.Remove(bt);
317 [EditorBrowsable(EditorBrowsableState.Never)]
318 public void RemoveAll()
320 foreach (Button bt in itemGroup)
328 [EditorBrowsable(EditorBrowsableState.Never)]
329 public void UpdateButton(ButtonStyle btStyle)
331 if (Count == 0) return;
333 int buttonWidth = (int)root.Size.Width / Count;
334 int buttonHeight = (int)itemheight;
335 foreach (Button btnTemp in itemGroup)
337 btnTemp.Size = new Size(buttonWidth, buttonHeight);
341 if (root.LayoutDirection == ViewLayoutDirectionType.RTL)
343 for (int i = Count - 1; i >= 0; i--)
345 itemGroup[i].Style.PositionX = pos;
346 pos += (int)(itemGroup[i].Size.Width);
351 for (int i = 0; i < Count; i++)
353 itemGroup[i].Style.PositionX = pos;
354 pos += (int)(itemGroup[i].Size.Width);
358 if (btStyle == null || btStyle.Text == null || btStyle.Text.TextColor == null) return;
359 ItemTextColor = btStyle.Text.TextColor.All;
363 /// Common height for all of the Items
365 /// <since_tizen> 3 </since_tizen>
366 [EditorBrowsable(EditorBrowsableState.Never)]
367 public float Itemheight
371 return (float)GetValue(ItemheightProperty);
375 SetValue(ItemheightProperty, value);
379 [EditorBrowsable(EditorBrowsableState.Never)]
380 public float ItemPointSize
384 return (float)GetValue(ItemPointSizeProperty);
388 SetValue(ItemPointSizeProperty, value);
392 [EditorBrowsable(EditorBrowsableState.Never)]
393 public string ItemFontFamily
397 return (string)GetValue(ItemFontFamilyProperty);
401 SetValue(ItemFontFamilyProperty, value);
405 [EditorBrowsable(EditorBrowsableState.Never)]
406 public Color ItemTextColor
410 return (Color)GetValue(ItemTextColorProperty);
414 SetValue(ItemTextColorProperty, value);
418 [EditorBrowsable(EditorBrowsableState.Never)]
419 public HorizontalAlignment ItemTextAlignment
423 return (HorizontalAlignment)GetValue(ItemTextAlignmentProperty);
427 SetValue(ItemTextAlignmentProperty, value);
431 [EditorBrowsable(EditorBrowsableState.Never)]
432 public Selector<Color> OverLayBackgroundColorSelector
436 return (Selector<Color>)GetValue(OverLayBackgroundColorSelectorProperty);
440 SetValue(OverLayBackgroundColorSelectorProperty, value);
445 /// The mutually exclusive with "backgroundColor" and "background" type Map.
447 /// <since_tizen> 3 </since_tizen>
448 [EditorBrowsable(EditorBrowsableState.Never)]
449 public string ItemBackgroundImageUrl
453 return (string)GetValue(ItemBackgroundImageUrlProperty);
457 SetValue(ItemBackgroundImageUrlProperty, value);
461 [EditorBrowsable(EditorBrowsableState.Never)]
462 public Rectangle ItemBackgroundBorder
466 return (Rectangle)GetValue(ItemBackgroundBorderProperty);
470 SetValue(ItemBackgroundBorderProperty, value);
474 [EditorBrowsable(EditorBrowsableState.Never)]
475 public string ItemShadowUrl
479 return (string)GetValue(ItemShadowUrlProperty);
483 SetValue(ItemShadowUrlProperty, value);
487 [EditorBrowsable(EditorBrowsableState.Never)]
488 public Rectangle ItemShadowBorder
492 return (Rectangle)GetValue(ItemShadowBorderProperty);
496 SetValue(ItemShadowBorderProperty, value);
500 [EditorBrowsable(EditorBrowsableState.Never)]
501 public void Dispose()
503 if (disposed) return;
504 if (itemGroup != null)
512 private List<Button> itemGroup;
513 private View root = null;
514 private bool disposed = false;
515 private float itemheight;
516 private float itemPointSize;
517 private string itemFontFamily;
518 private Color itemTextColor = new Color();
519 private HorizontalAlignment itemTextAlignment;
520 private Selector<Color> overLayBackgroundColorSelector = new Selector<Color>();
521 private string itemBackgroundImageUrl;
522 private Rectangle itemBackgroundBorder = new Rectangle();
523 private string itemShadowUrl;
524 private Rectangle itemShadowBorder = new Rectangle();