浏览代码

Merge branch 'dragdrop_fix' into 'master'

code style cleanup + more

See merge request upm-packages/ui-widgets/com.unity.uiwidgets!39
/main
Shenhua Gu 6 年前
当前提交
6623a936
共有 19 个文件被更改,包括 207 次插入150 次删除
  1. 62
      Runtime/gestures/multidrag.cs
  2. 50
      Runtime/rendering/custom_layout.cs
  3. 3
      Samples/ReduxSample/CounterApp/CounterAppCanvas.cs
  4. 5
      Samples/ReduxSample/ObjectFinder/FinderGameObject.cs
  5. 2
      Samples/ReduxSample/ObjectFinder/Middleware.cs
  6. 3
      Samples/ReduxSample/ObjectFinder/ObjectFinderApp.cs
  7. 5
      Samples/ReduxSample/ObjectFinder/Reducer.cs
  8. 3
      Samples/ReduxSample/ObjectFinder/StoreProvider.cs
  9. 2
      Samples/ReduxSample/redux/store.cs
  10. 10
      Samples/ReduxSample/redux/widget_redux.cs
  11. 2
      Samples/ReduxSample/redux_logging/redux_logging.cs
  12. 6
      Samples/UIWidgetSample/AsScreenCanvas.cs
  13. 37
      Samples/UIWidgetSample/CustomPaintCanvas.cs
  14. 2
      Samples/UIWidgetSample/MaterialCanvas.cs
  15. 112
      Samples/UIWidgetSample/NavigationCanvas.cs
  16. 28
      Samples/UIWidgetSample/PageViewCanvas.cs
  17. 2
      Samples/UIWidgetSample/SelectOnStart.cs
  18. 14
      Samples/UIWidgetSample/TextInputCanvas.cs
  19. 9
      Samples/UIWidgetSample/ToDoAppCanvas.cs

62
Runtime/gestures/multidrag.cs


Drag _client;
public Offset pendingDelta => this._pendingDelta;
public Offset pendingDelta {
get { return this._pendingDelta; }
}
public Offset _pendingDelta = Offset.zero;

public void _move(PointerMoveEvent pEvent) {
D.assert(this._arenaEntry != null);
if (!pEvent.synthesized)
if (!pEvent.synthesized) {
}
if (this._client != null) {
D.assert(this.pendingDelta == null);
this._client.update(new DragUpdateDetails(

public override void acceptGesture(int pointer) {
D.assert(this._pointers != null);
T state = this._pointers[pointer];
if (state == null)
if (state == null) {
}
state.accepted((Offset initialPosition) => this._startDrag(initialPosition, pointer));
}

D.assert(state != null);
D.assert(state._pendingDelta != null);
Drag drag = null;
if (this.onStart != null)
if (this.onStart != null) {
if (drag != null)
}
if (drag != null) {
else
}
else {
}
return drag;
}

}
void _removeState(int pointer) {
if (this._pointers == null)
if (this._pointers == null) {
}
D.assert(this._pointers.ContainsKey(pointer));
GestureBinding.instance.pointerRouter.removeRoute(pointer, this._handleEvent);
this._pointers[pointer].dispose();

public override void checkForResolutionAfterMove() {
D.assert(this.pendingDelta != null);
if (this.pendingDelta.distance > Constants.kTouchSlop)
if (this.pendingDelta.distance > Constants.kTouchSlop) {
}
}
public override void accepted(GestureMultiDragStartCallback starter) {

return new _ImmediatePointerState(pEvent.position);
}
public override string debugDescription => "multidrag";
public override string debugDescription {
get { return "multidrag"; }
}
}
public class _HorizontalPointerState : MultiDragPointerState {

public override void checkForResolutionAfterMove() {
D.assert(this.pendingDelta != null);
if (this.pendingDelta.dx.abs() > Constants.kTouchSlop)
if (this.pendingDelta.dx.abs() > Constants.kTouchSlop) {
}
}
public override void accepted(GestureMultiDragStartCallback starter) {

return new _HorizontalPointerState(pEvent.position);
}
public override string debugDescription => "horizontal multidrag";
public override string debugDescription {
get { return "horizontal multidrag"; }
}
}

public override void checkForResolutionAfterMove() {
D.assert(this.pendingDelta != null);
if (this.pendingDelta.dy.abs() > Constants.kTouchSlop)
if (this.pendingDelta.dy.abs() > Constants.kTouchSlop) {
}
}
public override void accepted(GestureMultiDragStartCallback starter) {

return new _VerticalPointerState(pEvent.position);
}
public override string debugDescription => "vertical multidrag";
public override string debugDescription {
get { return "vertical multidrag"; }
}
}
public class _DelayedPointerState : MultiDragPointerState {

public override void accepted(GestureMultiDragStartCallback starter) {
D.assert(this._starter == null);
if (this._timer == null)
if (this._timer == null) {
else
}
else {
}
}
public override void checkForResolutionAfterMove() {

public DelayedMultiDragGestureRecognizer(
TimeSpan? delay = null,
object debugOwner = null) : base(debugOwner: debugOwner) {
if (delay == null)
if (delay == null) {
}
this.delay = delay;
}

return new _DelayedPointerState(pEvent.position, this.delay);
}
public override string debugDescription => "long multidrag";
public override string debugDescription {
get { return "long multidrag"; }
}
}
}

