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.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.basebutton; 24 import godot.texture; 25 import godot.control; 26 import godot.canvasitem; 27 import godot.node; 28 /** 29 Standard themed Button. 30 31 Button is the standard themed button. It can contain text and an icon, and will display them according to the current $(D Theme). 32 */ 33 @GodotBaseClass struct Button 34 { 35 enum string _GODOT_internal_name = "Button"; 36 public: 37 @nogc nothrow: 38 union { godot_object _godot_object; BaseButton _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("set_text") GodotMethod!(void, String) setText; 46 @GodotName("get_text") GodotMethod!(String) getText; 47 @GodotName("set_button_icon") GodotMethod!(void, Texture) setButtonIcon; 48 @GodotName("get_button_icon") GodotMethod!(Texture) getButtonIcon; 49 @GodotName("set_flat") GodotMethod!(void, bool) setFlat; 50 @GodotName("set_clip_text") GodotMethod!(void, bool) setClipText; 51 @GodotName("get_clip_text") GodotMethod!(bool) getClipText; 52 @GodotName("set_text_align") GodotMethod!(void, long) setTextAlign; 53 @GodotName("get_text_align") GodotMethod!(Button.TextAlign) getTextAlign; 54 @GodotName("is_flat") GodotMethod!(bool) isFlat; 55 } 56 bool opEquals(in Button other) const { return _godot_object.ptr is other._godot_object.ptr; } 57 Button opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 58 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 59 mixin baseCasts; 60 static Button _new() 61 { 62 static godot_class_constructor constructor; 63 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Button"); 64 if(constructor is null) return typeof(this).init; 65 return cast(Button)(constructor()); 66 } 67 @disable new(size_t s); 68 /// 69 enum TextAlign : int 70 { 71 /** 72 Align the text to the left. 73 */ 74 alignLeft = 0, 75 /** 76 Align the text to the center. 77 */ 78 alignCenter = 1, 79 /** 80 Align the text to the right. 81 */ 82 alignRight = 2, 83 } 84 /// 85 enum Constants : int 86 { 87 alignLeft = 0, 88 alignCenter = 1, 89 alignRight = 2, 90 } 91 /** 92 93 */ 94 void setText(StringArg0)(in StringArg0 text) 95 { 96 checkClassBinding!(typeof(this))(); 97 ptrcall!(void)(_classBinding.setText, _godot_object, text); 98 } 99 /** 100 101 */ 102 String getText() const 103 { 104 checkClassBinding!(typeof(this))(); 105 return ptrcall!(String)(_classBinding.getText, _godot_object); 106 } 107 /** 108 109 */ 110 void setButtonIcon(Texture texture) 111 { 112 checkClassBinding!(typeof(this))(); 113 ptrcall!(void)(_classBinding.setButtonIcon, _godot_object, texture); 114 } 115 /** 116 117 */ 118 Ref!Texture getButtonIcon() const 119 { 120 checkClassBinding!(typeof(this))(); 121 return ptrcall!(Texture)(_classBinding.getButtonIcon, _godot_object); 122 } 123 /** 124 125 */ 126 void setFlat(in bool enabled) 127 { 128 checkClassBinding!(typeof(this))(); 129 ptrcall!(void)(_classBinding.setFlat, _godot_object, enabled); 130 } 131 /** 132 133 */ 134 void setClipText(in bool enabled) 135 { 136 checkClassBinding!(typeof(this))(); 137 ptrcall!(void)(_classBinding.setClipText, _godot_object, enabled); 138 } 139 /** 140 141 */ 142 bool getClipText() const 143 { 144 checkClassBinding!(typeof(this))(); 145 return ptrcall!(bool)(_classBinding.getClipText, _godot_object); 146 } 147 /** 148 149 */ 150 void setTextAlign(in long _align) 151 { 152 checkClassBinding!(typeof(this))(); 153 ptrcall!(void)(_classBinding.setTextAlign, _godot_object, _align); 154 } 155 /** 156 157 */ 158 Button.TextAlign getTextAlign() const 159 { 160 checkClassBinding!(typeof(this))(); 161 return ptrcall!(Button.TextAlign)(_classBinding.getTextAlign, _godot_object); 162 } 163 /** 164 165 */ 166 bool isFlat() const 167 { 168 checkClassBinding!(typeof(this))(); 169 return ptrcall!(bool)(_classBinding.isFlat, _godot_object); 170 } 171 /** 172 The button's text that will be displayed inside the button's area. 173 */ 174 @property String text() 175 { 176 return getText(); 177 } 178 /// ditto 179 @property void text(String v) 180 { 181 setText(v); 182 } 183 /** 184 Button's icon, if text is present the icon will be placed before the text. 185 */ 186 @property Texture icon() 187 { 188 return getButtonIcon(); 189 } 190 /// ditto 191 @property void icon(Texture v) 192 { 193 setButtonIcon(v); 194 } 195 /** 196 Flat buttons don't display decoration. 197 */ 198 @property bool flat() 199 { 200 return isFlat(); 201 } 202 /// ditto 203 @property void flat(bool v) 204 { 205 setFlat(v); 206 } 207 /** 208 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. This property is disabled by default. 209 */ 210 @property bool clipText() 211 { 212 return getClipText(); 213 } 214 /// ditto 215 @property void clipText(bool v) 216 { 217 setClipText(v); 218 } 219 /** 220 Text alignment policy for the button's text, use one of the ALIGN_* constants. 221 */ 222 @property Button.TextAlign _align() 223 { 224 return getTextAlign(); 225 } 226 /// ditto 227 @property void _align(long v) 228 { 229 setTextAlign(v); 230 } 231 }