Skip to content

Latest commit

 

History

History
708 lines (414 loc) · 36.4 KB

class_label.rst

File metadata and controls

708 lines (414 loc) · 36.4 KB
github_url:hide

Label

Inherits: :ref:`Control<class_Control>` < :ref:`CanvasItem<class_CanvasItem>` < :ref:`Node<class_Node>` < :ref:`Object<class_Object>`

A control for displaying plain text.

.. rst-class:: classref-introduction-group

Description

A control for displaying plain text. 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 rich text formatting. For that, use :ref:`RichTextLabel<class_RichTextLabel>` instead.

.. rst-class:: classref-introduction-group

Tutorials

.. rst-class:: classref-reftable-group

Properties

:ref:`AutowrapMode<enum_TextServer_AutowrapMode>` :ref:`autowrap_mode<class_Label_property_autowrap_mode>` 0
:ref:`bool<class_bool>` :ref:`clip_text<class_Label_property_clip_text>` false
:ref:`String<class_String>` :ref:`ellipsis_char<class_Label_property_ellipsis_char>` "…"
:ref:`HorizontalAlignment<enum_@GlobalScope_HorizontalAlignment>` :ref:`horizontal_alignment<class_Label_property_horizontal_alignment>` 0
|bitfield|[:ref:`JustificationFlag<enum_TextServer_JustificationFlag>`] :ref:`justification_flags<class_Label_property_justification_flags>` 163
:ref:`LabelSettings<class_LabelSettings>` :ref:`label_settings<class_Label_property_label_settings>`  
:ref:`String<class_String>` :ref:`language<class_Label_property_language>` ""
:ref:`int<class_int>` :ref:`lines_skipped<class_Label_property_lines_skipped>` 0
:ref:`int<class_int>` :ref:`max_lines_visible<class_Label_property_max_lines_visible>` -1
:ref:`MouseFilter<enum_Control_MouseFilter>` mouse_filter 2 (overrides :ref:`Control<class_Control_property_mouse_filter>`)
|bitfield|[:ref:`SizeFlags<enum_Control_SizeFlags>`] size_flags_vertical 4 (overrides :ref:`Control<class_Control_property_size_flags_vertical>`)
:ref:`StructuredTextParser<enum_TextServer_StructuredTextParser>` :ref:`structured_text_bidi_override<class_Label_property_structured_text_bidi_override>` 0
:ref:`Array<class_Array>` :ref:`structured_text_bidi_override_options<class_Label_property_structured_text_bidi_override_options>` []
:ref:`PackedFloat32Array<class_PackedFloat32Array>` :ref:`tab_stops<class_Label_property_tab_stops>` PackedFloat32Array()
:ref:`String<class_String>` :ref:`text<class_Label_property_text>` ""
:ref:`TextDirection<enum_Control_TextDirection>` :ref:`text_direction<class_Label_property_text_direction>` 0
:ref:`OverrunBehavior<enum_TextServer_OverrunBehavior>` :ref:`text_overrun_behavior<class_Label_property_text_overrun_behavior>` 0
:ref:`bool<class_bool>` :ref:`uppercase<class_Label_property_uppercase>` false
:ref:`VerticalAlignment<enum_@GlobalScope_VerticalAlignment>` :ref:`vertical_alignment<class_Label_property_vertical_alignment>` 0
:ref:`int<class_int>` :ref:`visible_characters<class_Label_property_visible_characters>` -1
:ref:`VisibleCharactersBehavior<enum_TextServer_VisibleCharactersBehavior>` :ref:`visible_characters_behavior<class_Label_property_visible_characters_behavior>` 0
:ref:`float<class_float>` :ref:`visible_ratio<class_Label_property_visible_ratio>` 1.0
.. rst-class:: classref-reftable-group

Methods

:ref:`Rect2<class_Rect2>` :ref:`get_character_bounds<class_Label_method_get_character_bounds>`(pos: :ref:`int<class_int>`) |const|
:ref:`int<class_int>` :ref:`get_line_count<class_Label_method_get_line_count>`() |const|
:ref:`int<class_int>` :ref:`get_line_height<class_Label_method_get_line_height>`(line: :ref:`int<class_int>` = -1) |const|
:ref:`int<class_int>` :ref:`get_total_character_count<class_Label_method_get_total_character_count>`() |const|
:ref:`int<class_int>` :ref:`get_visible_line_count<class_Label_method_get_visible_line_count>`() |const|
.. rst-class:: classref-reftable-group

