text_align property

This page explains the text-related text_align property.

What property is this?

The text_align property updates or gets the instance’s text alignment setting.

Basic usage

The getter and setter interfaces’ type becomes a CssTextAlign enum value.

The acceptable enum values are as follows:

  • CssTextAlign.LEFT (default)

  • CssTextAlign.CENTER

  • CssTextAlign.RIGHT

  • CssTextAlign.JUSTIFY

Example of CssTextAlign.LEFT

Notes: This setting is a default setting.

import apysc as ap

stage: ap.Stage = ap.Stage(
    background_color=ap.Color("#333"),
    stage_width=350,
    stage_height=170,
    stage_elem_id="stage",
)
multi_line_text: ap.MultiLineText = ap.MultiLineText(
    text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, "
    "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "
    "Ut enim ad minim veniam",
    width=300,
    font_size=16,
    fill_color=ap.Color("#00aaff"),
    x=25,
    y=25,
)
multi_line_text.text_align = ap.CssTextAlign.LEFT

ap.save_overall_html(dest_dir_path="./css_text_align_left/")

Example of CssTextAlign.CENTER

import apysc as ap

stage: ap.Stage = ap.Stage(
    background_color=ap.Color("#333"),
    stage_width=350,
    stage_height=170,
    stage_elem_id="stage",
)
multi_line_text: ap.MultiLineText = ap.MultiLineText(
    text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, "
    "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "
    "Ut enim ad minim veniam",
    width=300,
    font_size=16,
    fill_color=ap.Color("#00aaff"),
    x=25,
    y=25,
)
multi_line_text.text_align = ap.CssTextAlign.CENTER

ap.save_overall_html(dest_dir_path="./css_text_align_center/")

Example of CssTextAlign.RIGHT

import apysc as ap

stage: ap.Stage = ap.Stage(
    background_color=ap.Color("#333"),
    stage_width=350,
    stage_height=170,
    stage_elem_id="stage",
)
multi_line_text: ap.MultiLineText = ap.MultiLineText(
    text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, "
    "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "
    "Ut enim ad minim veniam",
    width=300,
    font_size=16,
    fill_color=ap.Color("#00aaff"),
    x=25,
    y=25,
)
multi_line_text.text_align = ap.CssTextAlign.RIGHT

ap.save_overall_html(dest_dir_path="./css_text_align_right/")

Example of CSSTextAlign.JUSTIFY

Notes: This enum setting justifies a text evenly.

import apysc as ap

stage: ap.Stage = ap.Stage(
    background_color=ap.Color("#333"),
    stage_width=350,
    stage_height=170,
    stage_elem_id="stage",
)
multi_line_text: ap.MultiLineText = ap.MultiLineText(
    text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, "
    "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "
    "Ut enim ad minim veniam",
    width=300,
    font_size=16,
    fill_color=ap.Color("#00aaff"),
    x=25,
    y=25,
)
multi_line_text.text_align = ap.CssTextAlign.JUSTIFY

ap.save_overall_html(dest_dir_path="./css_text_align_justify/")

text_align property API

Note: the document build script generates and updates this API document section automatically. Maybe this section is duplicated compared with previous sections.

[Interface summary]

Get a text-align value.


[Returns]

  • text_align: CssTextAlign

    • A text-align value.


[Examples]

>>> import apysc as ap
>>> stage: ap.Stage = ap.Stage(
...     background_color=ap.Color("#333"),
...     stage_width=350,
...     stage_height=170,
...     stage_elem_id="stage",
... )
>>> multi_line_text: ap.MultiLineText = ap.MultiLineText(
...     text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, "
...     "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "
...     "Ut enim ad minim veniam",
...     width=300,
...     font_size=16,
...     fill_color=ap.Color("#00aaff"),
...     x=25,
...     y=25,
... )
>>> multi_line_text.text_align = ap.CssTextAlign.RIGHT
>>> assert multi_line_text.text_align == ap.CssTextAlign.RIGHT