50
Runtime/rendering/custom_layout.cs


public Size layoutChild(object childId, BoxConstraints constraints) {
RenderBox child = this._idToChild[childId];
D.assert(() => {
if (child == null)
if (child == null) {
}
if (!this._debugChildrenNeedingLayout.Remove(child))
if (!this._debugChildrenNeedingLayout.Remove(child)) {
}
try {
D.assert(constraints.debugAssertIsValid(isAppliedConstraint: true));

public void positionChild(object childId, Offset offset) {
RenderBox child = this._idToChild[childId];
D.assert(() => {
if (child == null)
if (child == null) {
}
if (offset == null)
if (offset == null) {
}
return true;
});

while (child != null) {
MultiChildLayoutParentData childParentData = (MultiChildLayoutParentData) child.parentData;
D.assert(() => {
if (childParentData.id == null)
if (childParentData.id == null) {
}
return true;
});

this.performLayout(size);
D.assert(() => {
if (this._debugChildrenNeedingLayout.isNotEmpty()) {
if (this._debugChildrenNeedingLayout.Count > 1)
if (this._debugChildrenNeedingLayout.Count > 1) {
else
}
else {
}
}
return true;

}
public override void setupParentData(RenderObject child) {
if (!(child.parentData is MultiChildLayoutParentData))
if (!(child.parentData is MultiChildLayoutParentData)) {
}
get => this._delegate;
get { return this._delegate; }
if (this._delegate == value)
if (this._delegate == value) {
if (value.GetType() != this._delegate.GetType() || value.shouldRelayout(this._delegate))
}
if (value.GetType() != this._delegate.GetType() || value.shouldRelayout(this._delegate)) {
}
this._delegate = value;
}
}

protected override double computeMinIntrinsicWidth(double height) {
double width = this._getSize(BoxConstraints.tightForFinite(height: height)).width;
if (width.isFinite())
if (width.isFinite()) {
}
if (width.isFinite())
if (width.isFinite()) {
}
if (height.isFinite())
if (height.isFinite()) {
}
if (height.isFinite())
if (height.isFinite()) {
}
return 0.0;
}

3
Samples/ReduxSample/CounterApp/CounterAppCanvas.cs


if (inc == null) {
return state;
}
return new CouterState(inc.amount + state.count);
}

);
}
}
}
}

5
Samples/ReduxSample/ObjectFinder/FinderGameObject.cs


var selectedId = StoreProvider.store.state.selected;
if (selectedId == this.GetInstanceID()) {
this.GetComponent<MeshRenderer>().material.color = new Color(1.0f, 0, 0, 1.0f);
} else {
}
else {
this.GetComponent<MeshRenderer>().material.color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
}
}

}
}
}
}

2
Samples/ReduxSample/ObjectFinder/Middleware.cs


};
}
}
}
}

3
Samples/ReduxSample/ObjectFinder/ObjectFinderApp.cs


//scheduler.SchedulerBinding.instance.scheduleFrameCallback
Window.instance.scheduleMicrotask(() => this.widget.doSearch(""));
}
this._controller.addListener(this.textChange);
}

);
}
}
}
}

5
Samples/ReduxSample/ObjectFinder/Reducer.cs


selected = 0;
}
}
if (action is SelectObjectAction) {
return new FinderAppState() {
objects = state.objects,

}
}

3
Samples/ReduxSample/ObjectFinder/StoreProvider.cs


if (_store != null) {
return _store;
}
var middlewares = new Middleware<FinderAppState>[] {
ReduxLogging.Create<FinderAppState>(),
GameFinderMiddleware.Create(),

}
}
}
}
}

2
Samples/ReduxSample/redux/store.cs


return action;
}
}
}
}

10
Samples/ReduxSample/redux/widget_redux.cs


if (provider == null) {
throw new UIWidgetsError("StoreProvider is missing");
}
return provider._store;
}

