1 /**
2 Control that provides single line string editing.
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.lineedit;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.meta;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.object;
22 import godot.classdb;
23 import godot.control;
24 import godot.inputevent;
25 import godot.popupmenu;
26 import godot.canvasitem;
27 import godot.node;
28 /**
29 Control that provides single line string editing.
30 
31 LineEdit provides a single line string editor, used for text fields.
32 */
33 @GodotBaseClass struct LineEdit
34 {
35 	enum string _GODOT_internal_name = "LineEdit";
36 public:
37 @nogc nothrow:
38 	union { godot_object _godot_object; Control _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 _classBinding
43 	{
44 		__gshared:
45 		@GodotName("_text_changed") GodotMethod!(void) _textChanged;
46 		@GodotName("_toggle_draw_caret") GodotMethod!(void) _toggleDrawCaret;
47 		@GodotName("_editor_settings_changed") GodotMethod!(void) _editorSettingsChanged;
48 		@GodotName("set_align") GodotMethod!(void, long) setAlign;
49 		@GodotName("get_align") GodotMethod!(LineEdit.Align) getAlign;
50 		@GodotName("_gui_input") GodotMethod!(void, InputEvent) _guiInput;
51 		@GodotName("clear") GodotMethod!(void) clear;
52 		@GodotName("select") GodotMethod!(void, long, long) select;
53 		@GodotName("select_all") GodotMethod!(void) selectAll;
54 		@GodotName("deselect") GodotMethod!(void) deselect;
55 		@GodotName("set_text") GodotMethod!(void, String) setText;
56 		@GodotName("get_text") GodotMethod!(String) getText;
57 		@GodotName("set_placeholder") GodotMethod!(void, String) setPlaceholder;
58 		@GodotName("get_placeholder") GodotMethod!(String) getPlaceholder;
59 		@GodotName("set_placeholder_alpha") GodotMethod!(void, double) setPlaceholderAlpha;
60 		@GodotName("get_placeholder_alpha") GodotMethod!(double) getPlaceholderAlpha;
61 		@GodotName("set_cursor_position") GodotMethod!(void, long) setCursorPosition;
62 		@GodotName("get_cursor_position") GodotMethod!(long) getCursorPosition;
63 		@GodotName("set_expand_to_text_length") GodotMethod!(void, bool) setExpandToTextLength;
64 		@GodotName("get_expand_to_text_length") GodotMethod!(bool) getExpandToTextLength;
65 		@GodotName("cursor_set_blink_enabled") GodotMethod!(void, bool) cursorSetBlinkEnabled;
66 		@GodotName("cursor_get_blink_enabled") GodotMethod!(bool) cursorGetBlinkEnabled;
67 		@GodotName("cursor_set_blink_speed") GodotMethod!(void, double) cursorSetBlinkSpeed;
68 		@GodotName("cursor_get_blink_speed") GodotMethod!(double) cursorGetBlinkSpeed;
69 		@GodotName("set_max_length") GodotMethod!(void, long) setMaxLength;
70 		@GodotName("get_max_length") GodotMethod!(long) getMaxLength;
71 		@GodotName("append_at_cursor") GodotMethod!(void, String) appendAtCursor;
72 		@GodotName("set_editable") GodotMethod!(void, bool) setEditable;
73 		@GodotName("is_editable") GodotMethod!(bool) isEditable;
74 		@GodotName("set_secret") GodotMethod!(void, bool) setSecret;
75 		@GodotName("is_secret") GodotMethod!(bool) isSecret;
76 		@GodotName("set_secret_character") GodotMethod!(void, String) setSecretCharacter;
77 		@GodotName("get_secret_character") GodotMethod!(String) getSecretCharacter;
78 		@GodotName("menu_option") GodotMethod!(void, long) menuOption;
79 		@GodotName("get_menu") GodotMethod!(PopupMenu) getMenu;
80 		@GodotName("set_context_menu_enabled") GodotMethod!(void, bool) setContextMenuEnabled;
81 		@GodotName("is_context_menu_enabled") GodotMethod!(bool) isContextMenuEnabled;
82 		@GodotName("set_clear_button_enabled") GodotMethod!(void, bool) setClearButtonEnabled;
83 		@GodotName("is_clear_button_enabled") GodotMethod!(bool) isClearButtonEnabled;
84 	}
85 	bool opEquals(in LineEdit other) const { return _godot_object.ptr is other._godot_object.ptr; }
86 	LineEdit opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; }
87 	bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; }
88 	mixin baseCasts;
89 	static LineEdit _new()
90 	{
91 		static godot_class_constructor constructor;
92 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("LineEdit");
93 		if(constructor is null) return typeof(this).init;
94 		return cast(LineEdit)(constructor());
95 	}
96 	@disable new(size_t s);
97 	/// 
98 	enum Align : int
99 	{
100 		/**
101 		Aligns the text on the left hand side of the $(D LineEdit).
102 		*/
103 		alignLeft = 0,
104 		/**
105 		Centers the text in the middle of the $(D LineEdit).
106 		*/
107 		alignCenter = 1,
108 		/**
109 		Aligns the text on the right hand side of the $(D LineEdit).
110 		*/
111 		alignRight = 2,
112 		/**
113 		Stretches whitespaces to fit the $(D LineEdit)'s width.
114 		*/
115 		alignFill = 3,
116 	}
117 	/// 
118 	enum MenuItems : int
119 	{
120 		/**
121 		Cuts (Copies and clears) the selected text.
122 		*/
123 		menuCut = 0,
124 		/**
125 		Copies the selected text.
126 		*/
127 		menuCopy = 1,
128 		/**
129 		Pastes the clipboard text over the selected text (or at the cursor's position).
130 		*/
131 		menuPaste = 2,
132 		/**
133 		Erases the whole $(D Linedit) text.
134 		*/
135 		menuClear = 3,
136 		/**
137 		Selects the whole $(D Linedit) text.
138 		*/
139 		menuSelectAll = 4,
140 		/**
141 		Undoes the previous action.
142 		*/
143 		menuUndo = 5,
144 		/**
145 		Reverse the last undo action.
146 		*/
147 		menuRedo = 6,
148 		/**
149 		
150 		*/
151 		menuMax = 7,
152 	}
153 	/// 
154 	enum Constants : int
155 	{
156 		alignLeft = 0,
157 		menuCut = 0,
158 		menuCopy = 1,
159 		alignCenter = 1,
160 		alignRight = 2,
161 		menuPaste = 2,
162 		alignFill = 3,
163 		menuClear = 3,
164 		menuSelectAll = 4,
165 		menuUndo = 5,
166 		menuRedo = 6,
167 		menuMax = 7,
168 	}
169 	/**
170 	
171 	*/
172 	void _textChanged()
173 	{
174 		Array _GODOT_args = Array.empty_array;
175 		String _GODOT_method_name = String("_text_changed");
176 		this.callv(_GODOT_method_name, _GODOT_args);
177 	}
178 	/**
179 	
180 	*/
181 	void _toggleDrawCaret()
182 	{
183 		Array _GODOT_args = Array.empty_array;
184 		String _GODOT_method_name = String("_toggle_draw_caret");
185 		this.callv(_GODOT_method_name, _GODOT_args);
186 	}
187 	/**
188 	
189 	*/
190 	void _editorSettingsChanged()
191 	{
192 		Array _GODOT_args = Array.empty_array;
193 		String _GODOT_method_name = String("_editor_settings_changed");
194 		this.callv(_GODOT_method_name, _GODOT_args);
195 	}
196 	/**
197 	
198 	*/
199 	void setAlign(in long _align)
200 	{
201 		checkClassBinding!(typeof(this))();
202 		ptrcall!(void)(_classBinding.setAlign, _godot_object, _align);
203 	}
204 	/**
205 	
206 	*/
207 	LineEdit.Align getAlign() const
208 	{
209 		checkClassBinding!(typeof(this))();
210 		return ptrcall!(LineEdit.Align)(_classBinding.getAlign, _godot_object);
211 	}
212 	/**
213 	
214 	*/
215 	void _guiInput(InputEvent arg0)
216 	{
217 		Array _GODOT_args = Array.empty_array;
218 		_GODOT_args.append(arg0);
219 		String _GODOT_method_name = String("_gui_input");
220 		this.callv(_GODOT_method_name, _GODOT_args);
221 	}
222 	/**
223 	Erases the $(D LineEdit) text.
224 	*/
225 	void clear()
226 	{
227 		checkClassBinding!(typeof(this))();
228 		ptrcall!(void)(_classBinding.clear, _godot_object);
229 	}
230 	/**
231 	Selects characters inside $(D LineEdit) between `from` and `to`. By default `from` is at the beginning and `to` at the end.
232 	
233 	
234 	text = "Welcome"
235 	select()     # Welcome
236 	select(4)    # ome
237 	select(2, 5) # lco
238 	
239 	
240 	*/
241 	void select(in long from = 0, in long to = -1)
242 	{
243 		checkClassBinding!(typeof(this))();
244 		ptrcall!(void)(_classBinding.select, _godot_object, from, to);
245 	}
246 	/**
247 	Selects the whole $(D String).
248 	*/
249 	void selectAll()
250 	{
251 		checkClassBinding!(typeof(this))();
252 		ptrcall!(void)(_classBinding.selectAll, _godot_object);
253 	}
254 	/**
255 	Clears the current selection.
256 	*/
257 	void deselect()
258 	{
259 		checkClassBinding!(typeof(this))();
260 		ptrcall!(void)(_classBinding.deselect, _godot_object);
261 	}
262 	/**
263 	
264 	*/
265 	void setText(StringArg0)(in StringArg0 text)
266 	{
267 		checkClassBinding!(typeof(this))();
268 		ptrcall!(void)(_classBinding.setText, _godot_object, text);
269 	}
270 	/**
271 	
272 	*/
273 	String getText() const
274 	{
275 		checkClassBinding!(typeof(this))();
276 		return ptrcall!(String)(_classBinding.getText, _godot_object);
277 	}
278 	/**
279 	
280 	*/
281 	void setPlaceholder(StringArg0)(in StringArg0 text)
282 	{
283 		checkClassBinding!(typeof(this))();
284 		ptrcall!(void)(_classBinding.setPlaceholder, _godot_object, text);
285 	}
286 	/**
287 	
288 	*/
289 	String getPlaceholder() const
290 	{
291 		checkClassBinding!(typeof(this))();
292 		return ptrcall!(String)(_classBinding.getPlaceholder, _godot_object);
293 	}
294 	/**
295 	
296 	*/
297 	void setPlaceholderAlpha(in double alpha)
298 	{
299 		checkClassBinding!(typeof(this))();
300 		ptrcall!(void)(_classBinding.setPlaceholderAlpha, _godot_object, alpha);
301 	}
302 	/**
303 	
304 	*/
305 	double getPlaceholderAlpha() const
306 	{
307 		checkClassBinding!(typeof(this))();
308 		return ptrcall!(double)(_classBinding.getPlaceholderAlpha, _godot_object);
309 	}
310 	/**
311 	
312 	*/
313 	void setCursorPosition(in long position)
314 	{
315 		checkClassBinding!(typeof(this))();
316 		ptrcall!(void)(_classBinding.setCursorPosition, _godot_object, position);
317 	}
318 	/**
319 	
320 	*/
321 	long getCursorPosition() const
322 	{
323 		checkClassBinding!(typeof(this))();
324 		return ptrcall!(long)(_classBinding.getCursorPosition, _godot_object);
325 	}
326 	/**
327 	
328 	*/
329 	void setExpandToTextLength(in bool enabled)
330 	{
331 		checkClassBinding!(typeof(this))();
332 		ptrcall!(void)(_classBinding.setExpandToTextLength, _godot_object, enabled);
333 	}
334 	/**
335 	
336 	*/
337 	bool getExpandToTextLength() const
338 	{
339 		checkClassBinding!(typeof(this))();
340 		return ptrcall!(bool)(_classBinding.getExpandToTextLength, _godot_object);
341 	}
342 	/**
343 	
344 	*/
345 	void cursorSetBlinkEnabled(in bool enabled)
346 	{
347 		checkClassBinding!(typeof(this))();
348 		ptrcall!(void)(_classBinding.cursorSetBlinkEnabled, _godot_object, enabled);
349 	}
350 	/**
351 	
352 	*/
353 	bool cursorGetBlinkEnabled() const
354 	{
355 		checkClassBinding!(typeof(this))();
356 		return ptrcall!(bool)(_classBinding.cursorGetBlinkEnabled, _godot_object);
357 	}
358 	/**
359 	
360 	*/
361 	void cursorSetBlinkSpeed(in double blink_speed)
362 	{
363 		checkClassBinding!(typeof(this))();
364 		ptrcall!(void)(_classBinding.cursorSetBlinkSpeed, _godot_object, blink_speed);
365 	}
366 	/**
367 	
368 	*/
369 	double cursorGetBlinkSpeed() const
370 	{
371 		checkClassBinding!(typeof(this))();
372 		return ptrcall!(double)(_classBinding.cursorGetBlinkSpeed, _godot_object);
373 	}
374 	/**
375 	
376 	*/
377 	void setMaxLength(in long chars)
378 	{
379 		checkClassBinding!(typeof(this))();
380 		ptrcall!(void)(_classBinding.setMaxLength, _godot_object, chars);
381 	}
382 	/**
383 	
384 	*/
385 	long getMaxLength() const
386 	{
387 		checkClassBinding!(typeof(this))();
388 		return ptrcall!(long)(_classBinding.getMaxLength, _godot_object);
389 	}
390 	/**
391 	Adds `text` after the cursor. If the resulting value is longer than $(D maxLength), nothing happens.
392 	*/
393 	void appendAtCursor(StringArg0)(in StringArg0 text)
394 	{
395 		checkClassBinding!(typeof(this))();
396 		ptrcall!(void)(_classBinding.appendAtCursor, _godot_object, text);
397 	}
398 	/**
399 	
400 	*/
401 	void setEditable(in bool enabled)
402 	{
403 		checkClassBinding!(typeof(this))();
404 		ptrcall!(void)(_classBinding.setEditable, _godot_object, enabled);
405 	}
406 	/**
407 	
408 	*/
409 	bool isEditable() const
410 	{
411 		checkClassBinding!(typeof(this))();
412 		return ptrcall!(bool)(_classBinding.isEditable, _godot_object);
413 	}
414 	/**
415 	
416 	*/
417 	void setSecret(in bool enabled)
418 	{
419 		checkClassBinding!(typeof(this))();
420 		ptrcall!(void)(_classBinding.setSecret, _godot_object, enabled);
421 	}
422 	/**
423 	
424 	*/
425 	bool isSecret() const
426 	{
427 		checkClassBinding!(typeof(this))();
428 		return ptrcall!(bool)(_classBinding.isSecret, _godot_object);
429 	}
430 	/**
431 	
432 	*/
433 	void setSecretCharacter(StringArg0)(in StringArg0 character)
434 	{
435 		checkClassBinding!(typeof(this))();
436 		ptrcall!(void)(_classBinding.setSecretCharacter, _godot_object, character);
437 	}
438 	/**
439 	
440 	*/
441 	String getSecretCharacter() const
442 	{
443 		checkClassBinding!(typeof(this))();
444 		return ptrcall!(String)(_classBinding.getSecretCharacter, _godot_object);
445 	}
446 	/**
447 	Executes a given action as defined in the MENU_* enum.
448 	*/
449 	void menuOption(in long option)
450 	{
451 		checkClassBinding!(typeof(this))();
452 		ptrcall!(void)(_classBinding.menuOption, _godot_object, option);
453 	}
454 	/**
455 	Returns the $(D PopupMenu) of this `LineEdit`. By default, this menu is displayed when right-clicking on the $(D LineEdit).
456 	*/
457 	PopupMenu getMenu() const
458 	{
459 		checkClassBinding!(typeof(this))();
460 		return ptrcall!(PopupMenu)(_classBinding.getMenu, _godot_object);
461 	}
462 	/**
463 	
464 	*/
465 	void setContextMenuEnabled(in bool enable)
466 	{
467 		checkClassBinding!(typeof(this))();
468 		ptrcall!(void)(_classBinding.setContextMenuEnabled, _godot_object, enable);
469 	}
470 	/**
471 	
472 	*/
473 	bool isContextMenuEnabled()
474 	{
475 		checkClassBinding!(typeof(this))();
476 		return ptrcall!(bool)(_classBinding.isContextMenuEnabled, _godot_object);
477 	}
478 	/**
479 	
480 	*/
481 	void setClearButtonEnabled(in bool enable)
482 	{
483 		checkClassBinding!(typeof(this))();
484 		ptrcall!(void)(_classBinding.setClearButtonEnabled, _godot_object, enable);
485 	}
486 	/**
487 	
488 	*/
489 	bool isClearButtonEnabled() const
490 	{
491 		checkClassBinding!(typeof(this))();
492 		return ptrcall!(bool)(_classBinding.isClearButtonEnabled, _godot_object);
493 	}
494 	/**
495 	String value of the $(D LineEdit).
496 	*/
497 	@property String text()
498 	{
499 		return getText();
500 	}
501 	/// ditto
502 	@property void text(String v)
503 	{
504 		setText(v);
505 	}
506 	/**
507 	Text alignment as defined in the ALIGN_* enum.
508 	*/
509 	@property LineEdit.Align _align()
510 	{
511 		return getAlign();
512 	}
513 	/// ditto
514 	@property void _align(long v)
515 	{
516 		setAlign(v);
517 	}
518 	/**
519 	Maximum amount of characters that can be entered inside the $(D LineEdit). If `0`, there is no limit.
520 	*/
521 	@property long maxLength()
522 	{
523 		return getMaxLength();
524 	}
525 	/// ditto
526 	@property void maxLength(long v)
527 	{
528 		setMaxLength(v);
529 	}
530 	/**
531 	If `false` existing text cannot be modified and new text cannot be added.
532 	*/
533 	@property bool editable()
534 	{
535 		return isEditable();
536 	}
537 	/// ditto
538 	@property void editable(bool v)
539 	{
540 		setEditable(v);
541 	}
542 	/**
543 	If `true`, every character is replaced with the secret character (see $(D secretCharacter)).
544 	*/
545 	@property bool secret()
546 	{
547 		return isSecret();
548 	}
549 	/// ditto
550 	@property void secret(bool v)
551 	{
552 		setSecret(v);
553 	}
554 	/**
555 	The character to use to mask secret input (defaults to "*"). Only a single character can be used as the secret character.
556 	*/
557 	@property String secretCharacter()
558 	{
559 		return getSecretCharacter();
560 	}
561 	/// ditto
562 	@property void secretCharacter(String v)
563 	{
564 		setSecretCharacter(v);
565 	}
566 	/**
567 	If `true` the $(D LineEdit) width will increase to stay longer than the $(D text). It will $(B not) compress if the $(D text) is shortened.
568 	*/
569 	@property bool expandToTextLength()
570 	{
571 		return getExpandToTextLength();
572 	}
573 	/// ditto
574 	@property void expandToTextLength(bool v)
575 	{
576 		setExpandToTextLength(v);
577 	}
578 	/**
579 	Defines how the $(D LineEdit) can grab focus (Keyboard and mouse, only keyboard, or none). See `enum FocusMode` in $(D Control) for details.
580 	*/
581 	@property Control.FocusMode focusMode()
582 	{
583 		return getFocusMode();
584 	}
585 	/// ditto
586 	@property void focusMode(long v)
587 	{
588 		setFocusMode(v);
589 	}
590 	/**
591 	If `true` the context menu will appear when right clicked.
592 	*/
593 	@property bool contextMenuEnabled()
594 	{
595 		return isContextMenuEnabled();
596 	}
597 	/// ditto
598 	@property void contextMenuEnabled(bool v)
599 	{
600 		setContextMenuEnabled(v);
601 	}
602 	/**
603 	If `true` the `LineEdit` will show a clear button if `text` is not empty.
604 	*/
605 	@property bool clearButtonEnabled()
606 	{
607 		return isClearButtonEnabled();
608 	}
609 	/// ditto
610 	@property void clearButtonEnabled(bool v)
611 	{
612 		setClearButtonEnabled(v);
613 	}
614 	/**
615 	Text shown when the $(D LineEdit) is empty. It is $(B not) the $(D LineEdit)'s default value (see $(D text)).
616 	*/
617 	@property String placeholderText()
618 	{
619 		return getPlaceholder();
620 	}
621 	/// ditto
622 	@property void placeholderText(String v)
623 	{
624 		setPlaceholder(v);
625 	}
626 	/**
627 	Opacity of the $(D placeholderText). From `0` to `1`.
628 	*/
629 	@property double placeholderAlpha()
630 	{
631 		return getPlaceholderAlpha();
632 	}
633 	/// ditto
634 	@property void placeholderAlpha(double v)
635 	{
636 		setPlaceholderAlpha(v);
637 	}
638 	/**
639 	If `true` the caret (visual cursor) blinks.
640 	*/
641 	@property bool caretBlink()
642 	{
643 		return cursorGetBlinkEnabled();
644 	}
645 	/// ditto
646 	@property void caretBlink(bool v)
647 	{
648 		cursorSetBlinkEnabled(v);
649 	}
650 	/**
651 	Duration (in seconds) of a caret's blinking cycle.
652 	*/
653 	@property double caretBlinkSpeed()
654 	{
655 		return cursorGetBlinkSpeed();
656 	}
657 	/// ditto
658 	@property void caretBlinkSpeed(double v)
659 	{
660 		cursorSetBlinkSpeed(v);
661 	}
662 	/**
663 	The cursor's position inside the `LineEdit`. When set, the text may scroll to accommodate it.
664 	*/
665 	@property long caretPosition()
666 	{
667 		return getCursorPosition();
668 	}
669 	/// ditto
670 	@property void caretPosition(long v)
671 	{
672 		setCursorPosition(v);
673 	}
674 }