1 /**
2 Custom control to edit properties for adding into the inspector.
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.editorproperty;
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.container;
24 import godot.control;
25 import godot.canvasitem;
26 import godot.node;
27 import godot.inputevent;
28 /**
29 Custom control to edit properties for adding into the inspector.
30 
31 This control allows property editing for one or multiple properties into $(D EditorInspector). It is added via $(D EditorInspectorPlugin).
32 */
33 @GodotBaseClass struct EditorProperty
34 {
35 	package(godot) enum string _GODOT_internal_name = "EditorProperty";
36 public:
37 @nogc nothrow:
38 	union { /** */ godot_object _godot_object; /** */ Container _GODOT_base; }
39 	alias _GODOT_base this;
40 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
41 	package(godot) __gshared bool _classBindingInitialized = false;
42 	package(godot) static struct GDNativeClassBinding
43 	{
44 		__gshared:
45 		@GodotName("_focusable_focused") GodotMethod!(void, long) _focusableFocused;
46 		@GodotName("_gui_input") GodotMethod!(void, InputEvent) _guiInput;
47 		@GodotName("add_focusable") GodotMethod!(void, Control) addFocusable;
48 		@GodotName("emit_changed") GodotMethod!(void, String, Variant, String, bool) emitChanged;
49 		@GodotName("get_edited_object") GodotMethod!(GodotObject) getEditedObject;
50 		@GodotName("get_edited_property") GodotMethod!(String) getEditedProperty;
51 		@GodotName("get_label") GodotMethod!(String) getLabel;
52 		@GodotName("get_tooltip_text") GodotMethod!(String) getTooltipText;
53 		@GodotName("is_checkable") GodotMethod!(bool) isCheckable;
54 		@GodotName("is_checked") GodotMethod!(bool) isChecked;
55 		@GodotName("is_draw_red") GodotMethod!(bool) isDrawRed;
56 		@GodotName("is_keying") GodotMethod!(bool) isKeying;
57 		@GodotName("is_read_only") GodotMethod!(bool) isReadOnly;
58 		@GodotName("set_bottom_editor") GodotMethod!(void, Control) setBottomEditor;
59 		@GodotName("set_checkable") GodotMethod!(void, bool) setCheckable;
60 		@GodotName("set_checked") GodotMethod!(void, bool) setChecked;
61 		@GodotName("set_draw_red") GodotMethod!(void, bool) setDrawRed;
62 		@GodotName("set_keying") GodotMethod!(void, bool) setKeying;
63 		@GodotName("set_label") GodotMethod!(void, String) setLabel;
64 		@GodotName("set_read_only") GodotMethod!(void, bool) setReadOnly;
65 		@GodotName("update_property") GodotMethod!(void) updateProperty;
66 	}
67 	/// 
68 	pragma(inline, true) bool opEquals(in EditorProperty other) const
69 	{ return _godot_object.ptr is other._godot_object.ptr; }
70 	/// 
71 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
72 	{ _godot_object.ptr = n; return null; }
73 	/// 
74 	pragma(inline, true) bool opEquals(typeof(null) n) const
75 	{ return _godot_object.ptr is n; }
76 	/// 
77 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
78 	mixin baseCasts;
79 	/// Construct a new instance of EditorProperty.
80 	/// Note: use `memnew!EditorProperty` instead.
81 	static EditorProperty _new()
82 	{
83 		static godot_class_constructor constructor;
84 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("EditorProperty");
85 		if(constructor is null) return typeof(this).init;
86 		return cast(EditorProperty)(constructor());
87 	}
88 	@disable new(size_t s);
89 	/**
90 	
91 	*/
92 	void _focusableFocused(in long arg0)
93 	{
94 		Array _GODOT_args = Array.make();
95 		_GODOT_args.append(arg0);
96 		String _GODOT_method_name = String("_focusable_focused");
97 		this.callv(_GODOT_method_name, _GODOT_args);
98 	}
99 	/**
100 	
101 	*/
102 	void _guiInput(InputEvent arg0)
103 	{
104 		Array _GODOT_args = Array.make();
105 		_GODOT_args.append(arg0);
106 		String _GODOT_method_name = String("_gui_input");
107 		this.callv(_GODOT_method_name, _GODOT_args);
108 	}
109 	/**
110 	If any of the controls added can gain keyboard focus, add it here. This ensures that focus will be restored if the inspector is refreshed.
111 	*/
112 	void addFocusable(Control control)
113 	{
114 		checkClassBinding!(typeof(this))();
115 		ptrcall!(void)(GDNativeClassBinding.addFocusable, _godot_object, control);
116 	}
117 	/**
118 	If one or several properties have changed, this must be called. `field` is used in case your editor can modify fields separately (as an example, Vector3.x). The `changing` argument avoids the editor requesting this property to be refreshed (leave as `false` if unsure).
119 	*/
120 	void emitChanged(VariantArg1)(in String property, in VariantArg1 value, in String field = gs!"", in bool changing = false)
121 	{
122 		checkClassBinding!(typeof(this))();
123 		ptrcall!(void)(GDNativeClassBinding.emitChanged, _godot_object, property, value, field, changing);
124 	}
125 	/**
126 	Gets the edited object.
127 	*/
128 	GodotObject getEditedObject()
129 	{
130 		checkClassBinding!(typeof(this))();
131 		return ptrcall!(GodotObject)(GDNativeClassBinding.getEditedObject, _godot_object);
132 	}
133 	/**
134 	Gets the edited property. If your editor is for a single property (added via $(D EditorInspectorPlugin.parseProperty)), then this will return the property.
135 	*/
136 	String getEditedProperty()
137 	{
138 		checkClassBinding!(typeof(this))();
139 		return ptrcall!(String)(GDNativeClassBinding.getEditedProperty, _godot_object);
140 	}
141 	/**
142 	
143 	*/
144 	String getLabel() const
145 	{
146 		checkClassBinding!(typeof(this))();
147 		return ptrcall!(String)(GDNativeClassBinding.getLabel, _godot_object);
148 	}
149 	/**
150 	Must be implemented to provide a custom tooltip to the property editor.
151 	*/
152 	String getTooltipText() const
153 	{
154 		checkClassBinding!(typeof(this))();
155 		return ptrcall!(String)(GDNativeClassBinding.getTooltipText, _godot_object);
156 	}
157 	/**
158 	
159 	*/
160 	bool isCheckable() const
161 	{
162 		checkClassBinding!(typeof(this))();
163 		return ptrcall!(bool)(GDNativeClassBinding.isCheckable, _godot_object);
164 	}
165 	/**
166 	
167 	*/
168 	bool isChecked() const
169 	{
170 		checkClassBinding!(typeof(this))();
171 		return ptrcall!(bool)(GDNativeClassBinding.isChecked, _godot_object);
172 	}
173 	/**
174 	
175 	*/
176 	bool isDrawRed() const
177 	{
178 		checkClassBinding!(typeof(this))();
179 		return ptrcall!(bool)(GDNativeClassBinding.isDrawRed, _godot_object);
180 	}
181 	/**
182 	
183 	*/
184 	bool isKeying() const
185 	{
186 		checkClassBinding!(typeof(this))();
187 		return ptrcall!(bool)(GDNativeClassBinding.isKeying, _godot_object);
188 	}
189 	/**
190 	
191 	*/
192 	bool isReadOnly() const
193 	{
194 		checkClassBinding!(typeof(this))();
195 		return ptrcall!(bool)(GDNativeClassBinding.isReadOnly, _godot_object);
196 	}
197 	/**
198 	Puts the `editor` control below the property label. The control must be previously added using $(D Node.addChild).
199 	*/
200 	void setBottomEditor(Control editor)
201 	{
202 		checkClassBinding!(typeof(this))();
203 		ptrcall!(void)(GDNativeClassBinding.setBottomEditor, _godot_object, editor);
204 	}
205 	/**
206 	
207 	*/
208 	void setCheckable(in bool checkable)
209 	{
210 		checkClassBinding!(typeof(this))();
211 		ptrcall!(void)(GDNativeClassBinding.setCheckable, _godot_object, checkable);
212 	}
213 	/**
214 	
215 	*/
216 	void setChecked(in bool checked)
217 	{
218 		checkClassBinding!(typeof(this))();
219 		ptrcall!(void)(GDNativeClassBinding.setChecked, _godot_object, checked);
220 	}
221 	/**
222 	
223 	*/
224 	void setDrawRed(in bool draw_red)
225 	{
226 		checkClassBinding!(typeof(this))();
227 		ptrcall!(void)(GDNativeClassBinding.setDrawRed, _godot_object, draw_red);
228 	}
229 	/**
230 	
231 	*/
232 	void setKeying(in bool keying)
233 	{
234 		checkClassBinding!(typeof(this))();
235 		ptrcall!(void)(GDNativeClassBinding.setKeying, _godot_object, keying);
236 	}
237 	/**
238 	
239 	*/
240 	void setLabel(in String text)
241 	{
242 		checkClassBinding!(typeof(this))();
243 		ptrcall!(void)(GDNativeClassBinding.setLabel, _godot_object, text);
244 	}
245 	/**
246 	
247 	*/
248 	void setReadOnly(in bool read_only)
249 	{
250 		checkClassBinding!(typeof(this))();
251 		ptrcall!(void)(GDNativeClassBinding.setReadOnly, _godot_object, read_only);
252 	}
253 	/**
254 	When this virtual function is called, you must update your editor.
255 	*/
256 	void updateProperty()
257 	{
258 		Array _GODOT_args = Array.make();
259 		String _GODOT_method_name = String("update_property");
260 		this.callv(_GODOT_method_name, _GODOT_args);
261 	}
262 	/**
263 	Used by the inspector, set to `true` when the property is checkable.
264 	*/
265 	@property bool checkable()
266 	{
267 		return isCheckable();
268 	}
269 	/// ditto
270 	@property void checkable(bool v)
271 	{
272 		setCheckable(v);
273 	}
274 	/**
275 	Used by the inspector, set to `true` when the property is checked.
276 	*/
277 	@property bool checked()
278 	{
279 		return isChecked();
280 	}
281 	/// ditto
282 	@property void checked(bool v)
283 	{
284 		setChecked(v);
285 	}
286 	/**
287 	Used by the inspector, set to `true` when the property must draw with error color. This is used for editable children's properties.
288 	*/
289 	@property bool drawRed()
290 	{
291 		return isDrawRed();
292 	}
293 	/// ditto
294 	@property void drawRed(bool v)
295 	{
296 		setDrawRed(v);
297 	}
298 	/**
299 	Used by the inspector, set to `true` when the property can add keys for animation.
300 	*/
301 	@property bool keying()
302 	{
303 		return isKeying();
304 	}
305 	/// ditto
306 	@property void keying(bool v)
307 	{
308 		setKeying(v);
309 	}
310 	/**
311 	Set this property to change the label (if you want to show one).
312 	*/
313 	@property String label()
314 	{
315 		return getLabel();
316 	}
317 	/// ditto
318 	@property void label(String v)
319 	{
320 		setLabel(v);
321 	}
322 	/**
323 	Used by the inspector, set to `true` when the property is read-only.
324 	*/
325 	@property bool readOnly()
326 	{
327 		return isReadOnly();
328 	}
329 	/// ditto
330 	@property void readOnly(bool v)
331 	{
332 		setReadOnly(v);
333 	}
334 }