oldStore.stateChanged -= this._handleStateChanged;
this._init();
}
base.didUpdateWidget(oldWidget);
}

void _handleStateChanged(State state) {
if (Window.hasInstance) {
this._innerStateChanged(state);
} else {
}
else {
using (WindowProvider.of(this.context).getScope()) {
this._innerStateChanged(state);
}

if (!this.widget.shouldRebuild(preValue, this.latestValue)) {
return;
}
} else if (this.widget.distinct) {
}
else if (this.widget.distinct) {
if (Equals(preValue, this.latestValue)) {
return;
}

return this.widget.builder(context, this.latestValue);
}
}
}
}

2
Samples/ReduxSample/redux_logging/redux_logging.cs


};
}
}
}
}

6
Samples/UIWidgetSample/AsScreenCanvas.cs


if (pixels <= headerHeight) {
this.setState(() => { this._offsetY = pixels / 2.0; });
}
} else {
}
else {
return true;
}

public static readonly Color header = new Color(0xFF060B0C);
}
}
}
}

37
Samples/UIWidgetSample/CustomPaintCanvas.cs


using Unity.UIWidgets.widgets;
namespace UIWidgetsSample {
public class CustomPaintCanvas: WidgetCanvas {
public class CustomPaintCanvas : WidgetCanvas {
);
);
}
}

canvas.drawLine(new Offset(0, offsetY), new Offset(size.width, offsetY),
paint);
}
// draw a arrow line
canvas.save();
canvas.rotate(0.4);

new Paint(){
new Paint() {
var path = new Path();
var arrowPaint = new Paint() {
color = new Color(0xFFFF0000),
style = PaintingStyle.fill
};
path.moveTo(100, 0);
path.lineTo(100, 5);
path.lineTo(120, 0);
path.lineTo(100, -5);
path.close();
canvas.drawPath(path, arrowPaint);
canvas.restore();
var path = new Path();
var arrowPaint = new Paint() {
color = new Color(0xFFFF0000),
style = PaintingStyle.fill
};
path.moveTo(100, 0);
path.lineTo(100, 5);
path.lineTo(120, 0);
path.lineTo(100, -5);
path.close();
canvas.drawPath(path, arrowPaint);
canvas.restore();
}
public override bool shouldRepaint(CustomPainter oldDelegate) {

2
Samples/UIWidgetSample/MaterialCanvas.cs


color: Colors.blue,
splashColor: new Color(0xFFFF0011),
highlightColor: new Color(0x88FF0011),
onPressed: () => { Debug.Log("pressed here");}
onPressed: () => { Debug.Log("pressed here"); }
)
)
);

112
Samples/UIWidgetSample/NavigationCanvas.cs


