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 works as a clickable input element to trigger events.
24 public class Button : Layout
26 private SmartEvent _clicked;
27 private SmartEvent _repeated;
28 private SmartEvent _pressed;
29 private SmartEvent _released;
32 /// Creates and initializes a new instance of the Button class.
34 /// <param name="parent">
35 /// The EvasObject to which the new Button will be attached as a child.
37 public Button(EvasObject parent) : base(parent)
39 _clicked = new SmartEvent(this, this.RealHandle, "clicked");
40 _repeated = new SmartEvent(this, this.RealHandle, "repeated");
41 _pressed = new SmartEvent(this, this.RealHandle, "pressed");
42 _released = new SmartEvent(this, this.RealHandle, "unpressed");
44 _clicked.On += (sender, e) =>
46 Clicked?.Invoke(this, EventArgs.Empty);
49 _repeated.On += (sender, e) =>
51 Repeated?.Invoke(this, EventArgs.Empty);
54 _pressed.On += (sender, e) =>
56 Pressed?.Invoke(this, EventArgs.Empty);
59 _released.On += (sender, e) =>
61 Released?.Invoke(this, EventArgs.Empty);
66 /// Clicked will be triggered when Button is clicked.
68 public event EventHandler Clicked;
71 /// Repeated will be triggered when Button is pressed without releasing it.
73 public event EventHandler Repeated;
76 /// Pressed will be triggered when the Button is pressed.
78 public event EventHandler Pressed;
81 /// Released will be triggered when the Button is released after being pressed.
83 public event EventHandler Released;
86 /// Sets or gets the autorepeat feature of a given Button.
89 /// Autorepeat feature means autorepeat event generated when the button is kept pressed.
90 /// When set AutoRepeat to false, no autorepeat is performed and buttons will trigger Clicked event when they are clicked.
91 /// When set to true, keeping a button pressed continuously trigger Repeated event until the button is released.
92 /// The time it takes until it starts triggering Repeated is given by AutoRepeatInitialTime,
93 /// and the time between each new emission is given by AutoRepeatGapTimeout.
95 public bool AutoRepeat
99 return Interop.Elementary.elm_button_autorepeat_get(RealHandle);
103 Interop.Elementary.elm_button_autorepeat_set(RealHandle, value);
108 /// Sets or gets the initial timeout before the Repeat event is generated.
110 public double AutoRepeatInitialTime
114 return Interop.Elementary.elm_button_autorepeat_initial_timeout_get(RealHandle);
118 Interop.Elementary.elm_button_autorepeat_initial_timeout_set(RealHandle, value);
123 /// Sets or gets the interval between each generated Repeat event.
125 public double AutoRepeatGapTimeout
129 return Interop.Elementary.elm_button_autorepeat_gap_timeout_get(RealHandle);
133 Interop.Elementary.elm_button_autorepeat_gap_timeout_set(RealHandle, value);
138 /// Delete the object color class.
140 /// <param name="part">The color class to be deleted.</param>
141 [Obsolete("DeleteColorClass is obsolete, please use EdjeObject.DeleteColorClass(string)")]
142 public void DeleteColorClass(string part)
144 Interop.Elementary.edje_object_color_class_del(Handle, part);
148 /// Sets or gets the BackgroundColor of a given Button in normal and pressed status.
150 public override Color BackgroundColor
156 EdjeObject.DeleteColorClass("button/bg");
157 EdjeObject.DeleteColorClass("button/bg_pressed");
158 EdjeObject.DeleteColorClass("button/bg_disabled");
162 SetPartColor("bg", value);
163 SetPartColor("bg_pressed", value);
164 SetPartColor("bg_disabled", value);
166 _backgroundColor = value;
171 /// Creates a widget handle.
173 /// <param name="parent">Parent EvasObject</param>
174 /// <returns>Handle IntPtr</returns>
175 protected override IntPtr CreateHandle(EvasObject parent)
177 return Interop.Elementary.elm_button_add(parent.Handle);