Theme Properties

:ref:`Color<class_Color>` :ref:`font_color<class_Label_theme_color_font_color>` Color(1, 1, 1, 1)
:ref:`Color<class_Color>` :ref:`font_outline_color<class_Label_theme_color_font_outline_color>` Color(0, 0, 0, 1)
:ref:`Color<class_Color>` :ref:`font_shadow_color<class_Label_theme_color_font_shadow_color>` Color(0, 0, 0, 0)
:ref:`int<class_int>` :ref:`line_spacing<class_Label_theme_constant_line_spacing>` 3
:ref:`int<class_int>` :ref:`outline_size<class_Label_theme_constant_outline_size>` 0
:ref:`int<class_int>` :ref:`shadow_offset_x<class_Label_theme_constant_shadow_offset_x>` 1
:ref:`int<class_int>` :ref:`shadow_offset_y<class_Label_theme_constant_shadow_offset_y>` 1
:ref:`int<class_int>` :ref:`shadow_outline_size<class_Label_theme_constant_shadow_outline_size>` 1
:ref:`Font<class_Font>` :ref:`font<class_Label_theme_font_font>`  
:ref:`int<class_int>` :ref:`font_size<class_Label_theme_font_size_font_size>`  
:ref:`StyleBox<class_StyleBox>` :ref:`normal<class_Label_theme_style_normal>`  
.. rst-class:: classref-section-separator


.. rst-class:: classref-descriptions-group

Property Descriptions

.. rst-class:: classref-property

:ref:`AutowrapMode<enum_TextServer_AutowrapMode>` autowrap_mode = 0 :ref:`🔗<class_Label_property_autowrap_mode>`

.. rst-class:: classref-property-setget

If set to something other than :ref:`TextServer.AUTOWRAP_OFF<class_TextServer_constant_AUTOWRAP_OFF>`, the text gets wrapped inside the node's bounding rectangle. If you resize the node, it will change its height automatically to show all the text. To see how each mode behaves, see :ref:`AutowrapMode<enum_TextServer_AutowrapMode>`.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

:ref:`bool<class_bool>` clip_text = false :ref:`🔗<class_Label_property_clip_text>`

.. rst-class:: classref-property-setget

If true, the Label only shows the text that fits inside its bounding rectangle and will clip text horizontally.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

:ref:`String<class_String>` ellipsis_char = "…" :ref:`🔗<class_Label_property_ellipsis_char>`

.. rst-class:: classref-property-setget

Ellipsis character used for text clipping.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

:ref:`HorizontalAlignment<enum_@GlobalScope_HorizontalAlignment>` horizontal_alignment = 0 :ref:`🔗<class_Label_property_horizontal_alignment>`

.. rst-class:: classref-property-setget

Controls the text's horizontal alignment. Supports left, center, right, and fill, or justify. Set it to one of the :ref:`HorizontalAlignment<enum_@GlobalScope_HorizontalAlignment>` constants.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

|bitfield|[:ref:`JustificationFlag<enum_TextServer_JustificationFlag>`] justification_flags = 163 :ref:`🔗<class_Label_property_justification_flags>`

.. rst-class:: classref-property-setget

Line fill alignment rules. For more info see :ref:`JustificationFlag<enum_TextServer_JustificationFlag>`.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

:ref:`LabelSettings<class_LabelSettings>` label_settings :ref:`🔗<class_Label_property_label_settings>`

.. rst-class:: classref-property-setget

A :ref:`LabelSettings<class_LabelSettings>` resource that can be shared between multiple Label nodes. Takes priority over theme properties.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

:ref:`String<class_String>` language = "" :ref:`🔗<class_Label_property_language>`

.. rst-class:: classref-property-setget

Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

:ref:`int<class_int>` lines_skipped = 0 :ref:`🔗<class_Label_property_lines_skipped>`

.. rst-class:: classref-property-setget

The number of the lines ignored and not displayed from the start of the :ref:`text<class_Label_property_text>` value.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

:ref:`int<class_int>` max_lines_visible = -1 :ref:`🔗<class_Label_property_max_lines_visible>`

.. rst-class:: classref-property-setget

Limits the lines of text the node shows on screen.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

:ref:`StructuredTextParser<enum_TextServer_StructuredTextParser>` structured_text_bidi_override = 0 :ref:`🔗<class_Label_property_structured_text_bidi_override>`