using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using Color = Unity.UIWidgets.ui.Color;
protected override string initialRoute => "/";
protected override string initialRoute {
get { return "/"; }
}
protected override Dictionary<string, WidgetBuilder> routes => new Dictionary<string, WidgetBuilder> {
{"/", (context) => new HomeScreen()},
{"/detail", (context) => new DetailScreen()}
};
protected override TextStyle textStyle => new TextStyle(fontSize: 24);
protected override PageRouteFactory pageRouteBuilder => (RouteSettings settings, WidgetBuilder builder) =>
new PageRouteBuilder(
settings: settings,
pageBuilder: (BuildContext context, Unity.UIWidgets.animation.Animation<double> animation,
Unity.UIWidgets.animation.Animation<double> secondaryAnimation) => builder(context),
transitionsBuilder: (BuildContext context, Animation<double>
animation, Animation<double> secondaryAnimation, Widget child) => new _FadeUpwardsPageTransition(
routeAnimation: animation,
child: child
)
);
protected override Dictionary<string, WidgetBuilder> routes {
get {
return new Dictionary<string, WidgetBuilder> {
{"/", (context) => new HomeScreen()},
{"/detail", (context) => new DetailScreen()}
};
}
}
protected override TextStyle textStyle {
get { return new TextStyle(fontSize: 24); }
}
protected override PageRouteFactory pageRouteBuilder {
get {
return (RouteSettings settings, WidgetBuilder builder) =>
new PageRouteBuilder(
settings: settings,
pageBuilder: (BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation) => builder(context),
transitionsBuilder: (BuildContext context, Animation<double>
animation, Animation<double> secondaryAnimation, Widget child) =>
new _FadeUpwardsPageTransition(
routeAnimation: animation,
child: child
)
);
}
}
body:new Container(
body: new Container(
child: new Center(child: new CustomButton(onPressed: () => {
Navigator.pushName(context, "/detail");
}, child: new Text("Go to Detail"))
child: new Center(
child: new CustomButton(onPressed: () => { Navigator.pushName(context, "/detail"); },
child: new Text("Go to Detail"))
);
);
class DetailScreen : StatelessWidget {
public override Widget build(BuildContext context) {
return new NavigationPage(

title: "Detail");
}
}
return new Center(child:new Container(
return new Center(child: new Container(
color: new Color(0xFFFF0000),
width: 100,
height: 80,

}
class _FadeUpwardsPageTransition : StatelessWidget {
) :base(key: key) {
) : base(key: key) {
this._positionAnimation = _bottomUpTween.chain(_fastOutSlowInTween).animate(routeAnimation);
this._opacityAnimation = _easeInTween.animate(routeAnimation);
this.child = child;

begin: new Offset(0.0, 0.25),
end: Offset.zero
);
public override Widget build(BuildContext context) {
return new SlideTransition(
position: this._positionAnimation,

);
}
}
class NavigationPage: StatelessWidget {
class NavigationPage : StatelessWidget {
public readonly Widget body;
public readonly string title;

}
back = new CustomButton(onPressed: () => { Navigator.pop(context); },
back = new CustomButton(onPressed: () => { Navigator.pop(context); },
back = new Column(mainAxisAlignment: MainAxisAlignment.center, children: new List<Widget>(){back});
back = new Column(mainAxisAlignment: MainAxisAlignment.center, children: new List<Widget>() {back});
new ConstrainedBox(constraints: new BoxConstraints(maxHeight:80),
child:new DecoratedBox(
new ConstrainedBox(constraints: new BoxConstraints(maxHeight: 80),
child: new DecoratedBox(
child:new NavigationToolbar(leading: back,
middle: new Text(this.title, textAlign: TextAlign.center))))
,
new Flexible(child:this.body)
}
)
);
child: new NavigationToolbar(leading: back,
middle: new Text(this.title, textAlign: TextAlign.center)))),
new Flexible(child: this.body)
}
)
);
}
}

28
Samples/UIWidgetSample/PageViewCanvas.cs


using Unity.UIWidgets.widgets;
namespace UIWidgetsSample {
public class PageViewCanvas : WidgetCanvas {
public class PageViewCanvas : WidgetCanvas {
children: new List<Widget>(){
new Container(
color: new Color(0xFFE91E63)
),
new Container(
color: new Color(0xFF00BCD4)
),
new Container(
color: new Color(0xFF673AB7)
)
}
));
children: new List<Widget>() {
new Container(
color: new Color(0xFFE91E63)
),
new Container(
color: new Color(0xFF00BCD4)
),
new Container(
color: new Color(0xFF673AB7)
)
}
));
}
}
}

2
Samples/UIWidgetSample/SelectOnStart.cs


EventSystem.current.SetSelectedGameObject(this.gameObject);
}
}
}
}

14
Samples/UIWidgetSample/TextInputCanvas.cs


using System;
using System.Collections.Generic;
using System.Collections.Generic;
using Unity.UIWidgets.service;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using TextStyle = Unity.UIWidgets.painting.TextStyle;

}
class _TextInputSampleState : State<TextInputSample> {
TextEditingController titleController = new TextEditingController("");
TextEditingController descController = new TextEditingController("");
FocusNode _titleFocusNode;

}
Widget title() {
return new Container(child:new Text(this.widget.title ?? "", textAlign: TextAlign.center,
style: new TextStyle(fontSize: 24, fontWeight: FontWeight.w700)), margin:EdgeInsets.only(bottom:20));
return new Container(child: new Text(this.widget.title ?? "", textAlign: TextAlign.center,
style: new TextStyle(fontSize: 24, fontWeight: FontWeight.w700)),
margin: EdgeInsets.only(bottom: 20));
}
Widget titleInput() {

}
}
}
}
}

9
Samples/UIWidgetSample/ToDoAppCanvas.cs


using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using Color = Unity.UIWidgets.ui.Color;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace UIWidgetsSample {

padding: EdgeInsets.all(10),
child: new Text("Add", style: new TextStyle(
fontSize: 20, color: Color.fromARGB(255, 255, 255, 255), fontWeight: FontWeight.w700
)), onPressed: () => {
this._addItem();
})
)), onPressed: () => { this._addItem(); })
}
)
);

this.setState(() => {
text = text ?? this.controller.text;
text = text ?? this.controller.text;
if (text != "") {
this.items.Add(new ToDoItem()
{id = this.nextId++, content = text});

);
}
}
}
}
正在加载...
取消
保存