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 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
ConstructorDescriptionBoringLayout
(CharSequence source, TextPaint paint, int outerWidth, Layout.Alignment align, BoringLayout.Metrics metrics, boolean includePad) BoringLayout
(CharSequence source, TextPaint paint, int outerWidth, Layout.Alignment align, BoringLayout.Metrics metrics, boolean includePad, TextUtils.TruncateAt ellipsize, int ellipsizedWidth) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Draw all visible text lines of this Layout on the specified canvas.void
ellipsized
(int start, int end) Callback for the ellipsizer to report what region it ellipsized.int
Returns the number of extra pixels of descent padding in the bottom line of the Layout.int
getEllipsisCount
(int line) Returns the number of characters to be ellipsized away, or 0 if no ellipsis is to take place.int
getEllipsisStart
(int line) Return the offset of the first character to be ellipsized away, relative to the start of the line.int
Return the width to which this Layout is ellipsizing, orLayout.getWidth()
if it is not doing anything special.int
Return the total height of this layout.boolean
getLineContainsTab
(int line) Returns whether the specified line contains one or more characters that need to be handled specially, like tabs.int
Return the number of lines of text in this layout.int
getLineDescent
(int line) Return the descent of the specified line(0…getLineCount() - 1).final Directions
getLineDirections
(int line) Returns the directional run information for the specified line.float
getLineMax
(int line) Gets the unsigned horizontal extent of the specified line, including leading margin indent, but excluding trailing whitespace.int
getLineStart
(int line) Return the text offset of the beginning of the specified line ( 0…getLineCount()).int
getLineTop
(int line) Return the vertical position of the top of the specified line (0…getLineCount()).float
getLineWidth
(int line) Gets the unsigned horizontal extent of the specified line, including leading margin indent and trailing whitespace.int
getParagraphDirection
(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
).int
Returns the (negative) number of extra pixels of ascent padding in the top line of the Layout.static BoringLayout.Metrics
isBoring
(CharSequence text, TextPaint paint) Determine and compute metrics if given text can be handled by BoringLayout.static BoringLayout.Metrics
isBoring
(CharSequence text, TextPaint paint, BoringLayout.Metrics metrics) Determine and compute metrics if given text can be handled by BoringLayout.static BoringLayout.Metrics
isBoring
(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 BoringLayout
make
(CharSequence source, TextPaint paint, int outerWidth, Layout.Alignment align, BoringLayout.Metrics metrics, boolean includePad) Utility function to construct a BoringLayout instance.static BoringLayout
make
(CharSequence source, TextPaint paint, int outerWidth, Layout.Alignment align, 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, 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, getDesiredWidth, getDesiredWidthWithLimit, getHeight, getIndentAdjust, getLineAscent, getLineBaseline, getLineBottom, getLineBounds, getLineEnd, getLineForOffset, getLineForVertical, getLineLeft, getLineRangeForDraw, getLineRight, getLineVisibleEnd, getOffsetForHorizontal, getOffsetForHorizontal, getOffsetToLeftOf, getOffsetToRightOf, getPaint, getParagraphAlignment, getParagraphLeft, getParagraphRight, getPrimaryHorizontal, getPrimaryHorizontal, getSecondaryHorizontal, getSecondaryHorizontal, getSelectionPath, getText, getTextDirectionHeuristic, getWidth, increaseWidthTo, isLevelBoundary, isRtlCharAt, primaryIsTrailingPrevious, primaryIsTrailingPreviousAllLineOffsets
-
Constructor Details
-
BoringLayout
public BoringLayout(CharSequence source, TextPaint paint, int outerWidth, Layout.Alignment align, 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
-#Metrics
instance 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, 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
-#Metrics
instance 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 requestedouterwidth
ellipsizedWidth
- the width to which this Layout is ellipsizing. Ifellipsize
isnull
, or isTextUtils.TruncateAt.MARQUEE
this value is not used,outerwidth
is used instead
-
-
Method Details
-
make
public static BoringLayout make(CharSequence source, TextPaint paint, int outerWidth, Layout.Alignment align, 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
-#Metrics
instance 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, 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
-#Metrics
instance 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. Ifellipsize
isnull
, or isTextUtils.TruncateAt.MARQUEE
this value is not used,outerWidth
is used instead
-
replaceOrMake
public BoringLayout replaceOrMake(CharSequence source, TextPaint paint, int outerWidth, Layout.Alignment align, 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
-#Metrics
instance 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
public BoringLayout 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. 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
-#Metrics
instance 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. Ifellipsize
isnull
, or isTextUtils.TruncateAt.MARQUEE
this value is not used,outerwidth
is 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:Layout
Return the total height of this layout. -
getLineCount
public int getLineCount()Description copied from class:Layout
Return the number of lines of text in this layout.- Specified by:
getLineCount
in classLayout
-
getLineTop
public int getLineTop(int line) Description copied from class:Layout
Return 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:
getLineTop
in classLayout
-
getLineDescent
public int getLineDescent(int line) Description copied from class:Layout
Return the descent of the specified line(0…getLineCount() - 1).- Specified by:
getLineDescent
in classLayout
-
getLineStart
public int getLineStart(int line) Description copied from class:Layout
Return 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:
getLineStart
in classLayout
-
getParagraphDirection
public int getParagraphDirection(int line) Description copied from class:Layout
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
).- Specified by:
getParagraphDirection
in classLayout
-
getLineContainsTab
public boolean getLineContainsTab(int line) Description copied from class:Layout
Returns whether the specified line contains one or more characters that need to be handled specially, like tabs.- Specified by:
getLineContainsTab
in classLayout
-
getLineMax
public float getLineMax(int line) Description copied from class:Layout
Gets the unsigned horizontal extent of the specified line, including leading margin indent, but excluding trailing whitespace.- Overrides:
getLineMax
in classLayout
-
getLineWidth
public float getLineWidth(int line) Description copied from class:Layout
Gets the unsigned horizontal extent of the specified line, including leading margin indent and trailing whitespace.- Overrides:
getLineWidth
in classLayout
-
getLineDirections
Description copied from class:Layout
Returns 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:
getLineDirections
in classLayout
-
getTopPadding
public int getTopPadding()Description copied from class:Layout
Returns the (negative) number of extra pixels of ascent padding in the top line of the Layout.- Specified by:
getTopPadding
in classLayout
-
getBottomPadding
public int getBottomPadding()Description copied from class:Layout
Returns the number of extra pixels of descent padding in the bottom line of the Layout.- Specified by:
getBottomPadding
in classLayout
-
getEllipsisCount
public int getEllipsisCount(int line) Description copied from class:Layout
Returns the number of characters to be ellipsized away, or 0 if no ellipsis is to take place.- Specified by:
getEllipsisCount
in classLayout
-
getEllipsisStart
public int getEllipsisStart(int line) Description copied from class:Layout
Return 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:
getEllipsisStart
in classLayout
-
getEllipsizedWidth
public int getEllipsizedWidth()Description copied from class:Layout
Return the width to which this Layout is ellipsizing, orLayout.getWidth()
if it is not doing anything special.- Overrides:
getEllipsizedWidth
in classLayout
-
drawText
Description copied from class:Layout
Draw all visible text lines of this Layout on the specified canvas.Significantly, visible area given by
firstLine
andlastLine
is 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:
ellipsized
in interfaceTextUtils.EllipsizeCallback
-