Package icyllis.modernui.text

# Class StaticLayout.Builder

java.lang.Object
icyllis.modernui.text.StaticLayout.Builder

Enclosing class:
  `StaticLayout`

public static final class StaticLayout.Builder extends Object
Builder for static layouts. The builder is the preferred pattern for constructing StaticLayout objects and should be preferred over the constructors, particularly to access newer features. To build a static layout, first call `StaticLayout.builder(CharSequence, int, int, TextPaint, int)` with the required arguments (text, paint, and width), then call setters for optional parameters, and finally `build()` to build the StaticLayout object. Parameters not explicitly set will get default values.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `StaticLayout`
  `build()`
  Build the `StaticLayout` after options have been set.
  `StaticLayout.Builder`
  `setAlignment(Layout.Alignment alignment)`
  Set the alignment.
  `StaticLayout.Builder`
  `setEllipsize(TextUtils.TruncateAt ellipsize)`
  Set ellipsizing on the layout.
  `StaticLayout.Builder`
  `setEllipsizedWidth(int ellipsizedWidth)`
  Set the width as used for ellipsizing purposes, if it differs from the normal layout width.
  `StaticLayout.Builder`
  `setFallbackLineSpacing(boolean fallbackLineSpacing)`
  Set whether to respect the ascent and descent of the fallback fonts that are used in displaying the text (which is needed to avoid text from consecutive lines running into each other).
  `StaticLayout.Builder`
  `setIncludePad(boolean includePad)`
  Set whether to include extra space beyond font ascent and descent (which is needed to avoid clipping in some languages, such as Arabic and Kannada).
  `StaticLayout.Builder`
  `setIndents(int[] leftIndents, int[] rightIndents)`
  Set indents.
  `StaticLayout.Builder`
  `setLineBreakConfig(LineBreakConfig lineBreakConfig)`
  Set the line break configuration.
  `StaticLayout.Builder`
  `setMaxLines(int maxLines)`
  Set maximum number of lines.
  `StaticLayout.Builder`
  `setTextDirection(TextDirectionHeuristic textDir)`
  Set the text direction heuristic.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### setAlignment

    @NonNull public StaticLayout.Builder setAlignment(@NonNull Layout.Alignment alignment)
    Set the alignment. The default is `Layout.Alignment.ALIGN_NORMAL`.
    Parameters:
      `alignment` - Alignment for the resulting `StaticLayout`
    Returns:
      this builder, useful for chaining

  - ### setTextDirection

    @NonNull public StaticLayout.Builder setTextDirection(@NonNull TextDirectionHeuristic textDir)
    Set the text direction heuristic. The text direction heuristic is used to resolve text direction per-paragraph based on the input text. The default is `TextDirectionHeuristics.FIRSTSTRONG_LTR`.
    Parameters:
      `textDir` - text direction heuristic for resolving bidi behavior.
    Returns:
      this builder, useful for chaining

  - ### setIncludePad

    @NonNull public StaticLayout.Builder setIncludePad(boolean includePad)
    Set whether to include extra space beyond font ascent and descent (which is needed to avoid clipping in some languages, such as Arabic and Kannada). The default is `true`.
    Parameters:
      `includePad` - whether to include padding
    Returns:
      this builder, useful for chaining

  - ### setFallbackLineSpacing

    @NonNull public StaticLayout.Builder setFallbackLineSpacing(boolean fallbackLineSpacing)
    Set whether to respect the ascent and descent of the fallback fonts that are used in displaying the text (which is needed to avoid text from consecutive lines running into each other). If set, fallback fonts that end up getting used can increase the ascent and descent of the lines that they are used on.

    The default is `true`. It is required to be true if text could be in languages like Burmese or Tibetan where text is typically much taller or deeper than Latin text.

    Parameters:
      `fallbackLineSpacing` - whether to expand line spacing based on fallback fonts
    Returns:
      this builder, useful for chaining

  - ### setEllipsizedWidth

    @NonNull public StaticLayout.Builder setEllipsizedWidth(int ellipsizedWidth)
    Set the width as used for ellipsizing purposes, if it differs from the normal layout width. The default is the `width` passed to `build()`.
    Parameters:
      `ellipsizedWidth` - width used for ellipsizing, in pixels
    Returns:
      this builder, useful for chaining

  - ### setEllipsize

    @NonNull public StaticLayout.Builder setEllipsize(@Nullable TextUtils.TruncateAt ellipsize)
    Set ellipsizing on the layout. Causes words that are longer than the view is wide, or exceeding the number of lines (see #setMaxLines) in the case of `TextUtils.TruncateAt.END` or `TextUtils.TruncateAt.MARQUEE`, to be ellipsized instead of broken. The default is `null`, indicating no ellipsis is to be applied.
    Parameters:
      `ellipsize` - type of ellipsis behavior
    Returns:
      this builder, useful for chaining

  - ### setMaxLines

    @NonNull public StaticLayout.Builder setMaxLines(int maxLines)
    Set maximum number of lines. This is particularly useful in the case of ellipsizing, where it changes the layout of the last line. The default is unlimited.
    Parameters:
      `maxLines` - maximum number of lines in the layout
    Returns:
      this builder, useful for chaining

  - ### setIndents

    @NonNull public StaticLayout.Builder setIndents(@Nullable int[] leftIndents, @Nullable int[] rightIndents)
    Set indents. Arguments are arrays holding an indent amount, one per line, measured in pixels. For lines past the last element in the array, the last element repeats.
    Parameters:
      `leftIndents` - array of indent values for left margin, in pixels
      `rightIndents` - array of indent values for right margin, in pixels
    Returns:
      this builder, useful for chaining

  - ### setLineBreakConfig

    @NonNull public StaticLayout.Builder setLineBreakConfig(@NonNull LineBreakConfig lineBreakConfig)
    Set the line break configuration. The line break will be passed to native used for calculating the text wrapping. The default value of the line break style is `LineBreakConfig.LINE_BREAK_STYLE_NONE`
    Parameters:
      `lineBreakConfig` - the line break configuration for text wrapping.
    Returns:
      this builder, useful for chaining.
    See Also:
      - `TextView.setLineBreakStyle(int)`
      - `TextView.setLineBreakWordStyle(int)`

  - ### build

    @NonNull public StaticLayout build()
    Build the `StaticLayout` after options have been set.

    Note: the builder object must not be reused in any way after calling this method. Setting parameters after calling this method, or calling it a second time on the same builder object, will likely lead to unexpected results.

    Returns:
      the newly constructed `StaticLayout` object