Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit af83bb5

Browse files
author
Yuncong Zhang
committed
[1.5.4] Upgrade widgets. Add visible to TextOverflow.
1 parent 4eb24c1 commit af83bb5

File tree

5 files changed

+35
-15
lines changed

5 files changed

+35
-15
lines changed

Runtime/rendering/paragraph.cs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public enum TextOverflow {
2020

2121
/// Use an ellipsis to indicate that the text has overflowed.
2222
ellipsis,
23+
24+
/// Render overflowing text outside of its container.
25+
visible,
2326
}
2427

2528

@@ -30,7 +33,7 @@ public class RenderParagraph : RenderBox {
3033

3134
TextOverflow _overflow;
3235
readonly TextPainter _textPainter;
33-
bool _hasVisualOverflow = false;
36+
bool _needsClipping = false;
3437

3538
List<TextBox> _selectionRects;
3639

@@ -405,11 +408,27 @@ public override void handleEvent(PointerEvent evt, HitTestEntry entry) {
405408
protected override void performLayout() {
406409
this._layoutTextWithConstraints(this.constraints);
407410
var textSize = this._textPainter.size;
408-
var didOverflowHeight = this._textPainter.didExceedMaxLines;
411+
var textDidExceedMaxLines = this._textPainter.didExceedMaxLines;
409412
this.size = this.constraints.constrain(textSize);
410413

414+
var didOverflowHeight = this.size.height < textSize.height || textDidExceedMaxLines;
411415
var didOverflowWidth = this.size.width < textSize.width;
412-
this._hasVisualOverflow = didOverflowWidth || didOverflowHeight;
416+
var hasVisualOverflow = didOverflowWidth || didOverflowHeight;
417+
if (hasVisualOverflow) {
418+
switch (this._overflow) {
419+
case TextOverflow.visible:
420+
this._needsClipping = false;
421+
break;
422+
case TextOverflow.clip:
423+
case TextOverflow.ellipsis:
424+
case TextOverflow.fade:
425+
this._needsClipping = true;
426+
break;
427+
}
428+
}
429+
else {
430+
this._needsClipping = false;
431+
}
413432

414433
this._selectionRects = null;
415434
}
@@ -419,7 +438,7 @@ void paintParagraph(PaintingContext context, Offset offset) {
419438
this._layoutTextWithConstraints(this.constraints);
420439
var canvas = context.canvas;
421440

422-
if (this._hasVisualOverflow) {
441+
if (this._needsClipping) {
423442
var bounds = offset & this.size;
424443
canvas.save();
425444
canvas.clipRect(bounds);
@@ -434,7 +453,7 @@ void paintParagraph(PaintingContext context, Offset offset) {
434453
}
435454

436455
this._textPainter.paint(canvas, offset);
437-
if (this._hasVisualOverflow) {
456+
if (this._needsClipping) {
438457
canvas.restore();
439458
}
440459
}

Runtime/widgets/fade_in_image.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ public static FadeInImage assetNetwork(
101101
) {
102102
D.assert(placeholder != null);
103103
D.assert(image != null);
104-
D.assert(fadeOutDuration != null);
105-
D.assert(fadeOutCurve != null);
106-
D.assert(fadeInDuration != null);
107-
D.assert(fadeInCurve != null);
108-
D.assert(alignment != null);
104+
fadeOutDuration = fadeOutDuration ?? new TimeSpan(0, 0, 0, 0, 300);
105+
fadeOutCurve = fadeOutCurve ?? Curves.easeOut;
106+
fadeInDuration = fadeInDuration ?? new TimeSpan(0, 0, 0, 0, 700);
107+
fadeInCurve = Curves.easeIn;
108+
alignment = alignment ?? Alignment.center;
109109
var imageProvider = placeholderScale != null
110110
? new ExactAssetImage(placeholder, bundle: bundle, scale: placeholderScale ?? 1.0f)
111111
: (ImageProvider) new AssetImage(placeholder, bundle: bundle);

Runtime/widgets/icon.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Unity.UIWidgets.foundation;
22
using Unity.UIWidgets.painting;
3+
using Unity.UIWidgets.rendering;
34
using Unity.UIWidgets.ui;
45
using TextStyle = Unity.UIWidgets.painting.TextStyle;
56

@@ -36,6 +37,7 @@ public override Widget build(BuildContext context) {
3637
}
3738

3839
Widget iconWidget = new RichText(
40+
overflow: TextOverflow.visible,
3941
text: new TextSpan(
4042
text: new string(new[] {(char) this.icon.codePoint}),
4143
style: new TextStyle(

Runtime/widgets/nested_scroll_view.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public NestedScrollView(
2525
ScrollPhysics physics = null,
2626
NestedScrollViewHeaderSliversBuilder headerSliverBuilder = null,
2727
Widget body = null,
28-
DragStartBehavior dragStartBehavior = DragStartBehavior.down
28+
DragStartBehavior dragStartBehavior = DragStartBehavior.start
2929
) : base(key: key) {
3030
D.assert(headerSliverBuilder != null);
3131
D.assert(body != null);
@@ -157,7 +157,7 @@ public _NestedScrollViewCustomScrollView(
157157
ScrollController controller,
158158
List<Widget> slivers,
159159
SliverOverlapAbsorberHandle handle,
160-
DragStartBehavior dragStartBehavior = DragStartBehavior.down
160+
DragStartBehavior dragStartBehavior = DragStartBehavior.start
161161
) : base(
162162
scrollDirection: scrollDirection,
163163
reverse: reverse,

Tests/Editor/Paragraph.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,15 @@ RenderBox none() {
6868
return null;
6969
}
7070

71-
RenderBox box(RenderParagraph p, int width = 200, int height = 200) {
71+
RenderBox box(RenderParagraph p, int width = 200, int height = 600) {
7272
return new RenderConstrainedOverflowBox(
7373
minWidth: width,
7474
maxWidth: width,
7575
minHeight: height,
7676
maxHeight: height,
7777
alignment: Alignment.center,
7878
child: p
79-
)
80-
;
79+
);
8180
}
8281

8382
RenderBox flexItemBox(RenderParagraph p, int width = 200, int height = 150) {

0 commit comments

Comments
 (0)