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

Commit c7e0cd0

Browse files
author
Yuncong Zhang
committed
[1.5.4] Upgrade widgets.
1 parent 832f81d commit c7e0cd0

File tree

10 files changed

+200
-86
lines changed

10 files changed

+200
-86
lines changed

Runtime/rendering/editable.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,18 @@ public bool obscureText {
224224

225225
public TextSelectionDelegate textSelectionDelegate;
226226

227+
public ValueListenable<bool> selectionStartInViewport {
228+
get { return this._selectionStartInViewport; }
229+
}
230+
231+
readonly ValueNotifier<bool> _selectionStartInViewport = new ValueNotifier<bool>(true);
232+
233+
public ValueListenable<bool> selectionEndInViewport {
234+
get { return this._selectionEndInViewport; }
235+
}
236+
237+
readonly ValueNotifier<bool> _selectionEndInViewport = new ValueNotifier<bool>(true);
238+
227239
int _extentOffset = -1;
228240

229241
int _baseOffset = -1;

Runtime/ui/painting/txt/font_manager.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void onTextureRebuilt() {
2424
public class FontManager {
2525
readonly Dictionary<string, FontInfo>[] _fonts =
2626
new Dictionary<string, FontInfo>[9 * 2]; // max weight size x max style size
27-
27+
2828
static readonly int defaultFontSize = 14;
2929

3030
public static readonly FontManager instance = new FontManager();
@@ -33,7 +33,7 @@ public class FontManager {
3333
Font.textureRebuilt += this.onFontTextureRebuilt;
3434
}
3535

36-
public void addFont(Font font, string familyName,
36+
public void addFont(Font font, string familyName,
3737
FontWeight fontWeight = null, FontStyle fontStyle = FontStyle.normal) {
3838
fontWeight = fontWeight ?? FontWeight.normal;
3939

@@ -43,7 +43,7 @@ public void addFont(Font font, string familyName,
4343

4444
var fonts = this._getFonts(fontWeight.index, fontStyle);
4545
fonts.TryGetValue(familyName, out var current);
46-
D.assert(current == null || current.font == font,
46+
D.assert(current == null || current.font == font,
4747
() => $"font with key {familyName} {fontWeight} {fontStyle} already exists");
4848
var fontInfo = new FontInfo(font);
4949
fonts[familyName] = fontInfo;
@@ -74,7 +74,7 @@ internal FontInfo getOrCreate(string familyName, FontWeight fontWeight, FontStyl
7474
return fontInfo;
7575
}
7676
}
77-
77+
7878
var osFont = Font.CreateDynamicFontFromOSFont(familyName, defaultFontSize);
7979
osFont.hideFlags = HideFlags.DontSave;
8080
osFont.material.hideFlags = HideFlags.DontSave;
@@ -99,8 +99,7 @@ void onFontTextureRebuilt(Font font) {
9999
}
100100
}
101101

102-
public static class FontExtension
103-
{
102+
public static class FontExtension {
104103
internal static bool getGlyphInfo(this Font font, char ch, out CharacterInfo info, int fontSize,
105104
UnityEngine.FontStyle fontStyle) {
106105
if (fontSize <= 0) {
@@ -111,8 +110,11 @@ internal static bool getGlyphInfo(this Font font, char ch, out CharacterInfo inf
111110
bool success = font.GetCharacterInfo(ch, out info, fontSize, fontStyle);
112111
if (!success) {
113112
if (!char.IsControl(ch)) {
114-
Debug.LogWarning(
115-
$"character info not found from the given font: character '{ch}' (code{(int) ch}) font: ${font.name}");
113+
D.assert(() => {
114+
Debug.LogWarning(
115+
$"character info not found from the given font: character '{ch}' (code{(int) ch}) font: ${font.name}");
116+
return true;
117+
});
116118
}
117119

118120
info = default;
@@ -122,11 +124,12 @@ internal static bool getGlyphInfo(this Font font, char ch, out CharacterInfo inf
122124
return true;
123125
}
124126

125-
internal static void RequestCharactersInTextureSafe(this Font font, string text, int fontSize,
126-
UnityEngine.FontStyle fontStyle = UnityEngine.FontStyle.Normal) {
127+
internal static void RequestCharactersInTextureSafe(this Font font, string text, int fontSize,
128+
UnityEngine.FontStyle fontStyle = UnityEngine.FontStyle.Normal) {
127129
if (fontSize <= 0) {
128130
return;
129131
}
132+
130133
font.RequestCharactersInTexture(text, fontSize, fontStyle);
131134
}
132135
}

Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shader.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using Unity.UIWidgets.foundation;
23
using UnityEngine;
34
using UnityEngine.Rendering;
45

@@ -62,7 +63,10 @@ public static void set(Material mat, BlendMode op) {
6263
mat.SetInt(_dstBlend, (int) UnityEngine.Rendering.BlendMode.Zero);
6364
}
6465
else {
65-
Debug.LogWarning("Not supported BlendMode: " + op + ". Defaults to srcOver");
66+
D.assert(() => {
67+
Debug.LogWarning("Not supported BlendMode: " + op + ". Defaults to srcOver");
68+
return true;
69+
});
6670
mat.SetInt(_srcBlend, (int) UnityEngine.Rendering.BlendMode.One);
6771
mat.SetInt(_dstBlend, (int) UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
6872
}

Runtime/widgets/page_view.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ public PageView(
286286
bool pageSnapping = true,
287287
ValueChanged<int> onPageChanged = null,
288288
List<Widget> children = null,
289-
DragStartBehavior dragStartBehavior = DragStartBehavior.down,
289+
DragStartBehavior dragStartBehavior = DragStartBehavior.start,
290290
IndexedWidgetBuilder itemBuilder = null,
291291
SliverChildDelegate childDelegate = null,
292292
int itemCount = 0
@@ -308,6 +308,11 @@ public PageView(
308308
this.childrenDelegate = new SliverChildListDelegate(children ?? new List<Widget>());
309309
}
310310
}
311+
312+
313+
// TODO: PageView.builder
314+
315+
// TODO: PageView.custom
311316

312317
public readonly Axis scrollDirection;
313318

Runtime/widgets/routes.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ internal void _handleStatusChanged(AnimationStatus status) {
122122

123123
break;
124124
case AnimationStatus.dismissed:
125-
// We might still be the current route if a subclass is controlling the
125+
// We might still be an active route if a subclass is controlling the
126126
// the transition and hits the dismissed status. For example, the iOS
127127
// back gesture drives this animation to the dismissed status before
128128
// popping the navigator.
129-
if (!this.isCurrent) {
129+
if (!this.isActive) {
130130
this.navigator.finalizeRoute(this);
131131
D.assert(this.overlayEntries.isEmpty());
132132
}

Runtime/widgets/scroll_view.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ protected ScrollView(
1919
Key center = null,
2020
float anchor = 0.0f,
2121
float? cacheExtent = null,
22-
DragStartBehavior dragStartBehavior = DragStartBehavior.down
22+
DragStartBehavior dragStartBehavior = DragStartBehavior.start
2323
) : base(key: key) {
2424
D.assert(!(controller != null && primary == true),
2525
() => "Primary ScrollViews obtain their ScrollController via inheritance from a PrimaryScrollController widget. " +
@@ -131,7 +131,7 @@ public CustomScrollView(
131131
float anchor = 0.0f,
132132
float? cacheExtent = null,
133133
List<Widget> slivers = null,
134-
DragStartBehavior dragStartBehavior = DragStartBehavior.down
134+
DragStartBehavior dragStartBehavior = DragStartBehavior.start
135135
) : base(
136136
key: key,
137137
scrollDirection: scrollDirection,
@@ -166,7 +166,7 @@ public BoxScrollView(
166166
bool shrinkWrap = false,
167167
EdgeInsets padding = null,
168168
float? cacheExtent = null,
169-
DragStartBehavior dragStartBehavior = DragStartBehavior.down
169+
DragStartBehavior dragStartBehavior = DragStartBehavior.start
170170
) : base(
171171
key: key,
172172
scrollDirection: scrollDirection,
@@ -218,7 +218,7 @@ public ListView(
218218
bool addRepaintBoundaries = true,
219219
float? cacheExtent = null,
220220
List<Widget> children = null,
221-
DragStartBehavior dragStartBehavior = DragStartBehavior.down
221+
DragStartBehavior dragStartBehavior = DragStartBehavior.start
222222
) : base(
223223
key: key,
224224
scrollDirection: scrollDirection,
@@ -254,7 +254,7 @@ public ListView(
254254
bool addAutomaticKeepAlives = true,
255255
bool addRepaintBoundaries = true,
256256
float? cacheExtent = null,
257-
DragStartBehavior dragStartBehavior = DragStartBehavior.down
257+
DragStartBehavior dragStartBehavior = DragStartBehavior.start
258258
) : base(key: key,
259259
scrollDirection: scrollDirection,
260260
reverse: reverse,
@@ -290,7 +290,7 @@ public static ListView builder(
290290
bool addAutomaticKeepAlives = true,
291291
bool addRepaintBoundaries = true,
292292
float? cacheExtent = null,
293-
DragStartBehavior dragStartBehavior = DragStartBehavior.down
293+
DragStartBehavior dragStartBehavior = DragStartBehavior.start
294294
) {
295295
return new ListView(
296296
key: key,
@@ -327,7 +327,7 @@ public static ListView builder(
327327
bool addAutomaticKeepAlives = true,
328328
bool addRepaintBoundaries = true,
329329
float? cacheExtent = null,
330-
DragStartBehavior dragStartBehavior = DragStartBehavior.down
330+
DragStartBehavior dragStartBehavior = DragStartBehavior.start
331331
) : base(
332332
key: key,
333333
scrollDirection: scrollDirection,
@@ -583,7 +583,7 @@ public GridView(
583583
SliverGridDelegate gridDelegate = null,
584584
SliverChildDelegate childrenDelegate = null,
585585
float? cacheExtent = null,
586-
DragStartBehavior dragStartBehavior = DragStartBehavior.down
586+
DragStartBehavior dragStartBehavior = DragStartBehavior.start
587587
) : base(
588588
key: key,
589589
scrollDirection: scrollDirection,
@@ -614,7 +614,7 @@ public static GridView custom(
614614
SliverGridDelegate gridDelegate = null,
615615
SliverChildDelegate childrenDelegate = null,
616616
float? cacheExtent = null,
617-
DragStartBehavior dragStartBehavior = DragStartBehavior.down
617+
DragStartBehavior dragStartBehavior = DragStartBehavior.start
618618
) {
619619
return new GridView(
620620
key: key,
@@ -649,7 +649,7 @@ public GridView(
649649
bool addRepaintBoundaries = true,
650650
float? cacheExtent = null,
651651
List<Widget> children = null,
652-
DragStartBehavior dragStartBehavior = DragStartBehavior.down
652+
DragStartBehavior dragStartBehavior = DragStartBehavior.start
653653
) : base(
654654
key: key,
655655
scrollDirection: scrollDirection,
@@ -692,7 +692,7 @@ public static GridView count(
692692
bool addRepaintBoundaries = true,
693693
float? cacheExtent = null,
694694
List<Widget> children = null,
695-
DragStartBehavior dragStartBehavior = DragStartBehavior.down
695+
DragStartBehavior dragStartBehavior = DragStartBehavior.start
696696
) {
697697
return new GridView(
698698
key: key,
@@ -732,7 +732,7 @@ public GridView(
732732
bool addRepaintBoundaries = true,
733733
bool addSemanticIndexes = true,
734734
List<Widget> children = null,
735-
DragStartBehavior dragStartBehavior = DragStartBehavior.down
735+
DragStartBehavior dragStartBehavior = DragStartBehavior.start
736736
) : base(
737737
key: key,
738738
scrollDirection: scrollDirection,
@@ -773,7 +773,7 @@ public static GridView extent(
773773
bool addAutomaticKeepAlives = true,
774774
bool addRepaintBoundaries = true,
775775
List<Widget> children = null,
776-
DragStartBehavior dragStartBehavior = DragStartBehavior.down
776+
DragStartBehavior dragStartBehavior = DragStartBehavior.start
777777
) {
778778
return new GridView(
779779
key: key,

Runtime/widgets/scrollable.cs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Unity.UIWidgets.rendering;
1010
using Unity.UIWidgets.scheduler;
1111
using Unity.UIWidgets.ui;
12+
using UnityEngine;
1213

1314
namespace Unity.UIWidgets.widgets {
1415
public delegate Widget ViewportBuilder(BuildContext context, ViewportOffset position);
@@ -20,7 +21,7 @@ public Scrollable(
2021
ScrollController controller = null,
2122
ScrollPhysics physics = null,
2223
ViewportBuilder viewportBuilder = null,
23-
DragStartBehavior dragStartBehavior = DragStartBehavior.down
24+
DragStartBehavior dragStartBehavior = DragStartBehavior.start
2425
) : base(key: key) {
2526
D.assert(viewportBuilder != null);
2627

@@ -360,6 +361,23 @@ void _handleDragCancel() {
360361
D.assert(this._hold == null);
361362
D.assert(this._drag == null);
362363
}
364+
365+
float _targetScrollOffsetForPointerScroll(PointerScrollEvent e) {
366+
float delta = this.widget.axis == Axis.horizontal ? e.delta.dx : e.delta.dy;
367+
return Mathf.Min(Mathf.Max(this.position.pixels + delta, this.position.minScrollExtent),
368+
this.position.maxScrollExtent);
369+
}
370+
371+
// TODO: float _receivedPointerSignal(PointerSignalEvent event) {
372+
// }
373+
374+
void _handlePointerrScroll(PointerEvent e) {
375+
D.assert(e is PointerScrollEvent);
376+
float targetScrollOffset = this._targetScrollOffsetForPointerScroll(e as PointerScrollEvent);
377+
if (targetScrollOffset != this.position.pixels) {
378+
this.position.jumpTo(targetScrollOffset);
379+
}
380+
}
363381

364382
void _disposeHold() {
365383
this._hold = null;
@@ -375,14 +393,17 @@ public override Widget build(BuildContext context) {
375393
Widget result = new _ScrollableScope(
376394
scrollable: this,
377395
position: this.position,
378-
child: new RawGestureDetector(
379-
key: this._gestureDetectorKey,
380-
gestures: this._gestureRecognizers,
381-
behavior: HitTestBehavior.opaque,
382-
child: new IgnorePointer(
383-
key: this._ignorePointerKey,
384-
ignoring: this._shouldIgnorePointer,
385-
child: this.widget.viewportBuilder(context, this.position)
396+
child: new Listener(
397+
// TODO: onPointerSignal: _receivePointerSignal,
398+
child: new RawGestureDetector(
399+
key: this._gestureDetectorKey,
400+
gestures: this._gestureRecognizers,
401+
behavior: HitTestBehavior.opaque,
402+
child: new IgnorePointer(
403+
key: this._ignorePointerKey,
404+
ignoring: this._shouldIgnorePointer,
405+
child: this.widget.viewportBuilder(context, this.position)
406+
)
386407
)
387408
)
388409
);

Runtime/widgets/single_child_scroll_view.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public SingleChildScrollView(
1919
ScrollPhysics physics = null,
2020
ScrollController controller = null,
2121
Widget child = null,
22-
DragStartBehavior dragStartBehavior = DragStartBehavior.down
22+
DragStartBehavior dragStartBehavior = DragStartBehavior.start
2323
) : base(key: key) {
2424
D.assert(!(controller != null && primary == true),
2525
() => "Primary ScrollViews obtain their ScrollController via inheritance from a PrimaryScrollController widget. " +

Runtime/widgets/text.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public Text(string data,
111111
TextOverflow? overflow = null,
112112
float? textScaleFactor = null,
113113
int? maxLines = null) : base(key) {
114-
D.assert(data != null);
114+
D.assert(data != null, () => "A non-null string must be provided to a Text widget.");
115115
this.textSpan = null;
116116
this.data = data;
117117
this.style = style;
@@ -130,7 +130,7 @@ public Text(string data,
130130
TextOverflow? overflow = null,
131131
float? textScaleFactor = null,
132132
int? maxLines = null) : base(key) {
133-
D.assert(textSpan != null);
133+
D.assert(textSpan != null, () => "A non-null TextSpan must be provided to a Text.rich widget.");
134134
this.textSpan = textSpan;
135135
this.data = null;
136136
this.style = style;

0 commit comments

Comments
 (0)