Package icyllis.modernui.text
Class BoringLayout
java.lang.Object
icyllis.modernui.text.Layout
icyllis.modernui.text.BoringLayout
- All Implemented Interfaces:
TextUtils.EllipsizeCallback
A BoringLayout is a very simple Layout implementation for text that
fits on a single line and is all left-to-right characters.
You will probably never want to make one of these yourself;
if you do, be sure to call
isBoring(java.lang.CharSequence, icyllis.modernui.text.TextPaint) first to make sure
the text meets the criteria.
This class is used by widgets to control text layout. You should not need to use this class directly unless you are implementing your own widget or custom display object, in which case you are encouraged to use a Layout.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class icyllis.modernui.text.Layout
Layout.Alignment -
Field Summary
Fields inherited from class icyllis.modernui.text.Layout
DIR_LEFT_TO_RIGHT, DIR_RIGHT_TO_LEFT, TAB_INCREMENT -
Constructor Summary
ConstructorsConstructorDescriptionBoringLayout(CharSequence source, TextPaint paint, int outerWidth, Layout.Alignment align, float spacingMult, float spacingAdd, BoringLayout.Metrics metrics, boolean includePad) BoringLayout(CharSequence source, TextPaint paint, int outerWidth, Layout.Alignment align, float spacingMult, float spacingAdd, BoringLayout.Metrics metrics, boolean includePad, TextUtils.TruncateAt ellipsize, int ellipsizedWidth) -
Method Summary
Modifier and TypeMethodDescriptionvoidDraw all visible text lines of this Layout on the specified canvas.voidellipsized(int start, int end) Callback for the ellipsizer to report what region it ellipsized.intReturns the number of extra pixels of descent padding in the bottom line of the Layout.intgetEllipsisCount(int line) Returns the number of characters to be ellipsized away, or 0 if no ellipsis is to take place.intgetEllipsisStart(int line) Return the offset of the first character to be ellipsized away, relative to the start of the line.intReturn the width to which this Layout is ellipsizing, orLayout.getWidth()if it is not doing anything special.intReturn the total height of this layout.booleangetLineContainsTab(int line) Returns whether the specified line contains one or more characters that need to be handled specially, like tabs.intReturn the number of lines of text in this layout.intgetLineDescent(int line) Return the descent of the specified line(0…getLineCount() - 1).final DirectionsgetLineDirections(int line) Returns the directional run information for the specified line.floatgetLineMax(int line) Gets the unsigned horizontal extent of the specified line, including leading margin indent, but excluding trailing whitespace.intgetLineStart(int line) Return the text offset of the beginning of the specified line ( 0…getLineCount()).intgetLineTop(int line) Return the vertical position of the top of the specified line (0…getLineCount()).floatgetLineWidth(int line) Gets the unsigned horizontal extent of the specified line, including leading margin indent and trailing whitespace.intgetParagraphDirection(int line) Returns the primary directionality of the paragraph containing the specified line, either 1 for left-to-right lines, or -1 for right-to-left lines (seeLayout.DIR_LEFT_TO_RIGHT,Layout.DIR_RIGHT_TO_LEFT).intReturns the (negative) number of extra pixels of ascent padding in the top line of the Layout.static BoringLayout.MetricsisBoring(CharSequence text, TextPaint paint) Determine and compute metrics if given text can be handled by BoringLayout.static BoringLayout.MetricsisBoring(CharSequence text, TextPaint paint, BoringLayout.Metrics metrics) Determine and compute metrics if given text can be handled by BoringLayout.static BoringLayout.MetricsisBoring(CharSequence text, TextPaint paint, TextDirectionHeuristic textDir, BoringLayout.Metrics metrics) Returns null if not boring; the width, ascent, and descent in the provided Metrics object (or a new one if the provided one was null) if boring.static BoringLayoutmake(CharSequence source, TextPaint paint, int outerWidth, Layout.Alignment align, float spacingMult, float spacingAdd, BoringLayout.Metrics metrics, boolean includePad) Utility function to construct a BoringLayout instance.static BoringLayoutmake(CharSequence source, TextPaint paint, int outerWidth, Layout.Alignment align, float spacingMult, float spacingAdd, BoringLayout.Metrics metrics, boolean includePad, TextUtils.TruncateAt ellipsize, int ellipsizedWidth) Utility function to construct a BoringLayout instance.replaceOrMake(CharSequence source, TextPaint paint, int outerWidth, Layout.Alignment align, float spacingMult, float spacingAdd, BoringLayout.Metrics metrics, boolean includePad) Returns a BoringLayout for the specified text, potentially reusing this one if it is already suitable.replaceOrMake(CharSequence source, TextPaint paint, int outerWidth, Layout.Alignment align, BoringLayout.Metrics metrics, boolean includePad, TextUtils.TruncateAt ellipsize, int ellipsizedWidth) Returns a BoringLayout for the specified text, potentially reusing this one if it is already suitable.Methods inherited from class icyllis.modernui.text.Layout
draw, drawBackground, getAlignment, getCursorPath, getDesiredWidth, getDesiredWidth, getHeight, getIndentAdjust, getLineAscent, getLineBaseline, getLineBottom, getLineBottom, getLineBounds, getLineEnd, getLineForOffset, getLineForVertical, getLineLeft, getLineRangeForDraw, getLineRight, getLineVisibleEnd, getOffsetForHorizontal, getOffsetToLeftOf, getOffsetToRightOf, getPaint, getParagraphAlignment, getParagraphLeft, getParagraphRight, getPrimaryHorizontal, getSecondaryHorizontal, getSelectionPath, getSpacingAdd, getSpacingMultiplier, getText, getTextDirectionHeuristic, getWidth, increaseWidthTo, isRtlCharAt
-
Constructor Details
-
BoringLayout
public BoringLayout(CharSequence source, TextPaint paint, int outerWidth, Layout.Alignment align, float spacingMult, float spacingAdd, BoringLayout.Metrics metrics, boolean includePad) - Parameters:
source- the text to renderpaint- the default paint for the layoutouterWidth- the wrapping width for the textalign- whether to left, right, or center the textmetrics-#Metricsinstance that contains information about FontMetrics and line widthincludePad- set whether to include extra space beyond font ascent and descent which is needed to avoid clipping in some scripts
-
BoringLayout
public BoringLayout(CharSequence source, TextPaint paint, int outerWidth, Layout.Alignment align, float spacingMult, float spacingAdd, BoringLayout.Metrics metrics, boolean includePad, TextUtils.TruncateAt ellipsize, int ellipsizedWidth) - Parameters:
source- the text to renderpaint- the default paint for the layoutouterWidth- the wrapping width for the textalign- whether to left, right, or center the textmetrics-#Metricsinstance that contains information about FontMetrics and line widthincludePad- set whether to include extra space beyond font ascent and descent which is needed to avoid clipping in some scriptsellipsize- whether to ellipsize the text if width of the text is longer than the requestedouterwidthellipsizedWidth- the width to which this Layout is ellipsizing. Ifellipsizeisnull, or isTextUtils.TruncateAt.MARQUEEthis value is not used,outerwidthis used instead
-
-
Method Details
-
make
public static BoringLayout make(CharSequence source, TextPaint paint, int outerWidth, Layout.Alignment align, float spacingMult, float spacingAdd, BoringLayout.Metrics metrics, boolean includePad) Utility function to construct a BoringLayout instance.- Parameters:
source- the text to renderpaint- the default paint for the layoutouterWidth- the wrapping width for the textalign- whether to left, right, or center the textmetrics-#Metricsinstance that contains information about FontMetrics and line widthincludePad- set whether to include extra space beyond font ascent and descent which is needed to avoid clipping in some scripts
-
make
public static BoringLayout make(CharSequence source, TextPaint paint, int outerWidth, Layout.Alignment align, float spacingMult, float spacingAdd, BoringLayout.Metrics metrics, boolean includePad, TextUtils.TruncateAt ellipsize, int ellipsizedWidth) Utility function to construct a BoringLayout instance.- Parameters:
source- the text to renderpaint- the default paint for the layoutouterWidth- the wrapping width for the textalign- whether to left, right, or center the textmetrics-#Metricsinstance that contains information about FontMetrics and line widthincludePad- set whether to include extra space beyond font ascent and descent which is needed to avoid clipping in some scriptsellipsize- whether to ellipsize the text if width of the text is longer than the requested widthellipsizedWidth- the width to which this Layout is ellipsizing. Ifellipsizeisnull, or isTextUtils.TruncateAt.MARQUEEthis value is not used,outerWidthis used instead
-
replaceOrMake
public BoringLayout replaceOrMake(CharSequence source, TextPaint paint, int outerWidth, Layout.Alignment align, float spacingMult, float spacingAdd, BoringLayout.Metrics metrics, boolean includePad) Returns a BoringLayout for the specified text, potentially reusing this one if it is already suitable. The caller must make sure that no one is still using this Layout.- Parameters:
source- the text to renderpaint- the default paint for the layoutouterWidth- the wrapping width for the textalign- whether to left, right, or center the textmetrics-#Metricsinstance that contains information about FontMetrics and line widthincludePad- set whether to include extra space beyond font ascent and descent which is needed to avoid clipping in some scripts
-
replaceOrMake
@NonNull public BoringLayout replaceOrMake(@NonNull CharSequence source, @NonNull TextPaint paint, @IntRange(from=0L) int outerWidth, @NonNull Layout.Alignment align, @NonNull BoringLayout.Metrics metrics, boolean includePad, @Nullable TextUtils.TruncateAt ellipsize, @IntRange(from=0L) int ellipsizedWidth) Returns a BoringLayout for the specified text, potentially reusing this one if it is already suitable. The caller must make sure that no one is still using this Layout. The spacing multiplier and additional amount spacing are not used by BoringLayout.Layout.getSpacingMultiplier()will return 1.0 andLayout.getSpacingAdd()will return 0.0.- Parameters:
source- the text to renderpaint- the default paint for the layoutouterWidth- the wrapping width for the textalign- whether to left, right, or center the textmetrics-#Metricsinstance that contains information about FontMetrics and line widthincludePad- set whether to include extra space beyond font ascent and descent which is needed to avoid clipping in some scriptsellipsize- whether to ellipsize the text if width of the text is longer than the requested width. null if ellipsis not applied.ellipsizedWidth- the width to which this Layout is ellipsizing. Ifellipsizeisnull, or isTextUtils.TruncateAt.MARQUEEthis value is not used,outerWidthis used instead
-
isBoring
Determine and compute metrics if given text can be handled by BoringLayout.- Parameters:
text- a textpaint- a paint- Returns:
- layout metric for the given text. null if given text is unable to be handled by BoringLayout.
-
isBoring
public static BoringLayout.Metrics isBoring(CharSequence text, TextPaint paint, BoringLayout.Metrics metrics) Determine and compute metrics if given text can be handled by BoringLayout.- Parameters:
text- a textpaint- a paintmetrics- a metrics object to be recycled. If null is passed, this function creat new object.- Returns:
- layout metric for the given text. If metrics is not null, this method fills values to given metrics object instead of allocating new metrics object. null if given text is unable to be handled by BoringLayout.
-
isBoring
@Nullable public static BoringLayout.Metrics isBoring(@Nonnull CharSequence text, TextPaint paint, TextDirectionHeuristic textDir, BoringLayout.Metrics metrics) Returns null if not boring; the width, ascent, and descent in the provided Metrics object (or a new one if the provided one was null) if boring. -
getHeight
public int getHeight()Description copied from class:LayoutReturn the total height of this layout. -
getLineCount
public int getLineCount()Description copied from class:LayoutReturn the number of lines of text in this layout.- Specified by:
getLineCountin classLayout
-
getLineTop
public int getLineTop(int line) Description copied from class:LayoutReturn the vertical position of the top of the specified line (0…getLineCount()). If the specified line is equal to the line count, returns the bottom of the last line.- Specified by:
getLineTopin classLayout
-
getLineDescent
public int getLineDescent(int line) Description copied from class:LayoutReturn the descent of the specified line(0…getLineCount() - 1).- Specified by:
getLineDescentin classLayout
-
getLineStart
public int getLineStart(int line) Description copied from class:LayoutReturn the text offset of the beginning of the specified line ( 0…getLineCount()). If the specified line is equal to the line count, returns the length of the text.- Specified by:
getLineStartin classLayout
-
getParagraphDirection
public int getParagraphDirection(int line) Description copied from class:LayoutReturns the primary directionality of the paragraph containing the specified line, either 1 for left-to-right lines, or -1 for right-to-left lines (seeLayout.DIR_LEFT_TO_RIGHT,Layout.DIR_RIGHT_TO_LEFT).- Specified by:
getParagraphDirectionin classLayout
-
getLineContainsTab
public boolean getLineContainsTab(int line) Description copied from class:LayoutReturns whether the specified line contains one or more characters that need to be handled specially, like tabs.- Specified by:
getLineContainsTabin classLayout
-
getLineMax
public float getLineMax(int line) Description copied from class:LayoutGets the unsigned horizontal extent of the specified line, including leading margin indent, but excluding trailing whitespace.- Overrides:
getLineMaxin classLayout
-
getLineWidth
public float getLineWidth(int line) Description copied from class:LayoutGets the unsigned horizontal extent of the specified line, including leading margin indent and trailing whitespace.- Overrides:
getLineWidthin classLayout
-
getLineDirections
Description copied from class:LayoutReturns the directional run information for the specified line. The array alternates counts of characters in left-to-right and right-to-left segments of the line.NOTE: this is inadequate to support bidirectional text, and will change.
- Specified by:
getLineDirectionsin classLayout
-
getTopPadding
public int getTopPadding()Description copied from class:LayoutReturns the (negative) number of extra pixels of ascent padding in the top line of the Layout.- Specified by:
getTopPaddingin classLayout
-
getBottomPadding
public int getBottomPadding()Description copied from class:LayoutReturns the number of extra pixels of descent padding in the bottom line of the Layout.- Specified by:
getBottomPaddingin classLayout
-
getEllipsisCount
public int getEllipsisCount(int line) Description copied from class:LayoutReturns the number of characters to be ellipsized away, or 0 if no ellipsis is to take place.- Specified by:
getEllipsisCountin classLayout
-
getEllipsisStart
public int getEllipsisStart(int line) Description copied from class:LayoutReturn the offset of the first character to be ellipsized away, relative to the start of the line. (So 0 if the beginning of the line is ellipsized, not getLineStart().)- Specified by:
getEllipsisStartin classLayout
-
getEllipsizedWidth
public int getEllipsizedWidth()Description copied from class:LayoutReturn the width to which this Layout is ellipsizing, orLayout.getWidth()if it is not doing anything special.- Overrides:
getEllipsizedWidthin classLayout
-
drawText
Description copied from class:LayoutDraw all visible text lines of this Layout on the specified canvas.Significantly, visible area given by
firstLineandlastLineis computed byLayout.getLineRangeForDraw(Canvas). You may never just call this method without that method. -
ellipsized
public void ellipsized(int start, int end) Callback for the ellipsizer to report what region it ellipsized.- Specified by:
ellipsizedin interfaceTextUtils.EllipsizeCallback
-