1 /**
2 Standard themed Button.
3 
4 Copyright:
5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.  
6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)  
7 Copyright (c) 2017-2018 Godot-D contributors  
8 
9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License)
10 
11 
12 */
13 module godot.button;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.traits;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.globalenums;
22 import godot.object;
23 import godot.classdb;
24 import godot.basebutton;
25 import godot.control;
26 import godot.texture;
27 /**
28 Standard themed Button.
29 
30 Button is the standard themed button. It can contain text and an icon, and will display them according to the current $(D Theme).
31 $(B Example of creating a button and assigning an action when pressed by code:)
32 
33 
34 func _ready():
35     var button = Button.new()
36     button.text = "Click me"
37     button.connect("pressed", self, "_button_pressed")
38     add_child(button)
39 
40 func _button_pressed():
41     print("Hello world!")
42 
43 
44 Buttons (like all Control nodes) can also be created in the editor, but some situations may require creating them from code.
45 See also $(D BaseButton) which contains common properties and methods associated with this node.
46 $(B Note:) Buttons do not interpret touch input and therefore don't support multitouch, since mouse emulation can only press one button at a given time. Use $(D TouchScreenButton) for buttons that trigger gameplay movement or actions, as $(D TouchScreenButton) supports multitouch.
47 */
48 @GodotBaseClass struct Button
49 {
50 	package(godot) enum string _GODOT_internal_name = "Button";
51 public:
52 @nogc nothrow:
53 	union { /** */ godot_object _godot_object; /** */ BaseButton _GODOT_base; }
54 	alias _GODOT_base this;
55 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
56 	package(godot) __gshared bool _classBindingInitialized = false;
57 	package(godot) static struct GDNativeClassBinding
58 	{
59 		__gshared:
60 		@GodotName("get_button_icon") GodotMethod!(Texture) getButtonIcon;
61 		@GodotName("get_clip_text") GodotMethod!(bool) getClipText;
62 		@GodotName("get_text") GodotMethod!(String) getText;
63 		@GodotName("get_text_align") GodotMethod!(Button.TextAlign) getTextAlign;
64 		@GodotName("is_expand_icon") GodotMethod!(bool) isExpandIcon;
65 		@GodotName("is_flat") GodotMethod!(bool) isFlat;
66 		@GodotName("set_button_icon") GodotMethod!(void, Texture) setButtonIcon;
67 		@GodotName("set_clip_text") GodotMethod!(void, bool) setClipText;
68 		@GodotName("set_expand_icon") GodotMethod!(void, bool) setExpandIcon;
69 		@GodotName("set_flat") GodotMethod!(void, bool) setFlat;
70 		@GodotName("set_text") GodotMethod!(void, String) setText;
71 		@GodotName("set_text_align") GodotMethod!(void, long) setTextAlign;
72 	}
73 	/// 
74 	pragma(inline, true) bool opEquals(in Button other) const
75 	{ return _godot_object.ptr is other._godot_object.ptr; }
76 	/// 
77 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
78 	{ _godot_object.ptr = n; return null; }
79 	/// 
80 	pragma(inline, true) bool opEquals(typeof(null) n) const
81 	{ return _godot_object.ptr is n; }
82 	/// 
83 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
84 	mixin baseCasts;
85 	/// Construct a new instance of Button.
86 	/// Note: use `memnew!Button` instead.
87 	static Button _new()
88 	{
89 		static godot_class_constructor constructor;
90 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Button");
91 		if(constructor is null) return typeof(this).init;
92 		return cast(Button)(constructor());
93 	}
94 	@disable new(size_t s);
95 	/// 
96 	enum TextAlign : int
97 	{
98 		/**
99 		Align the text to the left.
100 		*/
101 		alignLeft = 0,
102 		/**
103 		Align the text to the center.
104 		*/
105 		alignCenter = 1,
106 		/**
107 		Align the text to the right.
108 		*/
109 		alignRight = 2,
110 	}
111 	/// 
112 	enum Constants : int
113 	{
114 		alignLeft = 0,
115 		alignCenter = 1,
116 		alignRight = 2,
117 	}
118 	/**
119 	
120 	*/
121 	Ref!Texture getButtonIcon() const
122 	{
123 		checkClassBinding!(typeof(this))();
124 		return ptrcall!(Texture)(GDNativeClassBinding.getButtonIcon, _godot_object);
125 	}
126 	/**
127 	
128 	*/
129 	bool getClipText() const
130 	{
131 		checkClassBinding!(typeof(this))();
132 		return ptrcall!(bool)(GDNativeClassBinding.getClipText, _godot_object);
133 	}
134 	/**
135 	
136 	*/
137 	String getText() const
138 	{
139 		checkClassBinding!(typeof(this))();
140 		return ptrcall!(String)(GDNativeClassBinding.getText, _godot_object);
141 	}
142 	/**
143 	
144 	*/
145 	Button.TextAlign getTextAlign() const
146 	{
147 		checkClassBinding!(typeof(this))();
148 		return ptrcall!(Button.TextAlign)(GDNativeClassBinding.getTextAlign, _godot_object);
149 	}
150 	/**
151 	
152 	*/
153 	bool isExpandIcon() const
154 	{
155 		checkClassBinding!(typeof(this))();
156 		return ptrcall!(bool)(GDNativeClassBinding.isExpandIcon, _godot_object);
157 	}
158 	/**
159 	
160 	*/
161 	bool isFlat() const
162 	{
163 		checkClassBinding!(typeof(this))();
164 		return ptrcall!(bool)(GDNativeClassBinding.isFlat, _godot_object);
165 	}
166 	/**
167 	
168 	*/
169 	void setButtonIcon(Texture texture)
170 	{
171 		checkClassBinding!(typeof(this))();
172 		ptrcall!(void)(GDNativeClassBinding.setButtonIcon, _godot_object, texture);
173 	}
174 	/**
175 	
176 	*/
177 	void setClipText(in bool enabled)
178 	{
179 		checkClassBinding!(typeof(this))();
180 		ptrcall!(void)(GDNativeClassBinding.setClipText, _godot_object, enabled);
181 	}
182 	/**
183 	
184 	*/
185 	void setExpandIcon(in bool arg0)
186 	{
187 		checkClassBinding!(typeof(this))();
188 		ptrcall!(void)(GDNativeClassBinding.setExpandIcon, _godot_object, arg0);
189 	}
190 	/**
191 	
192 	*/
193 	void setFlat(in bool enabled)
194 	{
195 		checkClassBinding!(typeof(this))();
196 		ptrcall!(void)(GDNativeClassBinding.setFlat, _godot_object, enabled);
197 	}
198 	/**
199 	
200 	*/
201 	void setText(in String text)
202 	{
203 		checkClassBinding!(typeof(this))();
204 		ptrcall!(void)(GDNativeClassBinding.setText, _godot_object, text);
205 	}
206 	/**
207 	
208 	*/
209 	void setTextAlign(in long _align)
210 	{
211 		checkClassBinding!(typeof(this))();
212 		ptrcall!(void)(GDNativeClassBinding.setTextAlign, _godot_object, _align);
213 	}
214 	/**
215 	Text alignment policy for the button's text, use one of the $(D textalign) constants.
216 	*/
217 	@property Button.TextAlign _align()
218 	{
219 		return getTextAlign();
220 	}
221 	/// ditto
222 	@property void _align(long v)
223 	{
224 		setTextAlign(v);
225 	}
226 	/**
227 	When this property is enabled, text that is too large to fit the button is clipped, when disabled the Button will always be wide enough to hold the text.
228 	*/
229 	@property bool clipText()
230 	{
231 		return getClipText();
232 	}
233 	/// ditto
234 	@property void clipText(bool v)
235 	{
236 		setClipText(v);
237 	}
238 	/**
239 	When enabled, the button's icon will expand/shrink to fit the button's size while keeping its aspect.
240 	*/
241 	@property bool expandIcon()
242 	{
243 		return isExpandIcon();
244 	}
245 	/// ditto
246 	@property void expandIcon(bool v)
247 	{
248 		setExpandIcon(v);
249 	}
250 	/**
251 	Flat buttons don't display decoration.
252 	*/
253 	@property bool flat()
254 	{
255 		return isFlat();
256 	}
257 	/// ditto
258 	@property void flat(bool v)
259 	{
260 		setFlat(v);
261 	}
262 	/**
263 	Button's icon, if text is present the icon will be placed before the text.
264 	*/
265 	@property Texture icon()
266 	{
267 		return getButtonIcon();
268 	}
269 	/// ditto
270 	@property void icon(Texture v)
271 	{
272 		setButtonIcon(v);
273 	}
274 	/**
275 	The button's text that will be displayed inside the button's area.
276 	*/
277 	@property String text()
278 	{
279 		return getText();
280 	}
281 	/// ditto
282 	@property void text(String v)
283 	{
284 		setText(v);
285 	}
286 }