GitHub
6 年前
当前提交
30995c89
共有 8 个文件被更改,包括 207 次插入 和 8 次删除
-
1Runtime/painting/basic_types.cs
-
23Runtime/painting/text_span.cs
-
59Runtime/rendering/paragraph.cs
-
2Samples/UIWidgetSample/txt/TextSpanGesture.cs
-
26Runtime/gestures/hover.cs
-
11Runtime/gestures/hover.cs.meta
-
82Samples/UIWidgetSample/HoverRecognizerSample.cs
-
11Samples/UIWidgetSample/HoverRecognizerSample.cs.meta
|
|||
using Unity.UIWidgets.foundation; |
|||
|
|||
namespace Unity.UIWidgets.gestures { |
|||
|
|||
public delegate void PointerHoverEnterCallback(PointerHoverEvent evt); |
|||
|
|||
public delegate void PointerHoverLeaveCallback(); |
|||
|
|||
public class HoverRecognizer : DiagnosticableTree { |
|||
public HoverRecognizer(object debugOwner = null) { |
|||
this.debugOwner = debugOwner; |
|||
} |
|||
|
|||
readonly object debugOwner; |
|||
|
|||
public PointerHoverEnterCallback OnPointerEnter; |
|||
|
|||
public PointerHoverLeaveCallback OnPointerLeave; |
|||
|
|||
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) { |
|||
base.debugFillProperties(properties); |
|||
properties.add(new DiagnosticsProperty<object>("debugOwner", this.debugOwner, |
|||
defaultValue: Diagnostics.kNullDefaultValue)); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 0482dd5944bd647da9d8a1a32a86801b |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.gestures; |
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.rendering; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using UnityEngine; |
|||
|
|||
namespace UIWidgetsSample { |
|||
public class HoverRecognizerSample : UIWidgetsSamplePanel { |
|||
protected override Widget createWidget() { |
|||
return new MaterialApp( |
|||
showPerformanceOverlay: false, |
|||
home: new HoverMainPanel() |
|||
); |
|||
} |
|||
|
|||
protected override void OnEnable() { |
|||
FontManager.instance.addFont(Resources.Load<Font>(path: "MaterialIcons-Regular"), "Material Icons"); |
|||
base.OnEnable(); |
|||
} |
|||
} |
|||
|
|||
class HoverMainPanel : StatefulWidget { |
|||
public override State createState() { |
|||
return new HoverMainPanelState(); |
|||
} |
|||
} |
|||
|
|||
class HoverMainPanelState : State<HoverMainPanel> { |
|||
bool hoverActivated = false; |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
return new Scaffold( |
|||
appBar: new AppBar( |
|||
title: new Center( |
|||
child: new Text("Test Hover Widget") |
|||
) |
|||
), |
|||
body: new Card( |
|||
color: Colors.white, |
|||
child: new Center( |
|||
child: new Column( |
|||
mainAxisSize: MainAxisSize.min, |
|||
crossAxisAlignment: CrossAxisAlignment.center, |
|||
children: new List<Widget> { |
|||
new Icon(this.hoverActivated ? Unity.UIWidgets.material.Icons.pool : Unity.UIWidgets.material.Icons.directions_walk, size: 128.0f), |
|||
new RichText( |
|||
text: new TextSpan( |
|||
text: "Test <", |
|||
style: new TextStyle(color: Colors.black), |
|||
children: new List<TextSpan>() { |
|||
new TextSpan( |
|||
text: "Hover Me", |
|||
style: new TextStyle( |
|||
color: Colors.green, |
|||
decoration: TextDecoration.underline |
|||
), |
|||
hoverRecognizer: new HoverRecognizer { |
|||
OnPointerEnter = evt => { |
|||
this.setState(() => { this.hoverActivated = true; }); |
|||
}, |
|||
OnPointerLeave = () => { |
|||
this.setState(() => { this.hoverActivated = false;}); |
|||
} |
|||
} |
|||
), |
|||
new TextSpan( |
|||
text: ">" |
|||
) |
|||
} |
|||
) |
|||
) |
|||
} |
|||
) |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: aeab7b6e566d741a8a11a4400d52e708 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue