-
- All Implemented Interfaces:
-
com.patrykandpatrick.vico.core.component.dimension.Margins,com.patrykandpatrick.vico.core.component.dimension.Padding
public class TextComponent implements Padding, Margins
Uses Canvas to render text. This class utilizes StaticLayout and supports the following:
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classTextComponent.BuilderThe builder for TextComponent.
-
Field Summary
Fields Modifier and Type Field Description private Integercolorprivate Typefacetypefaceprivate FloattextSizeSpprivate TextUtils.TruncateAtellipsizeprivate IntegerlineCountprivate Componentbackgroundprivate Paint.AligntextAlignprivate MutableDimensionspaddingprivate MutableDimensionsmargins
-
Method Summary
Modifier and Type Method Description final IntegergetColor()The text’s color. final UnitsetColor(Integer color)The text’s color. final TypefacegetTypeface()The Typeface for the text. final UnitsetTypeface(Typeface typeface)The Typeface for the text. final FloatgetTextSizeSp()The font size (in sp). final UnitsetTextSizeSp(Float textSizeSp)The font size (in sp). final TextUtils.TruncateAtgetEllipsize()The type of text truncation to be used when the text’s width exceeds the amount of available space. final UnitsetEllipsize(TextUtils.TruncateAt ellipsize)The type of text truncation to be used when the text’s width exceeds the amount of available space. final IntegergetLineCount()The maximum number of lines for the text. final UnitsetLineCount(Integer lineCount)The maximum number of lines for the text. final ComponentgetBackground()The text’s background. final UnitsetBackground(Component background)The text’s background. final Paint.AligngetTextAlign()The text alignment. final UnitsetTextAlign(Paint.Align textAlign)The text alignment. MutableDimensionsgetPadding()The padding between the text and the background. UnitsetPadding(MutableDimensions padding)The padding between the text and the background. MutableDimensionsgetMargins()The margins around the background. UnitsetMargins(MutableDimensions margins)The margins around the background. final UnitdrawText(DrawContext context, CharSequence text, Float textX, Float textY, HorizontalPosition horizontalPosition, VerticalPosition verticalPosition, Integer maxTextWidth, Integer maxTextHeight, Float rotationDegrees)Uses Canvas to draw this TextComponent. final FloatgetWidth(MeasureContext context, CharSequence text, Integer width, Integer height, Float rotationDegrees)Returns the width of this TextComponent for the given text and the available width and height. final FloatgetHeight(MeasureContext context, CharSequence text, Integer width, Integer height, Float rotationDegrees)Returns the height of this TextComponent for the given text and the available width and height. final RectFgetTextBounds(MeasureContext context, CharSequence text, Integer width, Integer height, RectF outRect, Boolean includePaddingAndMargins, Float rotationDegrees)Returns the bounds (RectF) of this TextComponent for the given text and the available width and height. -
-
Method Detail
-
getTypeface
final Typeface getTypeface()
The Typeface for the text.
-
setTypeface
final Unit setTypeface(Typeface typeface)
The Typeface for the text.
-
getTextSizeSp
final Float getTextSizeSp()
The font size (in sp).
-
setTextSizeSp
final Unit setTextSizeSp(Float textSizeSp)
The font size (in sp).
-
getEllipsize
final TextUtils.TruncateAt getEllipsize()
The type of text truncation to be used when the text’s width exceeds the amount of available space. By default, text is truncated at the end, and an ellipsis (…) is used.
-
setEllipsize
final Unit setEllipsize(TextUtils.TruncateAt ellipsize)
The type of text truncation to be used when the text’s width exceeds the amount of available space. By default, text is truncated at the end, and an ellipsis (…) is used.
-
getLineCount
final Integer getLineCount()
The maximum number of lines for the text. For performance reasons, during the measurement phase, it is presumed that the actual number of lines is equal to this value.
-
setLineCount
final Unit setLineCount(Integer lineCount)
The maximum number of lines for the text. For performance reasons, during the measurement phase, it is presumed that the actual number of lines is equal to this value.
-
getBackground
final Component getBackground()
The text’s background. Use padding to set the padding between the text and the background.
-
setBackground
final Unit setBackground(Component background)
The text’s background. Use padding to set the padding between the text and the background.
-
getTextAlign
final Paint.Align getTextAlign()
The text alignment.
-
setTextAlign
final Unit setTextAlign(Paint.Align textAlign)
The text alignment.
-
getPadding
MutableDimensions getPadding()
The padding between the text and the background. This is applied even if background is null.
-
setPadding
Unit setPadding(MutableDimensions padding)
The padding between the text and the background. This is applied even if background is null.
-
getMargins
MutableDimensions getMargins()
The margins around the background. This is applied even if background is null.
-
setMargins
Unit setMargins(MutableDimensions margins)
The margins around the background. This is applied even if background is null.
-
drawText
final Unit drawText(DrawContext context, CharSequence text, Float textX, Float textY, HorizontalPosition horizontalPosition, VerticalPosition verticalPosition, Integer maxTextWidth, Integer maxTextHeight, Float rotationDegrees)
Uses Canvas to draw this TextComponent.
- Parameters:
context- holds environment data.text- the text to be drawn.textX- the x coordinate for the text.textY- the y coordinate for the text.horizontalPosition- the horizontal position of the text, relative to textX.verticalPosition- the vertical position of the text, relative to textY.maxTextWidth- the maximum width available for the text (in pixels).maxTextHeight- the maximum height available for the text (in pixels).rotationDegrees- the rotation of the text (in degrees).
-
getWidth
final Float getWidth(MeasureContext context, CharSequence text, Integer width, Integer height, Float rotationDegrees)
Returns the width of this TextComponent for the given text and the available width and height.
-
getHeight
final Float getHeight(MeasureContext context, CharSequence text, Integer width, Integer height, Float rotationDegrees)
Returns the height of this TextComponent for the given text and the available width and height.
-
getTextBounds
final RectF getTextBounds(MeasureContext context, CharSequence text, Integer width, Integer height, RectF outRect, Boolean includePaddingAndMargins, Float rotationDegrees)
Returns the bounds (RectF) of this TextComponent for the given text and the available width and height.
-
-
-
-