Skip to content

TextBlock

Michael Palmos edited this page Aug 14, 2022 · 19 revisions

TextBlock

This block is used to display text.

Required Properties

Name Type Description Example
padding Padding Padding around the block, which is applied before hooking. padding: Padding(left: 7.0, right: 7.0, top: 7.0, bottom: 7.0
text string Text to display in this text block. %s will be substituted with the summary text, %b with the body text, and a few more. See the Text Markup wiki page for full details. text: "%s"
text: "%t(%H:%M %P)"
font string Font description string for the desired font, in the format of "[FAMILY-LIST] [STYLE-OPTIONS] [SIZE] [VARIATIONS]".
For more information on font descriptions, see pango documentation.
> To find a font family's name, try fc-list in a terminal.
font: "Arial Bold 10"
color Color Text color. color: Color(hex: "#ebdbb2")
dimensions Dimensions Desired text dimensions. This means minimum and maximum width and height of the block (in pixels).
See notes below for more information on this behavior.
dimensions: (width: (min: 50, max: 150), height: (min: 0, max: 0))

Optional Properties

Name Type Description Example
color_hovered Color The text color that should be used while the mouse is hovered over this block.
Default: use color
color_hovered: Color(hex: "#fbf1c7")
dimensions_image_hint Dimensions Desired text dimensions when an image type of hint present.
Default: use dimensions
dimensions_image_hint: (width: (min: 50, max: 150), height: (min: 0, max: 0))
dimensions_image_app Dimensions Desired text dimensions when an image type of app is present.
Default: use dimensions
dimensions_image_app: (width: (min: 50, max: 150), height: (min: 0, max: 0))
dimensions_image_both Dimensions Desired text dimensions when both app image and hint image is present.
Default: use dimensions
dimensions_image_both: (width: (min: 50, max: 150), height: (min: 0, max: 0))
ellipsize EllipsizeMode Determines which part of the string should be trimmed when it exceeds its maximum width.
Either Start, Middle, End, or None.
Default: Middle
ellipsize: Middle
align AlignMode Where the text should be aligned within its block. Note that this only really useful if your dimensions are larger than the text.
Either Left, Center, or Right.
Default: Left
align: Center

Additional Information

Dimensions Behavior

The way the minimum and maximum width and height of text blocks work is a bit unintuitive; sorry about that.

The max fields are actually passed directly to Pango's layout_set_width() and layout_set_height() functions. Their documentation explains the behavior in much more detail than I can here, but the cheat sheet is this:

  • A positive max width means that the text will be truncated to that pixel length. Note that this truncation isn't always pixel exact; if you want a precisely sized text block, set min and max to the same value.
  • A max width of -1 means that the text will not be truncated or wrapped at all. This can produce some pretty long notifications.
  • A positive max height ultimately decides how many lines should be shown. At least one line is always shown.
  • A negative max height does paragraph related stuff -- you probably don't want this for notifications.

Useful resources:

The min fields primarily exist to allow for precisely sized text block, and to give some more visual control. For instance, you may want to set a min width so that particularly short notifications don't look ugly.

Other useful resources: set_ellipsize, set_width, set_height


TextBlock negative max width
ellipsize: Middle, dimensions: (width: min: 50, max: -1), height: (min: 0, max: 0))

TextBlock ellipsize none
ellipsize: None, dimensions: (width: (min: 50, max: 150), height: (min: 0, max: 0))

Notice that the height property is overridden here because we're using ellipsize: None.

TextBlock ellipsize start
ellipsize: Start, dimensions: <as above>

TextBlock ellipsize middle
ellipsize: Middle, dimensions: <as above>

TextBlock ellipsize end
ellipsize: End, dimensions: <as above>

Clone this wiki locally