Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
65580026
Unverified
Commit
65580026
authored
Feb 20, 2019
by
Michael Goderbauer
Committed by
GitHub
Feb 20, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add TextOverflow.visible (#28182)
parent
4ed096bd
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
6 deletions
+40
-6
paragraph.dart
packages/flutter/lib/src/rendering/paragraph.dart
+15
-5
icon.dart
packages/flutter/lib/src/widgets/icon.dart
+5
-1
text_test.dart
packages/flutter/test/widgets/text_test.dart
+20
-0
No files found.
packages/flutter/lib/src/rendering/paragraph.dart
View file @
65580026
...
...
@@ -25,6 +25,9 @@ enum TextOverflow {
/// Use an ellipsis to indicate that the text has overflowed.
ellipsis
,
/// Render overflowing text outside of its container.
visible
,
}
const
String
_kEllipsis
=
'
\
u2026'
;
...
...
@@ -268,7 +271,7 @@ class RenderParagraph extends RenderBox {
span
?.
recognizer
?.
addPointer
(
event
);
}
bool
_
hasVisualOverflow
=
false
;
bool
_
needsClipping
=
false
;
ui
.
Shader
_overflowShader
;
/// Whether this paragraph currently has a [dart:ui.Shader] for its overflow
...
...
@@ -297,15 +300,21 @@ class RenderParagraph extends RenderBox {
// visual overflow when there actually is visual overflow. This can become
// a problem if we start having horizontal overflow and introduce a clip
// that affects the actual (but undetected) vertical overflow.
_
hasVisualOverflow
=
didOverflowWidth
||
didOverflowHeight
;
if
(
_
hasVisualOverflow
)
{
final
bool
hasVisualOverflow
=
didOverflowWidth
||
didOverflowHeight
;
if
(
hasVisualOverflow
)
{
switch
(
_overflow
)
{
case
TextOverflow
.
visible
:
_needsClipping
=
false
;
_overflowShader
=
null
;
break
;
case
TextOverflow
.
clip
:
case
TextOverflow
.
ellipsis
:
_needsClipping
=
true
;
_overflowShader
=
null
;
break
;
case
TextOverflow
.
fade
:
assert
(
textDirection
!=
null
);
_needsClipping
=
true
;
final
TextPainter
fadeSizePainter
=
TextPainter
(
text:
TextSpan
(
style:
_textPainter
.
text
.
style
,
text:
'
\
u2026'
),
textDirection:
textDirection
,
...
...
@@ -341,6 +350,7 @@ class RenderParagraph extends RenderBox {
break
;
}
}
else
{
_needsClipping
=
false
;
_overflowShader
=
null
;
}
}
...
...
@@ -369,7 +379,7 @@ class RenderParagraph extends RenderBox {
return
true
;
}());
if
(
_
hasVisualOverflow
)
{
if
(
_
needsClipping
)
{
final
Rect
bounds
=
offset
&
size
;
if
(
_overflowShader
!=
null
)
{
// This layer limits what the shader below blends with to be just the text
...
...
@@ -381,7 +391,7 @@ class RenderParagraph extends RenderBox {
canvas
.
clipRect
(
bounds
);
}
_textPainter
.
paint
(
canvas
,
offset
);
if
(
_
hasVisualOverflow
)
{
if
(
_
needsClipping
)
{
if
(
_overflowShader
!=
null
)
{
canvas
.
translate
(
offset
.
dx
,
offset
.
dy
);
final
Paint
paint
=
Paint
()
...
...
packages/flutter/lib/src/widgets/icon.dart
View file @
65580026
...
...
@@ -21,10 +21,13 @@ import 'icon_theme_data.dart';
/// Typically this is introduced automatically by the [WidgetsApp] or
/// [MaterialApp].
///
/// This widget assumes that the rendered icon is squared. Non-squared icons may
/// render incorrectly.
///
/// {@tool sample}
///
/// This example shows how to use [Icon] to create an addition icon, in the
/// color pink, and 30 pixels in size.
/// color pink, and 30
x 30
pixels in size.
///
/// ```dart
/// Icon(
...
...
@@ -148,6 +151,7 @@ class Icon extends StatelessWidget {
iconColor
=
iconColor
.
withOpacity
(
iconColor
.
opacity
*
iconOpacity
);
Widget
iconWidget
=
RichText
(
overflow:
TextOverflow
.
visible
,
// Never clip.
textDirection:
textDirection
,
// Since we already fetched it for the assert...
text:
TextSpan
(
text:
String
.
fromCharCode
(
icon
.
codePoint
),
...
...
packages/flutter/test/widgets/text_test.dart
View file @
65580026
...
...
@@ -298,6 +298,26 @@ void main() {
expect
(
find
.
byType
(
Text
),
isNot
(
paints
..
clipRect
()));
});
testWidgets
(
'Overflow is clipping correctly - long text with overflow: visible'
,
(
WidgetTester
tester
)
async
{
await
_pumpTextWidget
(
tester:
tester
,
overflow:
TextOverflow
.
visible
,
text:
'a long long long long text, should be clip'
,
);
expect
(
find
.
byType
(
Text
),
isNot
(
paints
..
clipRect
()));
});
testWidgets
(
'Overflow is clipping correctly - short text with overflow: visible'
,
(
WidgetTester
tester
)
async
{
await
_pumpTextWidget
(
tester:
tester
,
overflow:
TextOverflow
.
visible
,
text:
'Hi'
,
);
expect
(
find
.
byType
(
Text
),
isNot
(
paints
..
clipRect
()));
});
}
Future
<
void
>
_pumpTextWidget
({
WidgetTester
tester
,
String
text
,
TextOverflow
overflow
})
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment