Package icyllis.modernui.graphics.text

# Class MeasuredText.Builder

java.lang.Object
icyllis.modernui.graphics.text.MeasuredText.Builder

Enclosing class:
  `MeasuredText`

public static class MeasuredText.Builder extends Object
For creating a MeasuredText.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Builder(char[] text)`
  Construct a builder.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addReplacementRun(Locale locale, int length, float width)`
  `void`
  `addStyleRun(FontPaint paint, LineBreakConfig lineBreakConfig, int length, boolean isRtl)`
  `MeasuredText.Builder`
  `appendReplacementRun(TextPaint paint, int length, float width)`
  Used to inform the text layout that the given length is replaced with the object of given width.
  `MeasuredText.Builder`
  `appendStyleRun(TextPaint paint, int length, boolean isRtl)`
  Apply styles to the given length.
  `MeasuredText.Builder`
  `appendStyleRun(TextPaint paint, LineBreakConfig lineBreakConfig, int length, boolean isRtl)`
  Apply styles to the given length.
  `MeasuredText`
  `build()`
  Starts laying-out the text and creates a MeasuredText for the result.
  `MeasuredText.Builder`
  `setComputeLayout(boolean computeLayout)`
  By passing true to this method, the build method will compute all full layout information.

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

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

- ## Constructor Details

  - ### Builder

    public Builder(@NonNull char[] text)
    Construct a builder.

    The MeasuredText returned by build method will hold a reference of the text, then the char array must be immutable.

    Parameters:
      `text` - a text, with full range, can be empty

- ## Method Details

  - ### appendStyleRun

    @NonNull public MeasuredText.Builder appendStyleRun(@NonNull TextPaint paint, @IntRange(from=0L) int length, boolean isRtl)
    Apply styles to the given length.

    Keeps an internal offset which increases at every append. The initial value for this offset is zero. After the style is applied the internal offset is moved to `offset + length`, and next call will start from this new position.

    Parameters:
      `paint` - a paint
      `length` - a length to be applied with a given paint, can not exceed the length of the text
      `isRtl` - true if the text is in RTL context, otherwise false.

  - ### appendStyleRun

    @NonNull public MeasuredText.Builder appendStyleRun(@NonNull TextPaint paint, @Nullable LineBreakConfig lineBreakConfig, @IntRange(from=0L) int length, boolean isRtl)
    Apply styles to the given length.

    Keeps an internal offset which increases at every append. The initial value for this offset is zero. After the style is applied the internal offset is moved to `offset + length`, and next call will start from this new position.

    Parameters:
      `paint` - a paint
      `lineBreakConfig` - a line break configuration.
      `length` - a length to be applied with a given paint, can not exceed the length of the text
      `isRtl` - true if the text is in RTL context, otherwise false.

  - ### addStyleRun

    public void addStyleRun(@NonNull FontPaint paint, @Nullable LineBreakConfig lineBreakConfig, @IntRange(from=0L) int length, boolean isRtl)

  - ### appendReplacementRun

    @NonNull public MeasuredText.Builder appendReplacementRun(@NonNull TextPaint paint, @IntRange(from=0L) int length, @FloatRange(from=0.0) float width)
    Used to inform the text layout that the given length is replaced with the object of given width.

    Keeps an internal offset which increases at every append. The initial value for this offset is zero. After the style is applied the internal offset is moved to `offset + length`, and next call will start from this new position.

    Informs the layout engine that the given length should not be processed, instead the provided width should be used for calculating the width of that range.

    Parameters:
      `paint` - a paint
      `length` - a length to be replaced with the object, can not exceed the length of the text
      `width` - a replacement width of the range in pixels

  - ### addReplacementRun

    public void addReplacementRun(@NonNull Locale locale, @IntRange(from=0L) int length, @FloatRange(from=0.0) float width)

  - ### setComputeLayout

    @NonNull public MeasuredText.Builder setComputeLayout(boolean computeLayout)
    By passing true to this method, the build method will compute all full layout information.
    Parameters:
      `computeLayout` - true if you want to retrieve full layout info, e.g. glyphs bounds

  - ### build

    @NonNull public MeasuredText build()
    Starts laying-out the text and creates a MeasuredText for the result.

    Once you called this method, you can't touch this Builder again.

    Returns:
      text measurement result