.. rst-class:: classref-property-setget

Set BiDi algorithm override for the structured text.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

:ref:`Array<class_Array>` structured_text_bidi_override_options = [] :ref:`🔗<class_Label_property_structured_text_bidi_override_options>`

.. rst-class:: classref-property-setget

Set additional options for BiDi override.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

:ref:`PackedFloat32Array<class_PackedFloat32Array>` tab_stops = PackedFloat32Array() :ref:`🔗<class_Label_property_tab_stops>`

.. rst-class:: classref-property-setget

Aligns text to the given tab-stops.

Note: The returned array is copied and any changes to it will not update the original property value. See :ref:`PackedFloat32Array<class_PackedFloat32Array>` for more details.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

:ref:`String<class_String>` text = "" :ref:`🔗<class_Label_property_text>`

.. rst-class:: classref-property-setget

The text to display on screen.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

:ref:`TextDirection<enum_Control_TextDirection>` text_direction = 0 :ref:`🔗<class_Label_property_text_direction>`

.. rst-class:: classref-property-setget

Base text writing direction.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

:ref:`OverrunBehavior<enum_TextServer_OverrunBehavior>` text_overrun_behavior = 0 :ref:`🔗<class_Label_property_text_overrun_behavior>`

.. rst-class:: classref-property-setget

Sets the clipping behavior when the text exceeds the node's bounding rectangle. See :ref:`OverrunBehavior<enum_TextServer_OverrunBehavior>` for a description of all modes.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

:ref:`bool<class_bool>` uppercase = false :ref:`🔗<class_Label_property_uppercase>`

.. rst-class:: classref-property-setget

If true, all the text displays as UPPERCASE.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

:ref:`VerticalAlignment<enum_@GlobalScope_VerticalAlignment>` vertical_alignment = 0 :ref:`🔗<class_Label_property_vertical_alignment>`

.. rst-class:: classref-property-setget

Controls the text's vertical alignment. Supports top, center, bottom, and fill. Set it to one of the :ref:`VerticalAlignment<enum_@GlobalScope_VerticalAlignment>` constants.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

:ref:`int<class_int>` visible_characters = -1 :ref:`🔗<class_Label_property_visible_characters>`

.. rst-class:: classref-property-setget

The number of characters to display. If set to -1, all characters are displayed. This can be useful when animating the text appearing in a dialog box.

Note: Setting this property updates :ref:`visible_ratio<class_Label_property_visible_ratio>` accordingly.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

:ref:`VisibleCharactersBehavior<enum_TextServer_VisibleCharactersBehavior>` visible_characters_behavior = 0 :ref:`🔗<class_Label_property_visible_characters_behavior>`

.. rst-class:: classref-property-setget

Sets the clipping behavior when :ref:`visible_characters<class_Label_property_visible_characters>` or :ref:`visible_ratio<class_Label_property_visible_ratio>` is set. See :ref:`VisibleCharactersBehavior<enum_TextServer_VisibleCharactersBehavior>` for more info.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

:ref:`float<class_float>` visible_ratio = 1.0 :ref:`🔗<class_Label_property_visible_ratio>`

.. rst-class:: classref-property-setget

The fraction of characters to display, relative to the total number of characters (see :ref:`get_total_character_count<class_Label_method_get_total_character_count>`). If set to 1.0, all characters are displayed. If set to 0.5, only half of the characters will be displayed. This can be useful when animating the text appearing in a dialog box.

Note: Setting this property updates :ref:`visible_characters<class_Label_property_visible_characters>` accordingly.

.. rst-class:: classref-section-separator


.. rst-class:: classref-descriptions-group

Method Descriptions

.. rst-class:: classref-method

:ref:`Rect2<class_Rect2>` get_character_bounds(pos: :ref:`int<class_int>`) |const| :ref:`🔗<class_Label_method_get_character_bounds>`

Returns the bounding rectangle of the character at position pos. If the character is a non-visual character or pos is outside the valid range, an empty :ref:`Rect2<class_Rect2>` is returned. If the character is a part of a composite grapheme, the bounding rectangle of the whole grapheme is returned.

.. rst-class:: classref-item-separator


.. rst-class:: classref-method

:ref:`int<class_int>` get_line_count() |const| :ref:`🔗<class_Label_method_get_line_count>`

