Description
Currently, the text API which uses Pango isn't great and I would like to refactor it. Here is my proposal:
-
New Class:
FormattedString
- It's similar to a list of strings but would give more control over the formatting of each string. Initialising it would require the following optional parameters:text
: The text to show. This would be added as the first in the list.font
: The fonts of the strings. Default when not overridden individually. (much like howtext
inMarkupText
current is)font_size
: The size of the font. Default when not overridden individually.fallback_font
: Font to fall back to when the main one isn't available or doesn't contain a specific character. This can also be overridden individually.color
: The color of the text. Default to white. Probably should be overridden by themes.strikethrough
: whether to strikethroughstrikethrough_color
: the color of strikethroughinsert_hypens
: use hyphens when breaking a work (default to True)underline
: Underline the text.overline
: Draw an overline on text.underline_color
: Color of underlineoverline_color
: Color of overlinebaseline_shift
: Set's baseline shift for a given textopen_type_features
: which features to enablelanguage
: The language of the textindent
: the indent of the parastyle
: styles of textweight
: Font weightletter_spacing
: Space between letters
and more see https://gnome.pages.gitlab.gnome.org/gtk/Pango/enum.AttrType.html
-
The
FormattedString
will have the functions:clear
: clear all the texts storedappend
: Add a new text. Accepts all arguments from__init__()
.
-
Addition should be possible with
FormattedString
. If the addition isFormattedString
andFormattedString
it should add items from second to the first one. If the addition isFormattedString
andstr
a new text should be added to the original one. -
The
Text
class which exists should accept anstr
and aFormattedString
. The string passed here will be considered as Pango Markup. -
The
MarkupText
class will be deprecated. -
All the
t2*
parameters are deprecated and removed from theText
class. -
Paragraph
will be aliased toText
-
Text
will have new parameterswidth
andheight
which will be considered when creating text and paragraphs would be broken based on this. By defaultwidth
andheight
should be full screen. -
Text
will be treated as a paragraph, which means it has parameters like
-justify
: Justify paragraph
-align
: Align the text should beleft
,right
,center
-line_height
: Height of each line. -
Text
should also accept parameters fromFormattedString
for backwards compatibility.
Example Code
class TextScene(Scene):
def construct(self):
a = FormattedString(font="Roboto")
a += "Hello"
a += "World"
a.append("bold", weigth=BOLD)
self.add(Text(a))
CC: @PhilippImhof
Metadata
Metadata
Assignees
Type
Projects
Status