Merge "Hide TextPainter and rename it to TextDelegate" into androidx-master-dev
diff --git a/ui/ui-framework/src/main/java/androidx/ui/core/Text.kt b/ui/ui-framework/src/main/java/androidx/ui/core/Text.kt
index eaf59ee..19f63ae 100644
--- a/ui/ui-framework/src/main/java/androidx/ui/core/Text.kt
+++ b/ui/ui-framework/src/main/java/androidx/ui/core/Text.kt
@@ -38,7 +38,7 @@
import androidx.ui.semantics.Semantics
import androidx.ui.semantics.accessibilityLabel
import androidx.ui.text.TextSelection
-import androidx.ui.text.TextPainter
+import androidx.ui.text.TextDelegate
import androidx.ui.text.TextSpan
import androidx.ui.text.TextStyle
import androidx.ui.text.style.TextAlign
@@ -214,7 +214,7 @@
maxLines,
density
) {
- TextPainter(
+ TextDelegate(
text = text,
style = mergedStyle,
paragraphStyle = paragraphStyle,
@@ -247,8 +247,8 @@
minIntrinsicWidth { _, _ ->
// TODO(popam): discuss with the Text team about this
throw UnsupportedOperationException()
- // textPainter.layout(Constraints(0.ipx, IntPx.Infinity, 0.ipx, h))
- // textPainter.minIntrinsicWidth.px.round()
+ // textDelegate.layout(Constraints(0.ipx, IntPx.Infinity, 0.ipx, h))
+ // textDelegate.minIntrinsicWidth.px.round()
}
minIntrinsicHeight { _, w ->
textPainter.layout(Constraints(0.ipx, w, 0.ipx, IntPx.Infinity))
@@ -290,7 +290,7 @@
selectionCoordinates = Pair(startPx, endPx),
mode = mode,
onSelectionChange = { internalSelection.value = it },
- textPainter = textPainter
+ textDelegate = textPainter
)
if (!textSelectionProcessor.isSelected) return null
diff --git a/ui/ui-framework/src/main/java/androidx/ui/core/TextField.kt b/ui/ui-framework/src/main/java/androidx/ui/core/TextField.kt
index 8efe4e7..4871240 100644
--- a/ui/ui-framework/src/main/java/androidx/ui/core/TextField.kt
+++ b/ui/ui-framework/src/main/java/androidx/ui/core/TextField.kt
@@ -31,7 +31,7 @@
import androidx.ui.input.EditorModel
import androidx.ui.input.ImeAction
import androidx.ui.input.KeyboardType
-import androidx.ui.text.TextPainter
+import androidx.ui.text.TextDelegate
import androidx.ui.text.TextStyle
/**
@@ -126,7 +126,7 @@
}
val textPainter = +memo(visualText, mergedStyle, density, resourceLoader) {
// TODO(nona): Add parameter for text direction, softwrap, etc.
- TextPainter(
+ TextDelegate(
text = visualText,
style = mergedStyle,
density = density,
diff --git a/ui/ui-framework/src/main/java/androidx/ui/core/TextFieldDelegate.kt b/ui/ui-framework/src/main/java/androidx/ui/core/TextFieldDelegate.kt
index 9d66efa..7ba4396 100644
--- a/ui/ui-framework/src/main/java/androidx/ui/core/TextFieldDelegate.kt
+++ b/ui/ui-framework/src/main/java/androidx/ui/core/TextFieldDelegate.kt
@@ -28,39 +28,39 @@
import androidx.ui.input.TextInputService
import androidx.ui.painting.Canvas
import androidx.ui.text.AnnotatedString
-import androidx.ui.text.TextPainter
+import androidx.ui.text.TextDelegate
internal class TextFieldDelegate {
companion object {
/**
* Process text layout with given constraint.
*
- * @param textPainter The text painter
+ * @param textDelegate The text painter
* @param constraints The layout constraints
* @return the bounding box size(width and height) of the layout result
*/
@JvmStatic
- fun layout(textPainter: TextPainter, constraints: Constraints): Pair<IntPx, IntPx> {
- val isEmptyText = textPainter.text?.text?.isEmpty() ?: true
+ fun layout(textDelegate: TextDelegate, constraints: Constraints): Pair<IntPx, IntPx> {
+ val isEmptyText = textDelegate.text?.text?.isEmpty() ?: true
val activeTextPainter = if (isEmptyText) {
// Even with empty text, edit filed must have at least non-zero height widget. Use
// "H" height for this empty text height.
- TextPainter(
+ TextDelegate(
text = AnnotatedString(text = "H"),
- style = textPainter.style,
- density = textPainter.density,
- resourceLoader = textPainter.resourceLoader
+ style = textDelegate.style,
+ density = textDelegate.density,
+ resourceLoader = textDelegate.resourceLoader
).apply {
layout(constraints)
}
} else {
- textPainter
+ textDelegate
}
// We anyway need to compute layout for preventing NPE during draw which require layout
// result.
// TODO(nona): Fix this?
- textPainter.layout(constraints)
+ textDelegate.layout(constraints)
val height = activeTextPainter.height.px.round()
val width = constraints.maxWidth
@@ -73,7 +73,7 @@
* @param canvas The target canvas.
* @param value The editor state
* @param offsetMap The offset map
- * @param textPainter The text painter
+ * @param textDelegate The text painter
* @param hasFocus true if this widget is focused, otherwise false
* @param editorStyle The editor style.
*/
@@ -82,12 +82,12 @@
canvas: Canvas,
value: EditorModel,
offsetMap: OffsetMap,
- textPainter: TextPainter,
+ textDelegate: TextDelegate,
hasFocus: Boolean,
editorStyle: EditorStyle
) {
value.composition?.let {
- textPainter.paintBackground(
+ textDelegate.paintBackground(
offsetMap.originalToTransformed(it.start),
offsetMap.originalToTransformed(it.end),
editorStyle.compositionColor,
@@ -96,18 +96,18 @@
}
if (value.selection.collapsed) {
if (hasFocus) {
- textPainter.paintCursor(
+ textDelegate.paintCursor(
offsetMap.originalToTransformed(value.selection.start), canvas)
}
} else {
- textPainter.paintBackground(
+ textDelegate.paintBackground(
offsetMap.originalToTransformed(value.selection.start),
offsetMap.originalToTransformed(value.selection.end),
editorStyle.selectionColor,
canvas
)
}
- textPainter.paint(canvas)
+ textDelegate.paint(canvas)
}
/**
@@ -118,7 +118,7 @@
@JvmStatic
fun notifyFocusedRect(
value: EditorModel,
- textPainter: TextPainter,
+ textDelegate: TextDelegate,
layoutCoordinates: LayoutCoordinates,
textInputService: TextInputService,
hasFocus: Boolean,
@@ -129,11 +129,12 @@
}
val bbox = if (value.selection.end < value.text.length) {
- textPainter.getBoundingBox(offsetMap.originalToTransformed(value.selection.end))
+ textDelegate.getBoundingBox(offsetMap.originalToTransformed(value.selection.end))
} else if (value.selection.end != 0) {
- textPainter.getBoundingBox(offsetMap.originalToTransformed(value.selection.end) - 1)
+ textDelegate.getBoundingBox(
+ offsetMap.originalToTransformed(value.selection.end) - 1)
} else {
- Rect(0f, 0f, 1.0f, textPainter.preferredLineHeight)
+ Rect(0f, 0f, 1.0f, textDelegate.preferredLineHeight)
}
val globalLT = layoutCoordinates.localToRoot(PxPosition(bbox.left.px, bbox.top.px))
@@ -178,7 +179,7 @@
* Called when onRelease event is fired.
*
* @param position The event position in widget coordinate.
- * @param textPainter The text painter
+ * @param textDelegate The text painter
* @param editProcessor The edit processor
* @param offsetMap The offset map
* @param onValueChange The callback called when the new editor state arrives.
@@ -188,7 +189,7 @@
@JvmStatic
fun onRelease(
position: PxPosition,
- textPainter: TextPainter,
+ textDelegate: TextDelegate,
editProcessor: EditProcessor,
offsetMap: OffsetMap,
onValueChange: (EditorModel) -> Unit,
@@ -198,7 +199,7 @@
textInputService?.showSoftwareKeyboard()
if (hasFocus) {
val offset = offsetMap.transformedToOriginal(
- textPainter.getOffsetForPosition(position))
+ textDelegate.getOffsetForPosition(position))
onEditCommand(
listOf(SetSelectionEditOp(offset, offset)),
editProcessor,
diff --git a/ui/ui-framework/src/main/java/androidx/ui/core/selection/SelectionMode.kt b/ui/ui-framework/src/main/java/androidx/ui/core/selection/SelectionMode.kt
index b405cb2..ba90523 100644
--- a/ui/ui-framework/src/main/java/androidx/ui/core/selection/SelectionMode.kt
+++ b/ui/ui-framework/src/main/java/androidx/ui/core/selection/SelectionMode.kt
@@ -18,7 +18,7 @@
import androidx.ui.core.PxPosition
import androidx.ui.core.px
-import androidx.ui.text.TextPainter
+import androidx.ui.text.TextDelegate
/**
* The enum class allows user to decide the selection mode.
@@ -31,14 +31,14 @@
*/
Vertical {
override fun isSelected(
- textPainter: TextPainter,
+ textDelegate: TextDelegate,
start: PxPosition,
end: PxPosition
): Boolean {
val top = 0.px
- val bottom = textPainter.height.px
+ val bottom = textDelegate.height.px
val left = 0.px
- val right = textPainter.width.px
+ val right = textDelegate.width.px
// When the end of the selection is above the top of the widget, the widget is outside
// of the selection range.
@@ -67,14 +67,14 @@
*/
Horizontal {
override fun isSelected(
- textPainter: TextPainter,
+ textDelegate: TextDelegate,
start: PxPosition,
end: PxPosition
): Boolean {
val top = 0.px
- val bottom = textPainter.height.px
+ val bottom = textDelegate.height.px
val left = 0.px
- val right = textPainter.width.px
+ val right = textDelegate.width.px
// When the end of the selection is on the left of the widget, the widget is outside of
// the selection range.
@@ -97,7 +97,7 @@
};
internal abstract fun isSelected(
- textPainter: TextPainter,
+ textDelegate: TextDelegate,
start: PxPosition,
end: PxPosition
): Boolean
diff --git a/ui/ui-framework/src/main/java/androidx/ui/core/selection/TextSelectionProcessor.kt b/ui/ui-framework/src/main/java/androidx/ui/core/selection/TextSelectionProcessor.kt
index 23419ed..6fa8887 100644
--- a/ui/ui-framework/src/main/java/androidx/ui/core/selection/TextSelectionProcessor.kt
+++ b/ui/ui-framework/src/main/java/androidx/ui/core/selection/TextSelectionProcessor.kt
@@ -19,7 +19,7 @@
import androidx.ui.core.PxPosition
import androidx.ui.core.px
import androidx.ui.text.TextSelection
-import androidx.ui.text.TextPainter
+import androidx.ui.text.TextDelegate
import kotlin.math.max
/**
@@ -34,8 +34,8 @@
/** The lambda contains certain behavior when selection changes. Currently this is for changing
* the selection used for drawing in Text widget. */
var onSelectionChange: (TextSelection?) -> Unit = {},
- /** The TextPainter object from Text widget. */
- val textPainter: TextPainter
+ /** The TextDelegate object from Text widget. */
+ val textDelegate: TextDelegate
) {
/**
* The coordinates of the graphical position for selection start character offset.
@@ -69,7 +69,7 @@
internal var isSelected = false
/** The length of the text in text widget. */
- private val length = textPainter.text?.let { it.text.length } ?: 0
+ private val length = textDelegate.text?.let { it.text.length } ?: 0
init {
processTextSelection()
@@ -82,19 +82,19 @@
val startPx = selectionCoordinates.first
val endPx = selectionCoordinates.second
- if (!mode.isSelected(textPainter, start = startPx, end = endPx)) {
+ if (!mode.isSelected(textDelegate, start = startPx, end = endPx)) {
onSelectionChange(null)
return
}
isSelected = true
var (textSelectionStart, containsWholeSelectionStart) =
- getSelectionBorder(textPainter, startPx, true)
+ getSelectionBorder(textDelegate, startPx, true)
var (textSelectionEnd, containsWholeSelectionEnd) =
- getSelectionBorder(textPainter, endPx, false)
+ getSelectionBorder(textDelegate, endPx, false)
if (textSelectionStart == textSelectionEnd) {
- val wordBoundary = textPainter.getWordBoundary(textSelectionStart)
+ val wordBoundary = textDelegate.getWordBoundary(textSelectionStart)
textSelectionStart = wordBoundary.start
textSelectionEnd = wordBoundary.end
}
@@ -113,7 +113,7 @@
* selection.
*/
private fun getSelectionBorder(
- textPainter: TextPainter,
+ textDelegate: TextDelegate,
// This position is in Text widget coordinate system.
position: PxPosition,
isStart: Boolean
@@ -127,9 +127,9 @@
var containsWholeSelectionBorder = false
val top = 0.px
- val bottom = textPainter.height.px
+ val bottom = textDelegate.height.px
val left = 0.px
- val right = textPainter.width.px
+ val right = textDelegate.width.px
// If the current text widget contains the whole selection's border, then find the exact
// character offset of the border, and the flag checking if the widget contains the whole
// selection's border will be set to true.
@@ -141,7 +141,7 @@
// Constrain the character offset of the selection border to be within the text range
// of the current widget.
val constrainedSelectionBorderOffset =
- textPainter.getOffsetForPosition(position).coerceIn(0, length - 1)
+ textDelegate.getOffsetForPosition(position).coerceIn(0, length - 1)
selectionBorder = constrainedSelectionBorderOffset
containsWholeSelectionBorder = true
}
@@ -149,10 +149,10 @@
}
private fun getSelectionHandleCoordinates(offset: Int): PxPosition {
- val left = textPainter.getPrimaryHorizontal(offset)
+ val left = textDelegate.getPrimaryHorizontal(offset)
- val line = textPainter.getLineForOffset(offset)
- val bottom = textPainter.getLineBottom(line)
+ val line = textDelegate.getLineForOffset(offset)
+ val bottom = textDelegate.getLineBottom(line)
return PxPosition(left.px, bottom.px)
}
diff --git a/ui/ui-framework/src/test/java/androidx/ui/core/TextFieldDelegateTest.kt b/ui/ui-framework/src/test/java/androidx/ui/core/TextFieldDelegateTest.kt
index 4657c23..7ef5b97 100644
--- a/ui/ui-framework/src/test/java/androidx/ui/core/TextFieldDelegateTest.kt
+++ b/ui/ui-framework/src/test/java/androidx/ui/core/TextFieldDelegateTest.kt
@@ -29,7 +29,7 @@
import androidx.ui.input.TextInputService
import androidx.ui.painting.Canvas
import androidx.ui.text.AnnotatedString
-import androidx.ui.text.TextPainter
+import androidx.ui.text.TextDelegate
import androidx.ui.text.TextRange
import androidx.ui.text.TextStyle
import com.nhaarman.mockitokotlin2.any
@@ -52,7 +52,7 @@
class TextFieldDelegateTest {
private lateinit var canvas: Canvas
- private lateinit var painter: TextPainter
+ private lateinit var mDelegate: TextDelegate
private lateinit var processor: EditProcessor
private lateinit var onValueChange: (EditorModel) -> Unit
private lateinit var onEditorActionPerformed: (Any) -> Unit
@@ -92,7 +92,7 @@
@Before
fun setup() {
- painter = mock()
+ mDelegate = mock()
canvas = mock()
processor = mock()
onValueChange = mock()
@@ -108,18 +108,18 @@
TextFieldDelegate.draw(
canvas = canvas,
- textPainter = painter,
+ textDelegate = mDelegate,
value = EditorModel(text = "Hello, World", selection = selection),
editorStyle = EditorStyle(selectionColor = selectionColor),
hasFocus = true,
offsetMap = identityOffsetMap
)
- verify(painter, times(1)).paintBackground(
+ verify(mDelegate, times(1)).paintBackground(
eq(selection.start), eq(selection.end), eq(selectionColor), eq(canvas))
- verify(painter, times(1)).paint(eq(canvas))
+ verify(mDelegate, times(1)).paint(eq(canvas))
- verify(painter, never()).paintCursor(any(), any())
+ verify(mDelegate, never()).paintCursor(any(), any())
}
@Test
@@ -128,16 +128,16 @@
TextFieldDelegate.draw(
canvas = canvas,
- textPainter = painter,
+ textDelegate = mDelegate,
value = EditorModel(text = "Hello, World", selection = cursor),
editorStyle = EditorStyle(),
hasFocus = true,
offsetMap = identityOffsetMap
)
- verify(painter, times(1)).paintCursor(eq(cursor.start), eq(canvas))
- verify(painter, times(1)).paint(eq(canvas))
- verify(painter, never()).paintBackground(any(), any(), any(), any())
+ verify(mDelegate, times(1)).paintCursor(eq(cursor.start), eq(canvas))
+ verify(mDelegate, times(1)).paint(eq(canvas))
+ verify(mDelegate, never()).paintBackground(any(), any(), any(), any())
}
@Test
@@ -146,16 +146,16 @@
TextFieldDelegate.draw(
canvas = canvas,
- textPainter = painter,
+ textDelegate = mDelegate,
value = EditorModel(text = "Hello, World", selection = cursor),
editorStyle = EditorStyle(),
hasFocus = false,
offsetMap = identityOffsetMap
)
- verify(painter, never()).paintCursor(any(), any())
- verify(painter, times(1)).paint(eq(canvas))
- verify(painter, never()).paintBackground(any(), any(), any(), any())
+ verify(mDelegate, never()).paintCursor(any(), any())
+ verify(mDelegate, times(1)).paint(eq(canvas))
+ verify(mDelegate, never()).paintBackground(any(), any(), any(), any())
}
@Test
@@ -167,7 +167,7 @@
TextFieldDelegate.draw(
canvas = canvas,
- textPainter = painter,
+ textDelegate = mDelegate,
value = EditorModel(text = "Hello, World", selection = cursor,
composition = composition),
editorStyle = EditorStyle(compositionColor = compositionColor),
@@ -175,10 +175,10 @@
offsetMap = identityOffsetMap
)
- verify(painter, times(1)).paintBackground(
+ verify(mDelegate, times(1)).paintBackground(
eq(composition.start), eq(composition.end), eq(compositionColor), eq(canvas))
- verify(painter, times(1)).paint(eq(canvas))
- verify(painter, times(1)).paintCursor(eq(cursor.start), any())
+ verify(mDelegate, times(1)).paint(eq(canvas))
+ verify(mDelegate, times(1)).paintCursor(eq(cursor.start), any())
}
@Test
@@ -199,7 +199,7 @@
val offset = 10
val dummyEditorState = EditorModel(text = "Hello, World", selection = TextRange(1, 1))
- whenever(painter.getOffsetForPosition(position)).thenReturn(offset)
+ whenever(mDelegate.getOffsetForPosition(position)).thenReturn(offset)
val captor = argumentCaptor<List<EditOperation>>()
@@ -207,7 +207,7 @@
TextFieldDelegate.onRelease(
position,
- painter,
+ mDelegate,
processor,
identityOffsetMap,
onValueChange,
@@ -226,10 +226,10 @@
val position = PxPosition(100.px, 200.px)
val offset = 10
- whenever(painter.getOffsetForPosition(position)).thenReturn(offset)
+ whenever(mDelegate.getOffsetForPosition(position)).thenReturn(offset)
TextFieldDelegate.onRelease(
position,
- painter,
+ mDelegate,
processor,
identityOffsetMap,
onValueChange,
@@ -246,7 +246,7 @@
TextFieldDelegate.draw(
canvas = canvas,
- textPainter = painter,
+ textDelegate = mDelegate,
value = EditorModel(
text = "Hello, World", selection = TextRange(1, 1),
composition = TextRange(1, 3)
@@ -256,9 +256,9 @@
offsetMap = identityOffsetMap
)
- inOrder(painter) {
- verify(painter).paintBackground(eq(1), eq(3), eq(Color.Red), eq(canvas))
- verify(painter).paintCursor(eq(1), eq(canvas))
+ inOrder(mDelegate) {
+ verify(mDelegate).paintBackground(eq(1), eq(3), eq(Color.Red), eq(canvas))
+ verify(mDelegate).paintCursor(eq(1), eq(canvas))
}
}
@@ -293,13 +293,13 @@
@Test
fun notify_focused_rect() {
val dummyRect = Rect(0f, 1f, 2f, 3f)
- whenever(painter.getBoundingBox(any())).thenReturn(dummyRect)
+ whenever(mDelegate.getBoundingBox(any())).thenReturn(dummyRect)
val dummyPoint = PxPosition(5.px, 6.px)
whenever(layoutCoordinates.localToRoot(any())).thenReturn(dummyPoint)
val dummyEditorState = EditorModel(text = "Hello, World", selection = TextRange(1, 1))
TextFieldDelegate.notifyFocusedRect(
dummyEditorState,
- painter,
+ mDelegate,
layoutCoordinates,
textInputService,
true /* hasFocus */,
@@ -313,7 +313,7 @@
val dummyEditorState = EditorModel(text = "Hello, World", selection = TextRange(1, 1))
TextFieldDelegate.notifyFocusedRect(
dummyEditorState,
- painter,
+ mDelegate,
layoutCoordinates,
textInputService,
false /* hasFocus */,
@@ -325,13 +325,13 @@
@Test
fun notify_rect_tail() {
val dummyRect = Rect(0f, 1f, 2f, 3f)
- whenever(painter.getBoundingBox(any())).thenReturn(dummyRect)
+ whenever(mDelegate.getBoundingBox(any())).thenReturn(dummyRect)
val dummyPoint = PxPosition(5.px, 6.px)
whenever(layoutCoordinates.localToRoot(any())).thenReturn(dummyPoint)
val dummyEditorState = EditorModel(text = "Hello, World", selection = TextRange(12, 12))
TextFieldDelegate.notifyFocusedRect(
dummyEditorState,
- painter,
+ mDelegate,
layoutCoordinates,
textInputService,
true /* hasFocus */,
@@ -343,13 +343,13 @@
@Test
fun notify_rect_empty() {
val dummyHeight = 64f
- whenever(painter.preferredLineHeight).thenReturn(dummyHeight)
+ whenever(mDelegate.preferredLineHeight).thenReturn(dummyHeight)
val dummyPoint = PxPosition(5.px, 6.px)
whenever(layoutCoordinates.localToRoot(any())).thenReturn(dummyPoint)
val dummyEditorState = EditorModel(text = "", selection = TextRange(0, 0))
TextFieldDelegate.notifyFocusedRect(
dummyEditorState,
- painter,
+ mDelegate,
layoutCoordinates,
textInputService,
true, /* hasFocus */
@@ -369,17 +369,17 @@
)
val dummyText = AnnotatedString(text = "Hello, World")
- whenever(painter.text).thenReturn(dummyText)
- whenever(painter.style).thenReturn(TextStyle())
- whenever(painter.density).thenReturn(Density(1.0f))
- whenever(painter.resourceLoader).thenReturn(mock())
- whenever(painter.height).thenReturn(512.0f)
+ whenever(mDelegate.text).thenReturn(dummyText)
+ whenever(mDelegate.style).thenReturn(TextStyle())
+ whenever(mDelegate.density).thenReturn(Density(1.0f))
+ whenever(mDelegate.resourceLoader).thenReturn(mock())
+ whenever(mDelegate.height).thenReturn(512.0f)
- val res = TextFieldDelegate.layout(painter, constraints)
+ val res = TextFieldDelegate.layout(mDelegate, constraints)
assertEquals(1024.px.round(), res.first)
assertEquals(512.px.round(), res.second)
- verify(painter, times(1)).layout(constraints)
+ verify(mDelegate, times(1)).layout(constraints)
}
@Test
@@ -389,7 +389,7 @@
TextFieldDelegate.draw(
canvas = canvas,
- textPainter = painter,
+ textDelegate = mDelegate,
value = EditorModel(text = "Hello, World", selection = selection),
editorStyle = EditorStyle(selectionColor = selectionColor),
hasFocus = true,
@@ -399,7 +399,7 @@
val selectionStartInTransformedText = selection.start * 2
val selectionEmdInTransformedText = selection.end * 2
- verify(painter, times(1)).paintBackground(
+ verify(mDelegate, times(1)).paintBackground(
eq(selectionStartInTransformedText),
eq(selectionEmdInTransformedText),
eq(selectionColor),
@@ -411,18 +411,18 @@
val dummyRect = Rect(0f, 1f, 2f, 3f)
val dummyPoint = PxPosition(5.px, 6.px)
val dummyEditorState = EditorModel(text = "Hello, World", selection = TextRange(1, 3))
- whenever(painter.getBoundingBox(any())).thenReturn(dummyRect)
+ whenever(mDelegate.getBoundingBox(any())).thenReturn(dummyRect)
whenever(layoutCoordinates.localToRoot(any())).thenReturn(dummyPoint)
TextFieldDelegate.notifyFocusedRect(
dummyEditorState,
- painter,
+ mDelegate,
layoutCoordinates,
textInputService,
true /* hasFocus */,
skippingOffsetMap
)
- verify(painter).getBoundingBox(6)
+ verify(mDelegate).getBoundingBox(6)
verify(textInputService).notifyFocusedRect(any())
}
@@ -432,7 +432,7 @@
val offset = 10
val dummyEditorState = EditorModel(text = "Hello, World", selection = TextRange(1, 1))
- whenever(painter.getOffsetForPosition(position)).thenReturn(offset)
+ whenever(mDelegate.getOffsetForPosition(position)).thenReturn(offset)
val captor = argumentCaptor<List<EditOperation>>()
@@ -440,7 +440,7 @@
TextFieldDelegate.onRelease(
position,
- painter,
+ mDelegate,
processor,
skippingOffsetMap,
onValueChange,
diff --git a/ui/ui-text/api/1.0.0-alpha01.txt b/ui/ui-text/api/1.0.0-alpha01.txt
index 11033b4..7d15e2a 100644
--- a/ui/ui-text/api/1.0.0-alpha01.txt
+++ b/ui/ui-text/api/1.0.0-alpha01.txt
@@ -140,43 +140,8 @@
method public androidx.ui.text.ParagraphStyle merge(androidx.ui.text.ParagraphStyle? other = null);
}
- public final class TextPainter {
- ctor public TextPainter(androidx.ui.text.AnnotatedString? text, androidx.ui.text.TextStyle? style, androidx.ui.text.ParagraphStyle? paragraphStyle, Integer? maxLines, boolean softWrap, androidx.ui.text.style.TextOverflow overflow, androidx.ui.text.Locale? locale, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
- method public androidx.ui.core.Density getDensity();
- method public boolean getDidExceedMaxLines();
- method public float getHeight();
- method public androidx.ui.text.Locale? getLocale();
- method public float getMaxIntrinsicWidth();
- method public Integer? getMaxLines();
- method public float getMinIntrinsicWidth();
- method public int getOffsetForPosition(androidx.ui.core.PxPosition position);
- method public androidx.ui.text.style.TextOverflow getOverflow();
- method public androidx.ui.text.ParagraphStyle? getParagraphStyle();
- method public float getPreferredLineHeight();
- method public androidx.ui.text.font.Font.ResourceLoader getResourceLoader();
- method public androidx.ui.engine.geometry.Size getSize();
- method public boolean getSoftWrap();
- method public androidx.ui.text.TextStyle? getStyle();
- method public androidx.ui.text.AnnotatedString? getText();
- method public float getWidth();
- method public androidx.ui.text.TextRange getWordBoundary(int offset);
- method public void layout(androidx.ui.core.Constraints constraints);
- method public void paint(androidx.ui.painting.Canvas canvas);
- method public void paintBackground(int start, int end, androidx.ui.graphics.Color color, androidx.ui.painting.Canvas canvas);
- method public void paintCursor(int offset, androidx.ui.painting.Canvas canvas);
- method public void setText(androidx.ui.text.AnnotatedString? value);
- property public final boolean didExceedMaxLines;
- property public final float height;
- property public final float maxIntrinsicWidth;
- property public final float minIntrinsicWidth;
- property public final float preferredLineHeight;
- property public final androidx.ui.engine.geometry.Size size;
- property public final androidx.ui.text.AnnotatedString? text;
- property public final float width;
- }
-
- public final class TextPainterKt {
- ctor public TextPainterKt();
+ public final class TextDelegateKt {
+ ctor public TextDelegateKt();
}
public final class TextSpanKt {
diff --git a/ui/ui-text/api/api_lint.ignore b/ui/ui-text/api/api_lint.ignore
index 6051d58..87e9863 100644
--- a/ui/ui-text/api/api_lint.ignore
+++ b/ui/ui-text/api/api_lint.ignore
@@ -9,9 +9,9 @@
Must avoid boxed primitives (`java.lang.Float`)
AutoBoxing: androidx.ui.text.ParagraphStyle#getLineHeight():
Must avoid boxed primitives (`java.lang.Float`)
-AutoBoxing: androidx.ui.text.TextPainter#TextPainter(androidx.ui.text.AnnotatedString, androidx.ui.text.TextStyle, androidx.ui.text.ParagraphStyle, Integer, boolean, androidx.ui.text.style.TextOverflow, androidx.ui.text.Locale, androidx.ui.core.Density, androidx.ui.text.font.Font.ResourceLoader) parameter #3:
+AutoBoxing: androidx.ui.text.TextDelegate#TextPainter(androidx.ui.text.AnnotatedString, androidx.ui.text.TextStyle, androidx.ui.text.ParagraphStyle, Integer, boolean, androidx.ui.text.style.TextOverflow, androidx.ui.text.Locale, androidx.ui.core.Density, androidx.ui.text.font.Font.ResourceLoader) parameter #3:
Must avoid boxed primitives (`java.lang.Integer`)
-AutoBoxing: androidx.ui.text.TextPainter#getMaxLines():
+AutoBoxing: androidx.ui.text.TextDelegate#getMaxLines():
Must avoid boxed primitives (`java.lang.Integer`)
AutoBoxing: androidx.ui.text.TextStyle#TextStyle(androidx.ui.graphics.Color, androidx.ui.core.Sp, Float, androidx.ui.text.font.FontWeight, androidx.ui.text.font.FontStyle, androidx.ui.text.font.FontSynthesis, androidx.ui.text.font.FontFamily, String, Float, androidx.ui.text.style.BaselineShift, androidx.ui.text.style.TextGeometricTransform, androidx.ui.text.Locale, androidx.ui.graphics.Color, androidx.ui.text.style.TextDecoration, androidx.ui.painting.Shadow) parameter #2:
Must avoid boxed primitives (`java.lang.Float`)
diff --git a/ui/ui-text/api/current.txt b/ui/ui-text/api/current.txt
index 11033b4..7d15e2a 100644
--- a/ui/ui-text/api/current.txt
+++ b/ui/ui-text/api/current.txt
@@ -140,43 +140,8 @@
method public androidx.ui.text.ParagraphStyle merge(androidx.ui.text.ParagraphStyle? other = null);
}
- public final class TextPainter {
- ctor public TextPainter(androidx.ui.text.AnnotatedString? text, androidx.ui.text.TextStyle? style, androidx.ui.text.ParagraphStyle? paragraphStyle, Integer? maxLines, boolean softWrap, androidx.ui.text.style.TextOverflow overflow, androidx.ui.text.Locale? locale, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
- method public androidx.ui.core.Density getDensity();
- method public boolean getDidExceedMaxLines();
- method public float getHeight();
- method public androidx.ui.text.Locale? getLocale();
- method public float getMaxIntrinsicWidth();
- method public Integer? getMaxLines();
- method public float getMinIntrinsicWidth();
- method public int getOffsetForPosition(androidx.ui.core.PxPosition position);
- method public androidx.ui.text.style.TextOverflow getOverflow();
- method public androidx.ui.text.ParagraphStyle? getParagraphStyle();
- method public float getPreferredLineHeight();
- method public androidx.ui.text.font.Font.ResourceLoader getResourceLoader();
- method public androidx.ui.engine.geometry.Size getSize();
- method public boolean getSoftWrap();
- method public androidx.ui.text.TextStyle? getStyle();
- method public androidx.ui.text.AnnotatedString? getText();
- method public float getWidth();
- method public androidx.ui.text.TextRange getWordBoundary(int offset);
- method public void layout(androidx.ui.core.Constraints constraints);
- method public void paint(androidx.ui.painting.Canvas canvas);
- method public void paintBackground(int start, int end, androidx.ui.graphics.Color color, androidx.ui.painting.Canvas canvas);
- method public void paintCursor(int offset, androidx.ui.painting.Canvas canvas);
- method public void setText(androidx.ui.text.AnnotatedString? value);
- property public final boolean didExceedMaxLines;
- property public final float height;
- property public final float maxIntrinsicWidth;
- property public final float minIntrinsicWidth;
- property public final float preferredLineHeight;
- property public final androidx.ui.engine.geometry.Size size;
- property public final androidx.ui.text.AnnotatedString? text;
- property public final float width;
- }
-
- public final class TextPainterKt {
- ctor public TextPainterKt();
+ public final class TextDelegateKt {
+ ctor public TextDelegateKt();
}
public final class TextSpanKt {
diff --git a/ui/ui-text/api/restricted_1.0.0-alpha01.txt b/ui/ui-text/api/restricted_1.0.0-alpha01.txt
index 4850b0f..a2896e5 100644
--- a/ui/ui-text/api/restricted_1.0.0-alpha01.txt
+++ b/ui/ui-text/api/restricted_1.0.0-alpha01.txt
@@ -154,43 +154,9 @@
method public androidx.ui.text.ParagraphStyle merge(androidx.ui.text.ParagraphStyle? other = null);
}
- public final class TextPainter {
- ctor public TextPainter(androidx.ui.text.AnnotatedString? text, androidx.ui.text.TextStyle? style, androidx.ui.text.ParagraphStyle? paragraphStyle, Integer? maxLines, boolean softWrap, androidx.ui.text.style.TextOverflow overflow, androidx.ui.text.Locale? locale, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
- method public androidx.ui.core.Density getDensity();
- method public boolean getDidExceedMaxLines();
- method public float getHeight();
- method public androidx.ui.text.Locale? getLocale();
- method public float getMaxIntrinsicWidth();
- method public Integer? getMaxLines();
- method public float getMinIntrinsicWidth();
- method public int getOffsetForPosition(androidx.ui.core.PxPosition position);
- method public androidx.ui.text.style.TextOverflow getOverflow();
- method public androidx.ui.text.ParagraphStyle? getParagraphStyle();
- method public float getPreferredLineHeight();
- method public androidx.ui.text.font.Font.ResourceLoader getResourceLoader();
- method public androidx.ui.engine.geometry.Size getSize();
- method public boolean getSoftWrap();
- method public androidx.ui.text.TextStyle? getStyle();
- method public androidx.ui.text.AnnotatedString? getText();
- method public float getWidth();
- method public androidx.ui.text.TextRange getWordBoundary(int offset);
- method public void layout(androidx.ui.core.Constraints constraints);
- method public void paint(androidx.ui.painting.Canvas canvas);
- method public void paintBackground(int start, int end, androidx.ui.graphics.Color color, androidx.ui.painting.Canvas canvas);
- method public void paintCursor(int offset, androidx.ui.painting.Canvas canvas);
- method public void setText(androidx.ui.text.AnnotatedString? value);
- property public final boolean didExceedMaxLines;
- property public final float height;
- property public final float maxIntrinsicWidth;
- property public final float minIntrinsicWidth;
- property public final float preferredLineHeight;
- property public final androidx.ui.engine.geometry.Size size;
- property public final androidx.ui.text.AnnotatedString? text;
- property public final float width;
- }
- public final class TextPainterKt {
- ctor public TextPainterKt();
+ public final class TextDelegateKt {
+ ctor public TextDelegateKt();
}
@RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP) public final class TextSpan {
diff --git a/ui/ui-text/api/restricted_current.txt b/ui/ui-text/api/restricted_current.txt
index 4850b0f..a2896e5 100644
--- a/ui/ui-text/api/restricted_current.txt
+++ b/ui/ui-text/api/restricted_current.txt
@@ -154,43 +154,9 @@
method public androidx.ui.text.ParagraphStyle merge(androidx.ui.text.ParagraphStyle? other = null);
}
- public final class TextPainter {
- ctor public TextPainter(androidx.ui.text.AnnotatedString? text, androidx.ui.text.TextStyle? style, androidx.ui.text.ParagraphStyle? paragraphStyle, Integer? maxLines, boolean softWrap, androidx.ui.text.style.TextOverflow overflow, androidx.ui.text.Locale? locale, androidx.ui.core.Density density, androidx.ui.text.font.Font.ResourceLoader resourceLoader);
- method public androidx.ui.core.Density getDensity();
- method public boolean getDidExceedMaxLines();
- method public float getHeight();
- method public androidx.ui.text.Locale? getLocale();
- method public float getMaxIntrinsicWidth();
- method public Integer? getMaxLines();
- method public float getMinIntrinsicWidth();
- method public int getOffsetForPosition(androidx.ui.core.PxPosition position);
- method public androidx.ui.text.style.TextOverflow getOverflow();
- method public androidx.ui.text.ParagraphStyle? getParagraphStyle();
- method public float getPreferredLineHeight();
- method public androidx.ui.text.font.Font.ResourceLoader getResourceLoader();
- method public androidx.ui.engine.geometry.Size getSize();
- method public boolean getSoftWrap();
- method public androidx.ui.text.TextStyle? getStyle();
- method public androidx.ui.text.AnnotatedString? getText();
- method public float getWidth();
- method public androidx.ui.text.TextRange getWordBoundary(int offset);
- method public void layout(androidx.ui.core.Constraints constraints);
- method public void paint(androidx.ui.painting.Canvas canvas);
- method public void paintBackground(int start, int end, androidx.ui.graphics.Color color, androidx.ui.painting.Canvas canvas);
- method public void paintCursor(int offset, androidx.ui.painting.Canvas canvas);
- method public void setText(androidx.ui.text.AnnotatedString? value);
- property public final boolean didExceedMaxLines;
- property public final float height;
- property public final float maxIntrinsicWidth;
- property public final float minIntrinsicWidth;
- property public final float preferredLineHeight;
- property public final androidx.ui.engine.geometry.Size size;
- property public final androidx.ui.text.AnnotatedString? text;
- property public final float width;
- }
- public final class TextPainterKt {
- ctor public TextPainterKt();
+ public final class TextDelegateKt {
+ ctor public TextDelegateKt();
}
@RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP) public final class TextSpan {
diff --git a/ui/ui-text/src/androidTest/java/androidx/ui/text/TextPainterIntegrationTest.kt b/ui/ui-text/src/androidTest/java/androidx/ui/text/TextDelegateIntegrationTest.kt
similarity index 96%
rename from ui/ui-text/src/androidTest/java/androidx/ui/text/TextPainterIntegrationTest.kt
rename to ui/ui-text/src/androidTest/java/androidx/ui/text/TextDelegateIntegrationTest.kt
index 3b17aae..a5e04ac 100644
--- a/ui/ui-text/src/androidTest/java/androidx/ui/text/TextPainterIntegrationTest.kt
+++ b/ui/ui-text/src/androidTest/java/androidx/ui/text/TextDelegateIntegrationTest.kt
@@ -45,7 +45,7 @@
@RunWith(JUnit4::class)
@SmallTest
-class TextPainterIntegrationTest {
+class TextDelegateIntegrationTest {
private val fontFamily = BASIC_MEASURE_FONT.asFontFamily()
private val density = Density(density = 1f)
@@ -57,7 +57,7 @@
withDensity(density) {
val fontSize = 20.sp
val textStyle = TextStyle(fontSize = fontSize, fontFamily = fontFamily)
- val textPainter = TextPainter(
+ val textPainter = TextDelegate(
style = textStyle,
density = density,
resourceLoader = resourceLoader
@@ -73,7 +73,7 @@
// @Test
// fun preferredLineHeight_style_not_set() {
// val defaultTextStyle = TextStyle(fontFamily = fontFamily)
-// val textPainter = TextPainter(style = defaultTextStyle)
+// val textPainter = TextDelegate(style = defaultTextStyle)
//
// val prefferedHeight = textPainter.preferredLineHeight
//
@@ -89,7 +89,7 @@
text = text,
textStyles = listOf(AnnotatedString.Item(textStyle, 0, text.length))
)
- val textPainter = TextPainter(
+ val textPainter = TextDelegate(
text = annotatedString,
paragraphStyle = ParagraphStyle(textDirection = TextDirection.Rtl),
density = density,
@@ -117,7 +117,7 @@
)
)
)
- val textPainter = TextPainter(
+ val textPainter = TextDelegate(
text = annotatedString,
paragraphStyle = ParagraphStyle(textDirection = TextDirection.Rtl),
density = density,
@@ -146,7 +146,7 @@
)
)
)
- val textPainter = TextPainter(
+ val textPainter = TextDelegate(
text = annotatedString,
paragraphStyle = ParagraphStyle(textDirection = TextDirection.Rtl),
density = density,
@@ -168,7 +168,7 @@
text = text,
textStyles = listOf(AnnotatedString.Item(textStyle, 0, text.length))
)
- val textPainter = TextPainter(
+ val textPainter = TextDelegate(
text = annotatedString,
paragraphStyle = ParagraphStyle(textDirection = TextDirection.Rtl),
density = density,
@@ -196,7 +196,7 @@
)
)
)
- val textPainter = TextPainter(
+ val textPainter = TextDelegate(
text = annotatedString,
paragraphStyle = ParagraphStyle(textDirection = TextDirection.Rtl),
density = density,
@@ -226,7 +226,7 @@
)
)
)
- val textPainter = TextPainter(
+ val textPainter = TextDelegate(
text = annotatedString,
paragraphStyle = ParagraphStyle(textDirection = TextDirection.Rtl),
density = density,
@@ -249,7 +249,7 @@
var text = ""
for (i in 1..50) text += " Hello"
val annotatedString = AnnotatedString(text = text)
- val textPainter = TextPainter(
+ val textPainter = TextDelegate(
text = annotatedString,
paragraphStyle = ParagraphStyle(textDirection = TextDirection.Rtl),
maxLines = 2,
@@ -266,7 +266,7 @@
fun didExceedMaxLines_not_exceed() {
val text = "Hello"
val annotatedString = AnnotatedString(text = text)
- val textPainter = TextPainter(
+ val textPainter = TextDelegate(
text = annotatedString,
paragraphStyle = ParagraphStyle(textDirection = TextDirection.Rtl),
maxLines = 2,
@@ -281,7 +281,7 @@
@Test
fun layout_build_paragraph() {
- val textPainter = TextPainter(
+ val textPainter = TextDelegate(
text = AnnotatedString(text = "Hello"),
paragraphStyle = ParagraphStyle(textDirection = TextDirection.Ltr),
density = density,
@@ -306,7 +306,7 @@
)
)
)
- val textPainter = TextPainter(
+ val textPainter = TextDelegate(
text = annotatedString,
paragraphStyle = ParagraphStyle(textDirection = TextDirection.Ltr),
density = density,
@@ -335,7 +335,7 @@
)
)
)
- val textPainter = TextPainter(
+ val textPainter = TextDelegate(
text = annotatedString,
paragraphStyle = ParagraphStyle(textDirection = TextDirection.Ltr),
density = density,
@@ -359,7 +359,7 @@
text = text,
textStyles = listOf(AnnotatedString.Item(textStyle, 0, text.length))
)
- val textPainter = TextPainter(
+ val textPainter = TextDelegate(
text = annotatedString,
paragraphStyle = ParagraphStyle(textDirection = TextDirection.Ltr),
density = density,
@@ -382,7 +382,7 @@
text = text,
textStyles = listOf(AnnotatedString.Item(textStyle, 0, text.length))
)
- val textPainter = TextPainter(
+ val textPainter = TextDelegate(
text = annotatedString,
paragraphStyle = ParagraphStyle(textDirection = TextDirection.Ltr),
overflow = TextOverflow.Fade,
@@ -408,7 +408,7 @@
text = text,
textStyles = listOf(AnnotatedString.Item(textStyle, 0, text.length))
)
- val textPainter = TextPainter(
+ val textPainter = TextDelegate(
text = annotatedString,
paragraphStyle = ParagraphStyle(textDirection = TextDirection.Ltr),
overflow = TextOverflow.Fade,
@@ -440,7 +440,7 @@
)
)
)
- val textPainter = TextPainter(
+ val textPainter = TextDelegate(
text = annotatedString,
paragraphStyle = ParagraphStyle(textDirection = TextDirection.Ltr),
density = density,
@@ -518,7 +518,7 @@
)
)
)
- val textPainter = TextPainter(
+ val textPainter = TextDelegate(
text = annotatedString,
paragraphStyle = ParagraphStyle(textDirection = TextDirection.Ltr),
density = density,
@@ -589,7 +589,7 @@
)
)
)
- val textPainter = TextPainter(
+ val textPainter = TextDelegate(
text = annotatedString,
paragraphStyle = ParagraphStyle(textDirection = TextDirection.Ltr),
density = density,
@@ -670,7 +670,7 @@
)
)
val selectionColor = Color(0x66AABB33)
- val textPainter = TextPainter(
+ val textPainter = TextDelegate(
text = annotatedString,
paragraphStyle = ParagraphStyle(textDirection = TextDirection.Ltr),
density = density,
diff --git a/ui/ui-text/src/main/java/androidx/ui/text/ParagraphConstraints.kt b/ui/ui-text/src/main/java/androidx/ui/text/ParagraphConstraints.kt
index 0de2f0d..be60281 100644
--- a/ui/ui-text/src/main/java/androidx/ui/text/ParagraphConstraints.kt
+++ b/ui/ui-text/src/main/java/androidx/ui/text/ParagraphConstraints.kt
@@ -38,8 +38,7 @@
* forced line break is placed after it (even if an explicit line break
* follows).
*
- * The width influences how ellipses are applied. See the discussion at
- * [TextPainter] for more details.
+ * The width influences how ellipses are applied.
*
* This width is also used to position glyphs according to the text alignment
* described in the [ParagraphStyle.textAlign] to create [Paragraph].
diff --git a/ui/ui-text/src/main/java/androidx/ui/text/TextPainter.kt b/ui/ui-text/src/main/java/androidx/ui/text/TextDelegate.kt
similarity index 95%
rename from ui/ui-text/src/main/java/androidx/ui/text/TextPainter.kt
rename to ui/ui-text/src/main/java/androidx/ui/text/TextDelegate.kt
index c9f865d..ba418cc 100644
--- a/ui/ui-text/src/main/java/androidx/ui/text/TextPainter.kt
+++ b/ui/ui-text/src/main/java/androidx/ui/text/TextDelegate.kt
@@ -18,6 +18,7 @@
import androidx.annotation.RestrictTo
import androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP
+import androidx.annotation.RestrictTo.Scope.LIBRARY
import androidx.annotation.VisibleForTesting
import androidx.ui.core.Constraints
import androidx.ui.core.Density
@@ -63,9 +64,9 @@
/**
* An object that paints a [TextSpan] tree into a [Canvas].
*
- * To use a [TextPainter], follow these steps:
+ * To use a [TextDelegate], follow these steps:
*
- * 1. Create a [TextSpan] tree and pass it to the [TextPainter] constructor.
+ * 1. Create a [TextSpan] tree and pass it to the [TextDelegate] constructor.
*
* 2. Call [layout] to prepare the paragraph.
*
@@ -80,7 +81,7 @@
*
* @param style The text style specified to render the text. Notice that you can also set text style
* on the given [AnnotatedString], and the style set on [text] always has higher priority than this
- * setting. But if only one gobal text style is needed, passing it to [TextPainter] is always
+ * setting. But if only one gobal text style is needed, passing it to [TextDelegate] is always
* preferred.
*
* @param paragraphStyle Style configuration that applies only to paragraphs such as text alignment,
@@ -101,8 +102,11 @@
* After this is set, you must call [layout] before the next call to [paint].
*
* @param locale The locale used to select region-specific glyphs.
+ *
+ * @hide
*/
-class TextPainter(
+@RestrictTo(RestrictTo.Scope.LIBRARY)
+class TextDelegate(
text: AnnotatedString? = null,
val style: TextStyle? = null,
val paragraphStyle: ParagraphStyle? = null,
@@ -206,7 +210,7 @@
private fun assertNeedsLayout(name: String) {
assert(!needsLayout) {
- "TextPainter.$name should only be called after layout has been called."
+ "TextDelegate.$name should only be called after layout has been called."
}
}
@@ -294,11 +298,11 @@
*/
private fun layoutText(minWidth: Float = 0.0f, maxWidth: Float = Float.POSITIVE_INFINITY) {
assert(text != null) {
- "TextPainter.text must be set to a non-null value before using the TextPainter."
+ "TextDelegate.text must be set to a non-null value before using the TextDelegate."
}
assert(textDirection != null) {
- "TextPainter.textDirection must be set to a non-null value before using the" +
- " TextPainter."
+ "TextDelegate.textDirection must be set to a non-null value before using the" +
+ " TextDelegate."
}
// TODO(haoyuchang): fix that when softWarp is false and overflow is Ellipsis, ellipsis
@@ -348,7 +352,7 @@
// that affects the actual (but undetected) vertical overflow.
hasVisualOverflow = didOverflowWidth || didOverflowHeight
overflowShader = if (hasVisualOverflow && overflow == TextOverflow.Fade) {
- val fadeSizePainter = TextPainter(
+ val fadeSizePainter = TextDelegate(
text = AnnotatedString(text = "\u2026", textStyles = listOf()),
style = textStyle,
paragraphStyle = paragraphStyle,
@@ -394,11 +398,11 @@
* background, the text will not be visible by default.
*
* To set the text style, specify a [TextStyle] when creating the [TextSpan] that you pass to
- * the [TextPainter] constructor or to the [text] property.
+ * the [TextDelegate] constructor or to the [text] property.
*/
fun paint(canvas: Canvas) {
assert(!needsLayout) {
- "TextPainter.paint called when text geometry was not yet calculated.\n" +
+ "TextDelegate.paint called when text geometry was not yet calculated.\n" +
"Please call layout() before paint() to position the text before painting it."
}
// Ideally we could compute the min/max intrinsic width/height with a
diff --git a/ui/ui-text/src/test/java/androidx/ui/text/TextPainterTest.kt b/ui/ui-text/src/test/java/androidx/ui/text/TextDelegateTest.kt
similarity index 67%
rename from ui/ui-text/src/test/java/androidx/ui/text/TextPainterTest.kt
rename to ui/ui-text/src/test/java/androidx/ui/text/TextDelegateTest.kt
index 5dcae69..1c2f508 100644
--- a/ui/ui-text/src/test/java/androidx/ui/text/TextPainterTest.kt
+++ b/ui/ui-text/src/test/java/androidx/ui/text/TextDelegateTest.kt
@@ -30,105 +30,105 @@
import org.junit.runners.JUnit4
@RunWith(JUnit4::class)
-class TextPainterTest() {
+class TextDelegateTest() {
private val density = Density(density = 1f)
private val resourceLoader = mock<Font.ResourceLoader>()
@Test
fun `constructor with default values`() {
- val textPainter = TextPainter(density = density, resourceLoader = resourceLoader)
+ val textDelegate = TextDelegate(density = density, resourceLoader = resourceLoader)
- assertThat(textPainter.text).isNull()
- assertThat(textPainter.textAlign).isEqualTo(TextAlign.Start)
- assertThat(textPainter.textDirection).isEqualTo(TextDirection.Ltr)
- assertThat(textPainter.maxLines).isNull()
- assertThat(textPainter.overflow).isEqualTo(TextOverflow.Clip)
- assertThat(textPainter.locale).isNull()
+ assertThat(textDelegate.text).isNull()
+ assertThat(textDelegate.textAlign).isEqualTo(TextAlign.Start)
+ assertThat(textDelegate.textDirection).isEqualTo(TextDirection.Ltr)
+ assertThat(textDelegate.maxLines).isNull()
+ assertThat(textDelegate.overflow).isEqualTo(TextOverflow.Clip)
+ assertThat(textDelegate.locale).isNull()
}
@Test
fun `constructor with customized text(TextSpan)`() {
val text = AnnotatedString("Hello")
- val textPainter = TextPainter(
+ val textDelegate = TextDelegate(
text = text,
density = density,
resourceLoader = resourceLoader
)
- assertThat(textPainter.text).isEqualTo(text)
+ assertThat(textDelegate.text).isEqualTo(text)
}
@Test
fun `constructor with customized textAlign`() {
- val textPainter = TextPainter(
+ val textDelegate = TextDelegate(
paragraphStyle = ParagraphStyle(textAlign = TextAlign.Left),
density = density,
resourceLoader = resourceLoader
)
- assertThat(textPainter.textAlign).isEqualTo(TextAlign.Left)
+ assertThat(textDelegate.textAlign).isEqualTo(TextAlign.Left)
}
@Test
fun `constructor with customized textDirection`() {
- val textPainter = TextPainter(
+ val textDelegate = TextDelegate(
paragraphStyle = ParagraphStyle(textDirection = TextDirection.Rtl),
density = density,
resourceLoader = resourceLoader
)
- assertThat(textPainter.textDirection).isEqualTo(TextDirection.Rtl)
+ assertThat(textDelegate.textDirection).isEqualTo(TextDirection.Rtl)
}
@Test
fun `constructor with customized maxLines`() {
val maxLines = 8
- val textPainter = TextPainter(
+ val textDelegate = TextDelegate(
maxLines = maxLines,
density = density,
resourceLoader = resourceLoader
)
- assertThat(textPainter.maxLines).isEqualTo(maxLines)
+ assertThat(textDelegate.maxLines).isEqualTo(maxLines)
}
@Test
fun `constructor with customized overflow`() {
val overflow = TextOverflow.Ellipsis
- val textPainter = TextPainter(
+ val textDelegate = TextDelegate(
overflow = overflow,
density = density,
resourceLoader = resourceLoader
)
- assertThat(textPainter.overflow).isEqualTo(overflow)
+ assertThat(textDelegate.overflow).isEqualTo(overflow)
}
@Test
fun `constructor with customized locale`() {
val locale = Locale("en", "US")
- val textPainter = TextPainter(
+ val textDelegate = TextDelegate(
locale = locale,
density = density,
resourceLoader = resourceLoader
)
- assertThat(textPainter.locale).isEqualTo(locale)
+ assertThat(textDelegate.locale).isEqualTo(locale)
}
@Test
fun `text setter`() {
- val textPainter = TextPainter(density = density, resourceLoader = resourceLoader)
+ val textDelegate = TextDelegate(density = density, resourceLoader = resourceLoader)
val text = AnnotatedString(text = "Hello")
- textPainter.text = text
+ textDelegate.text = text
- assertThat(textPainter.text).isEqualTo(text)
- assertThat(textPainter.multiParagraph).isNull()
- assertThat(textPainter.needsLayout).isTrue()
+ assertThat(textDelegate.text).isEqualTo(text)
+ assertThat(textDelegate.multiParagraph).isNull()
+ assertThat(textDelegate.needsLayout).isTrue()
}
@Test
@@ -137,7 +137,7 @@
val overflow = TextOverflow.Ellipsis
val locale = Locale("en", "US")
val text = AnnotatedString(text = "Hello")
- val textPainter = TextPainter(
+ val textDelegate = TextDelegate(
text = text,
paragraphStyle = ParagraphStyle(
textAlign = TextAlign.Center,
@@ -150,7 +150,7 @@
resourceLoader = resourceLoader
)
- val paragraphStyle = textPainter.createParagraphStyle()
+ val paragraphStyle = textDelegate.createParagraphStyle()
assertThat(paragraphStyle.textAlign).isEqualTo(TextAlign.Center)
assertThat(paragraphStyle.textDirection).isEqualTo(TextDirection.Rtl)
@@ -173,55 +173,55 @@
@Test(expected = AssertionError::class)
fun `minIntrinsicWidth without layout assertion should fail`() {
- val textPainter = TextPainter(density = density, resourceLoader = resourceLoader)
+ val textDelegate = TextDelegate(density = density, resourceLoader = resourceLoader)
- textPainter.minIntrinsicWidth
+ textDelegate.minIntrinsicWidth
}
@Test(expected = AssertionError::class)
fun `maxIntrinsicWidth without layout assertion should fail`() {
- val textPainter = TextPainter(density = density, resourceLoader = resourceLoader)
+ val textDelegate = TextDelegate(density = density, resourceLoader = resourceLoader)
- textPainter.maxIntrinsicWidth
+ textDelegate.maxIntrinsicWidth
}
@Test(expected = AssertionError::class)
fun `width without layout assertion should fail`() {
- val textPainter = TextPainter(density = density, resourceLoader = resourceLoader)
+ val textDelegate = TextDelegate(density = density, resourceLoader = resourceLoader)
- textPainter.width
+ textDelegate.width
}
@Test(expected = AssertionError::class)
fun `height without layout assertion should fail`() {
- val textPainter = TextPainter(density = density, resourceLoader = resourceLoader)
+ val textDelegate = TextDelegate(density = density, resourceLoader = resourceLoader)
- textPainter.height
+ textDelegate.height
}
@Test(expected = AssertionError::class)
fun `size without layout assertion should fail`() {
- val textPainter = TextPainter(density = density, resourceLoader = resourceLoader)
+ val textDelegate = TextDelegate(density = density, resourceLoader = resourceLoader)
- textPainter.size
+ textDelegate.size
}
@Test(expected = AssertionError::class)
fun `layout without text assertion should fail`() {
- val textPainter = TextPainter(
+ val textDelegate = TextDelegate(
paragraphStyle = ParagraphStyle(textDirection = TextDirection.Ltr),
density = density,
resourceLoader = resourceLoader
)
- textPainter.layout(Constraints())
+ textDelegate.layout(Constraints())
}
@Test(expected = AssertionError::class)
fun `paint without layout assertion should fail`() {
- val textPainter = TextPainter(density = density, resourceLoader = resourceLoader)
+ val textDelegate = TextDelegate(density = density, resourceLoader = resourceLoader)
val canvas = mock<Canvas>()
- textPainter.paint(canvas)
+ textDelegate.paint(canvas)
}
}