Returns the number of lines of text the Label has.

.. rst-class:: classref-item-separator


.. rst-class:: classref-method

:ref:`int<class_int>` get_line_height(line: :ref:`int<class_int>` = -1) |const| :ref:`🔗<class_Label_method_get_line_height>`

Returns the height of the line line.

If line is set to -1, returns the biggest line height.

If there are no lines, returns font size in pixels.

.. rst-class:: classref-item-separator


.. rst-class:: classref-method

:ref:`int<class_int>` get_total_character_count() |const| :ref:`🔗<class_Label_method_get_total_character_count>`

Returns the total number of printable characters in the text (excluding spaces and newlines).

.. rst-class:: classref-item-separator


.. rst-class:: classref-method

:ref:`int<class_int>` get_visible_line_count() |const| :ref:`🔗<class_Label_method_get_visible_line_count>`

Returns the number of lines shown. Useful if the Label's height cannot currently display all lines.

.. rst-class:: classref-section-separator


.. rst-class:: classref-descriptions-group

Theme Property Descriptions

.. rst-class:: classref-themeproperty

:ref:`Color<class_Color>` font_color = Color(1, 1, 1, 1) :ref:`🔗<class_Label_theme_color_font_color>`

Default text :ref:`Color<class_Color>` of the Label.

.. rst-class:: classref-item-separator


.. rst-class:: classref-themeproperty

:ref:`Color<class_Color>` font_outline_color = Color(0, 0, 0, 1) :ref:`🔗<class_Label_theme_color_font_outline_color>`

The color of text outline.

.. rst-class:: classref-item-separator


.. rst-class:: classref-themeproperty

:ref:`Color<class_Color>` font_shadow_color = Color(0, 0, 0, 0) :ref:`🔗<class_Label_theme_color_font_shadow_color>`

:ref:`Color<class_Color>` of the text's shadow effect.

.. rst-class:: classref-item-separator


.. rst-class:: classref-themeproperty

:ref:`int<class_int>` line_spacing = 3 :ref:`🔗<class_Label_theme_constant_line_spacing>`

Vertical space between lines in multiline Label.

.. rst-class:: classref-item-separator


.. rst-class:: classref-themeproperty

:ref:`int<class_int>` outline_size = 0 :ref:`🔗<class_Label_theme_constant_outline_size>`

Text outline size.

Note: If using a font with :ref:`FontFile.multichannel_signed_distance_field<class_FontFile_property_multichannel_signed_distance_field>` enabled, its :ref:`FontFile.msdf_pixel_range<class_FontFile_property_msdf_pixel_range>` must be set to at least twice the value of :ref:`outline_size<class_Label_theme_constant_outline_size>` for outline rendering to look correct. Otherwise, the outline may appear to be cut off earlier than intended.

Note: Using a value that is larger than half the font size is not recommended, as the font outline may fail to be fully closed in this case.

.. rst-class:: classref-item-separator


.. rst-class:: classref-themeproperty

:ref:`int<class_int>` shadow_offset_x = 1 :ref:`🔗<class_Label_theme_constant_shadow_offset_x>`

The horizontal offset of the text's shadow.

.. rst-class:: classref-item-separator


.. rst-class:: classref-themeproperty

:ref:`int<class_int>` shadow_offset_y = 1 :ref:`🔗<class_Label_theme_constant_shadow_offset_y>`

The vertical offset of the text's shadow.

.. rst-class:: classref-item-separator


.. rst-class:: classref-themeproperty

:ref:`int<class_int>` shadow_outline_size = 1 :ref:`🔗<class_Label_theme_constant_shadow_outline_size>`

The size of the shadow outline.

.. rst-class:: classref-item-separator


.. rst-class:: classref-themeproperty

:ref:`Font<class_Font>` font :ref:`🔗<class_Label_theme_font_font>`

:ref:`Font<class_Font>` used for the Label's text.

.. rst-class:: classref-item-separator


.. rst-class:: classref-themeproperty

:ref:`int<class_int>` font_size :ref:`🔗<class_Label_theme_font_size_font_size>`

Font size of the Label's text.

.. rst-class:: classref-item-separator


.. rst-class:: classref-themeproperty

:ref:`StyleBox<class_StyleBox>` normal :ref:`🔗<class_Label_theme_style_normal>`

Background :ref:`StyleBox<class_StyleBox>` for the Label.