2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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.
22 /// The Button is a widget that works as a clickable input element to trigger events.
24 /// <since_tizen> preview </since_tizen>
25 public class Button : Layout
27 private SmartEvent _clicked;
28 private SmartEvent _repeated;
29 private SmartEvent _pressed;
30 private SmartEvent _released;
33 /// Creates and initializes a new instance of the Button class.
35 /// <param name="parent">
36 /// The EvasObject to which the new Button will be attached as a child.
38 /// <since_tizen> preview </since_tizen>
39 public Button(EvasObject parent) : base(parent)
41 _clicked = new SmartEvent(this, this.RealHandle, "clicked");
42 _repeated = new SmartEvent(this, this.RealHandle, "repeated");
43 _pressed = new SmartEvent(this, this.RealHandle, "pressed");
44 _released = new SmartEvent(this, this.RealHandle, "unpressed");
46 _clicked.On += (sender, e) =>
48 Clicked?.Invoke(this, EventArgs.Empty);
51 _repeated.On += (sender, e) =>
53 Repeated?.Invoke(this, EventArgs.Empty);
56 _pressed.On += (sender, e) =>
58 Pressed?.Invoke(this, EventArgs.Empty);
61 _released.On += (sender, e) =>
63 Released?.Invoke(this, EventArgs.Empty);
68 /// Clicked will be triggered when the button is clicked.
70 /// <since_tizen> preview </since_tizen>
71 public event EventHandler Clicked;
74 /// Repeated will be triggered when the button is pressed without releasing it.
76 /// <since_tizen> preview </since_tizen>
77 public event EventHandler Repeated;
80 /// Pressed will be triggered when the button is pressed.
82 /// <since_tizen> preview </since_tizen>
83 public event EventHandler Pressed;
86 /// Released will be triggered when the button is released after being pressed.
88 /// <since_tizen> preview </since_tizen>
89 public event EventHandler Released;
92 /// Sets or gets the autorepeat feature of a given Bbutton.
95 /// Autorepeat feature means the autorepeat event is generated when the button is kept pressed.
96 /// When set to false, no autorepeat is performed and the buttons will trigger the Clicked event when they are clicked.
97 /// When set to true, keeping a button pressed continuously will trigger the Repeated event until the button is released.
98 /// The time it takes until it starts triggering, repeated is given by AutoRepeatInitialTime,
99 /// and the time between each new emission is given by AutoRepeatGapTimeout.
101 /// <since_tizen> preview </since_tizen>
102 public bool AutoRepeat
106 return Interop.Elementary.elm_button_autorepeat_get(RealHandle);
110 Interop.Elementary.elm_button_autorepeat_set(RealHandle, value);
115 /// Sets or gets the initial timeout before the Repeat event is generated.
117 /// <since_tizen> preview </since_tizen>
118 public double AutoRepeatInitialTime
122 return Interop.Elementary.elm_button_autorepeat_initial_timeout_get(RealHandle);
126 Interop.Elementary.elm_button_autorepeat_initial_timeout_set(RealHandle, value);
131 /// Sets or gets the interval between each generated Repeat event.
133 /// <since_tizen> preview </since_tizen>
134 public double AutoRepeatGapTimeout
138 return Interop.Elementary.elm_button_autorepeat_gap_timeout_get(RealHandle);
142 Interop.Elementary.elm_button_autorepeat_gap_timeout_set(RealHandle, value);
147 /// Deletes the object Color class.
149 /// <param name="part">The Color class to be deleted.</param>
150 /// <since_tizen> preview </since_tizen>
151 [Obsolete("DeleteColorClass is obsolete, please use EdjeObject.DeleteColorClass(string)")]
152 public void DeleteColorClass(string part)
154 Interop.Elementary.edje_object_color_class_del(Handle, part);
158 /// Sets or gets the BackgroundColor of a given button in the normal and pressed status.
160 /// <since_tizen> preview </since_tizen>
161 public override Color BackgroundColor
167 EdjeObject.DeleteColorClass("button/bg");
168 EdjeObject.DeleteColorClass("button/bg_pressed");
169 EdjeObject.DeleteColorClass("button/bg_disabled");
173 SetPartColor("bg", value);
174 SetPartColor("bg_pressed", value);
175 SetPartColor("bg_disabled", value);
177 _backgroundColor = value;
182 /// Creates a widget handle.
184 /// <param name="parent">Parent EvasObject.</param>
185 /// <returns>Handle IntPtr.</returns>
186 /// <since_tizen> preview </since_tizen>
187 protected override IntPtr CreateHandle(EvasObject parent)
189 return Interop.Elementary.elm_button_add(parent.Handle);