1 /** 2 Displays plain text in a line or wrapped inside a rectangle. For formatted text, use $(D RichTextLabel). 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.label; 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.control; 25 import godot.canvasitem; 26 import godot.node; 27 /** 28 Displays plain text in a line or wrapped inside a rectangle. For formatted text, use $(D RichTextLabel). 29 30 Label displays plain text on the screen. It gives you control over the horizontal and vertical alignment and can wrap the text inside the node's bounding rectangle. It doesn't support bold, italics, or other formatting. For that, use $(D RichTextLabel) instead. 31 $(B Note:) Contrarily to most other $(D Control)s, Label's $(D Control.mouseFilter) defaults to $(D constant Control.MOUSE_FILTER_IGNORE) (i.e. it doesn't react to mouse input events). This implies that a label won't display any configured $(D Control.hintTooltip), unless you change its mouse filter. 32 */ 33 @GodotBaseClass struct Label 34 { 35 package(godot) enum string _GODOT_internal_name = "Label"; 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 GDNativeClassBinding 43 { 44 __gshared: 45 @GodotName("get_align") GodotMethod!(Label.Align) getAlign; 46 @GodotName("get_line_count") GodotMethod!(long) getLineCount; 47 @GodotName("get_line_height") GodotMethod!(long) getLineHeight; 48 @GodotName("get_lines_skipped") GodotMethod!(long) getLinesSkipped; 49 @GodotName("get_max_lines_visible") GodotMethod!(long) getMaxLinesVisible; 50 @GodotName("get_percent_visible") GodotMethod!(double) getPercentVisible; 51 @GodotName("get_text") GodotMethod!(String) getText; 52 @GodotName("get_total_character_count") GodotMethod!(long) getTotalCharacterCount; 53 @GodotName("get_valign") GodotMethod!(Label.VAlign) getValign; 54 @GodotName("get_visible_characters") GodotMethod!(long) getVisibleCharacters; 55 @GodotName("get_visible_line_count") GodotMethod!(long) getVisibleLineCount; 56 @GodotName("has_autowrap") GodotMethod!(bool) hasAutowrap; 57 @GodotName("is_clipping_text") GodotMethod!(bool) isClippingText; 58 @GodotName("is_uppercase") GodotMethod!(bool) isUppercase; 59 @GodotName("set_align") GodotMethod!(void, long) setAlign; 60 @GodotName("set_autowrap") GodotMethod!(void, bool) setAutowrap; 61 @GodotName("set_clip_text") GodotMethod!(void, bool) setClipText; 62 @GodotName("set_lines_skipped") GodotMethod!(void, long) setLinesSkipped; 63 @GodotName("set_max_lines_visible") GodotMethod!(void, long) setMaxLinesVisible; 64 @GodotName("set_percent_visible") GodotMethod!(void, double) setPercentVisible; 65 @GodotName("set_text") GodotMethod!(void, String) setText; 66 @GodotName("set_uppercase") GodotMethod!(void, bool) setUppercase; 67 @GodotName("set_valign") GodotMethod!(void, long) setValign; 68 @GodotName("set_visible_characters") GodotMethod!(void, long) setVisibleCharacters; 69 } 70 /// 71 pragma(inline, true) bool opEquals(in Label other) const 72 { return _godot_object.ptr is other._godot_object.ptr; } 73 /// 74 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 75 { _godot_object.ptr = n; return null; } 76 /// 77 pragma(inline, true) bool opEquals(typeof(null) n) const 78 { return _godot_object.ptr is n; } 79 /// 80 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 81 mixin baseCasts; 82 /// Construct a new instance of Label. 83 /// Note: use `memnew!Label` instead. 84 static Label _new() 85 { 86 static godot_class_constructor constructor; 87 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Label"); 88 if(constructor is null) return typeof(this).init; 89 return cast(Label)(constructor()); 90 } 91 @disable new(size_t s); 92 /// 93 enum Align : int 94 { 95 /** 96 Align rows to the left (default). 97 */ 98 alignLeft = 0, 99 /** 100 Align rows centered. 101 */ 102 alignCenter = 1, 103 /** 104 Align rows to the right. 105 */ 106 alignRight = 2, 107 /** 108 Expand row whitespaces to fit the width. 109 */ 110 alignFill = 3, 111 } 112 /// 113 enum VAlign : int 114 { 115 /** 116 Align the whole text to the top. 117 */ 118 valignTop = 0, 119 /** 120 Align the whole text to the center. 121 */ 122 valignCenter = 1, 123 /** 124 Align the whole text to the bottom. 125 */ 126 valignBottom = 2, 127 /** 128 Align the whole text by spreading the rows. 129 */ 130 valignFill = 3, 131 } 132 /// 133 enum Constants : int 134 { 135 alignLeft = 0, 136 valignTop = 0, 137 alignCenter = 1, 138 valignCenter = 1, 139 alignRight = 2, 140 valignBottom = 2, 141 valignFill = 3, 142 alignFill = 3, 143 } 144 /** 145 146 */ 147 Label.Align getAlign() const 148 { 149 checkClassBinding!(typeof(this))(); 150 return ptrcall!(Label.Align)(GDNativeClassBinding.getAlign, _godot_object); 151 } 152 /** 153 Returns the amount of lines of text the Label has. 154 */ 155 long getLineCount() const 156 { 157 checkClassBinding!(typeof(this))(); 158 return ptrcall!(long)(GDNativeClassBinding.getLineCount, _godot_object); 159 } 160 /** 161 Returns the font size in pixels. 162 */ 163 long getLineHeight() const 164 { 165 checkClassBinding!(typeof(this))(); 166 return ptrcall!(long)(GDNativeClassBinding.getLineHeight, _godot_object); 167 } 168 /** 169 170 */ 171 long getLinesSkipped() const 172 { 173 checkClassBinding!(typeof(this))(); 174 return ptrcall!(long)(GDNativeClassBinding.getLinesSkipped, _godot_object); 175 } 176 /** 177 178 */ 179 long getMaxLinesVisible() const 180 { 181 checkClassBinding!(typeof(this))(); 182 return ptrcall!(long)(GDNativeClassBinding.getMaxLinesVisible, _godot_object); 183 } 184 /** 185 186 */ 187 double getPercentVisible() const 188 { 189 checkClassBinding!(typeof(this))(); 190 return ptrcall!(double)(GDNativeClassBinding.getPercentVisible, _godot_object); 191 } 192 /** 193 194 */ 195 String getText() const 196 { 197 checkClassBinding!(typeof(this))(); 198 return ptrcall!(String)(GDNativeClassBinding.getText, _godot_object); 199 } 200 /** 201 Returns the total number of printable characters in the text (excluding spaces and newlines). 202 */ 203 long getTotalCharacterCount() const 204 { 205 checkClassBinding!(typeof(this))(); 206 return ptrcall!(long)(GDNativeClassBinding.getTotalCharacterCount, _godot_object); 207 } 208 /** 209 210 */ 211 Label.VAlign getValign() const 212 { 213 checkClassBinding!(typeof(this))(); 214 return ptrcall!(Label.VAlign)(GDNativeClassBinding.getValign, _godot_object); 215 } 216 /** 217 218 */ 219 long getVisibleCharacters() const 220 { 221 checkClassBinding!(typeof(this))(); 222 return ptrcall!(long)(GDNativeClassBinding.getVisibleCharacters, _godot_object); 223 } 224 /** 225 Returns the number of lines shown. Useful if the $(D Label)'s height cannot currently display all lines. 226 */ 227 long getVisibleLineCount() const 228 { 229 checkClassBinding!(typeof(this))(); 230 return ptrcall!(long)(GDNativeClassBinding.getVisibleLineCount, _godot_object); 231 } 232 /** 233 234 */ 235 bool hasAutowrap() const 236 { 237 checkClassBinding!(typeof(this))(); 238 return ptrcall!(bool)(GDNativeClassBinding.hasAutowrap, _godot_object); 239 } 240 /** 241 242 */ 243 bool isClippingText() const 244 { 245 checkClassBinding!(typeof(this))(); 246 return ptrcall!(bool)(GDNativeClassBinding.isClippingText, _godot_object); 247 } 248 /** 249 250 */ 251 bool isUppercase() const 252 { 253 checkClassBinding!(typeof(this))(); 254 return ptrcall!(bool)(GDNativeClassBinding.isUppercase, _godot_object); 255 } 256 /** 257 258 */ 259 void setAlign(in long _align) 260 { 261 checkClassBinding!(typeof(this))(); 262 ptrcall!(void)(GDNativeClassBinding.setAlign, _godot_object, _align); 263 } 264 /** 265 266 */ 267 void setAutowrap(in bool enable) 268 { 269 checkClassBinding!(typeof(this))(); 270 ptrcall!(void)(GDNativeClassBinding.setAutowrap, _godot_object, enable); 271 } 272 /** 273 274 */ 275 void setClipText(in bool enable) 276 { 277 checkClassBinding!(typeof(this))(); 278 ptrcall!(void)(GDNativeClassBinding.setClipText, _godot_object, enable); 279 } 280 /** 281 282 */ 283 void setLinesSkipped(in long lines_skipped) 284 { 285 checkClassBinding!(typeof(this))(); 286 ptrcall!(void)(GDNativeClassBinding.setLinesSkipped, _godot_object, lines_skipped); 287 } 288 /** 289 290 */ 291 void setMaxLinesVisible(in long lines_visible) 292 { 293 checkClassBinding!(typeof(this))(); 294 ptrcall!(void)(GDNativeClassBinding.setMaxLinesVisible, _godot_object, lines_visible); 295 } 296 /** 297 298 */ 299 void setPercentVisible(in double percent_visible) 300 { 301 checkClassBinding!(typeof(this))(); 302 ptrcall!(void)(GDNativeClassBinding.setPercentVisible, _godot_object, percent_visible); 303 } 304 /** 305 306 */ 307 void setText(in String text) 308 { 309 checkClassBinding!(typeof(this))(); 310 ptrcall!(void)(GDNativeClassBinding.setText, _godot_object, text); 311 } 312 /** 313 314 */ 315 void setUppercase(in bool enable) 316 { 317 checkClassBinding!(typeof(this))(); 318 ptrcall!(void)(GDNativeClassBinding.setUppercase, _godot_object, enable); 319 } 320 /** 321 322 */ 323 void setValign(in long valign) 324 { 325 checkClassBinding!(typeof(this))(); 326 ptrcall!(void)(GDNativeClassBinding.setValign, _godot_object, valign); 327 } 328 /** 329 330 */ 331 void setVisibleCharacters(in long amount) 332 { 333 checkClassBinding!(typeof(this))(); 334 ptrcall!(void)(GDNativeClassBinding.setVisibleCharacters, _godot_object, amount); 335 } 336 /** 337 Controls the text's horizontal align. Supports left, center, right, and fill, or justify. Set it to one of the $(D _align) constants. 338 */ 339 @property Label.Align _align() 340 { 341 return getAlign(); 342 } 343 /// ditto 344 @property void _align(long v) 345 { 346 setAlign(v); 347 } 348 /** 349 If `true`, wraps the text inside the node's bounding rectangle. If you resize the node, it will change its height automatically to show all the text. 350 */ 351 @property bool autowrap() 352 { 353 return hasAutowrap(); 354 } 355 /// ditto 356 @property void autowrap(bool v) 357 { 358 setAutowrap(v); 359 } 360 /** 361 If `true`, the Label only shows the text that fits inside its bounding rectangle and will clip text horizontally. 362 */ 363 @property bool clipText() 364 { 365 return isClippingText(); 366 } 367 /// ditto 368 @property void clipText(bool v) 369 { 370 setClipText(v); 371 } 372 /** 373 The node ignores the first `lines_skipped` lines before it starts to display text. 374 */ 375 @property long linesSkipped() 376 { 377 return getLinesSkipped(); 378 } 379 /// ditto 380 @property void linesSkipped(long v) 381 { 382 setLinesSkipped(v); 383 } 384 /** 385 Limits the lines of text the node shows on screen. 386 */ 387 @property long maxLinesVisible() 388 { 389 return getMaxLinesVisible(); 390 } 391 /// ditto 392 @property void maxLinesVisible(long v) 393 { 394 setMaxLinesVisible(v); 395 } 396 /** 397 Limits the amount of visible characters. If you set `percent_visible` to 0.5, only up to half of the text's characters will display on screen. Useful to animate the text in a dialog box. 398 */ 399 @property double percentVisible() 400 { 401 return getPercentVisible(); 402 } 403 /// ditto 404 @property void percentVisible(double v) 405 { 406 setPercentVisible(v); 407 } 408 /** 409 The text to display on screen. 410 */ 411 @property String text() 412 { 413 return getText(); 414 } 415 /// ditto 416 @property void text(String v) 417 { 418 setText(v); 419 } 420 /** 421 If `true`, all the text displays as UPPERCASE. 422 */ 423 @property bool uppercase() 424 { 425 return isUppercase(); 426 } 427 /// ditto 428 @property void uppercase(bool v) 429 { 430 setUppercase(v); 431 } 432 /** 433 Controls the text's vertical align. Supports top, center, bottom, and fill. Set it to one of the $(D valign) constants. 434 */ 435 @property Label.VAlign valign() 436 { 437 return getValign(); 438 } 439 /// ditto 440 @property void valign(long v) 441 { 442 setValign(v); 443 } 444 /** 445 Restricts the number of characters to display. Set to -1 to disable. 446 */ 447 @property long visibleCharacters() 448 { 449 return getVisibleCharacters(); 450 } 451 /// ditto 452 @property void visibleCharacters(long v) 453 { 454 setVisibleCharacters(v); 455 } 456 }