siyao
4 年前
当前提交
e916b0f8
共有 29 个文件被更改,包括 1370 次插入 和 319 次删除
-
30Samples/UIWidgetsSamples_2019_4/Assets/TextTest.unity
-
220Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsExample.cs
-
6com.unity.uiwidgets/Editor/UIWidgetsPanelEditor.cs
-
2com.unity.uiwidgets/Runtime/async/coroutine.cs.meta
-
14com.unity.uiwidgets/Runtime/async/microtask_queue.cs.meta
-
2com.unity.uiwidgets/Runtime/async/timer.cs.meta
-
55com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanel.cs
-
7com.unity.uiwidgets/Runtime/services/message_codecs.cs
-
1engine/src/common/settings.h
-
14engine/src/lib/ui/text/font_collection.cc
-
3engine/src/lib/ui/text/font_collection.h
-
22engine/src/shell/common/engine.cc
-
1engine/src/shell/platform/embedder/embedder.cc
-
1engine/src/shell/platform/embedder/embedder.h
-
37engine/src/shell/platform/unity/uiwidgets_panel.cc
-
3engine/src/shell/platform/unity/uiwidgets_panel.h
-
8Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets.meta
-
1001Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/CupertinoIcons.ttf
-
7Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/CupertinoIcons.ttf.meta
-
7Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/Ranchers-Regular.ttf.meta
-
7Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/Roboto-BlackItalic.ttf.meta
-
7Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/Roboto-Italic.ttf.meta
-
7Samples/UIWidgetsSamples_2019_4/Assets/TextTest.unity.meta
-
11Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsExample.cs.meta
-
11com.unity.uiwidgets/Runtime/material/colors.cs.meta
-
3com.unity.uiwidgets/Runtime/painting/inline_span.cs.meta
-
8com.unity.uiwidgets/Scripts/node_modules.meta
-
8com.unity.uiwidgets/StreamingAssets.meta
-
186Samples/UIWidgetsSamples_2019_4/Assets/TextTest.cs
|
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.animation; |
|||
using Unity.UIWidgets.engine; |
|||
using Unity.UIWidgets.engine2; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using UnityEngine; |
|||
using Color = Unity.UIWidgets.ui.Color; |
|||
using FontStyle = Unity.UIWidgets.ui.FontStyle; |
|||
using ui_ = Unity.UIWidgets.widgets.ui_; |
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.engine2; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using TextStyle = Unity.UIWidgets.painting.TextStyle; |
|||
using ui_ = Unity.UIWidgets.widgets.ui_; |
|||
namespace UIWidgetsSample { |
|||
public class UIWidgetsExample : UIWidgetsPanel { |
|||
|
|||
|
|||
protected void OnEnable() { |
|||
// if you want to use your own font or font icons.
|
|||
// FontManager.instance.addFont(Resources.Load<Font>(path: "path to your font"), "font family name");
|
|||
namespace UIWidgetsSample |
|||
{ |
|||
public class UIWidgetsExample : UIWidgetsPanel |
|||
{ |
|||
protected void OnEnable() |
|||
{ |
|||
base.OnEnable(); |
|||
} |
|||
// load custom font with weight & style. The font weight & style corresponds to fontWeight, fontStyle of
|
|||
// a TextStyle object
|
|||
// FontManager.instance.addFont(Resources.Load<Font>(path: "path to your font"), "Roboto", FontWeight.w500,
|
|||
// FontStyle.italic);
|
|||
protected override void main() |
|||
{ |
|||
ui_.runApp(new MyApp()); |
|||
} |
|||
// add material icons, familyName must be "Material Icons"
|
|||
// FontManager.instance.addFont(Resources.Load<Font>(path: "path to material icons"), "Material Icons");
|
|||
|
|||
base.OnEnable(); |
|||
} |
|||
|
|||
protected override void main() |
|||
{ |
|||
ui_.runApp(new MyApp()); |
|||
} |
|||
class MyApp : StatelessWidget |
|||
{ |
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
return new WidgetsApp( |
|||
home: new ExampleApp(), |
|||
pageRouteBuilder: (settings, builder) => |
|||
new PageRouteBuilder( |
|||
settings: settings, |
|||
pageBuilder: (Buildcontext, animation, secondaryAnimation) => builder(context) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
class MyApp : StatelessWidget |
|||
{ |
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
return new WidgetsApp( |
|||
home: new ExampleApp(), |
|||
pageRouteBuilder: (RouteSettings settings, WidgetBuilder builder) => |
|||
new PageRouteBuilder( |
|||
settings: settings, |
|||
pageBuilder: (BuildContext Buildcontext, Animation<float> animation, |
|||
Animation<float> secondaryAnimation) => builder(context) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
// protected override Widget createWidget() {
|
|||
// return new WidgetsApp(
|
|||
// home: new ExampleApp(),
|
|||
// pageRouteBuilder: (RouteSettings settings, WidgetBuilder builder) =>
|
|||
// new PageRouteBuilder(
|
|||
// settings: settings,
|
|||
// pageBuilder: (BuildContext context, Animation<float> animation,
|
|||
// Animation<float> secondaryAnimation) => builder(context)
|
|||
// )
|
|||
// );
|
|||
// }
|
|||
class ExampleApp : StatefulWidget |
|||
{ |
|||
public ExampleApp(Key key = null) : base(key) |
|||
{ |
|||
} |
|||
class ExampleApp : StatefulWidget { |
|||
public ExampleApp(Key key = null) : base(key) { |
|||
} |
|||
public override State createState() |
|||
{ |
|||
return new ExampleState(); |
|||
} |
|||
} |
|||
public override State createState() { |
|||
return new ExampleState(); |
|||
} |
|||
} |
|||
class ExampleState : State<ExampleApp> |
|||
{ |
|||
int counter; |
|||
class ExampleState : State<ExampleApp> { |
|||
int counter = 0; |
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
return new Container( |
|||
color: Colors.green, |
|||
child: new Column( |
|||
children: new List<Widget> |
|||
{ |
|||
new Text("Counter: " + counter, |
|||
style: new TextStyle(fontSize: 18, fontWeight: FontWeight.w100)), |
|||
new Text("Counter: " + counter, |
|||
style: new TextStyle(fontFamily: "racher", fontSize: 18, fontWeight: FontWeight.w100)), |
|||
new Text("Counter: " + counter, |
|||
style: new TextStyle(fontFamily: "roboto", fontSize: 18, fontWeight: FontWeight.w200)), |
|||
new Text("Counter: " + counter, |
|||
style: new TextStyle(fontFamily: "roboto", fontSize: 18, fontWeight: FontWeight.w300)), |
|||
new Text("Counter: " + counter, |
|||
style: new TextStyle(fontFamily: "roboto", fontSize: 18, fontWeight: FontWeight.w400)), |
|||
new Text("Counter: " + counter, |
|||
style: new TextStyle(fontFamily: "roboto", fontSize: 18, fontWeight: FontWeight.w500)), |
|||
new Text("Counter: " + counter, |
|||
style: new TextStyle(fontFamily: "roboto", fontSize: 18, fontWeight: FontWeight.w600)), |
|||
new Text("Counter: " + counter, |
|||
style: new TextStyle(fontFamily: "roboto", fontSize: 18, fontWeight: FontWeight.w700)), |
|||
new Text("Counter: " + counter, |
|||
style: new TextStyle(fontFamily: "roboto", fontSize: 18, fontWeight: FontWeight.w800)), |
|||
new Text("Counter: " + counter, |
|||
style: new TextStyle(fontFamily: "roboto", fontSize: 18, fontWeight: FontWeight.w900)), |
|||
new Text("Counter: " + counter, |
|||
style: new TextStyle(fontFamily: "roboto", fontSize: 18, fontWeight: FontWeight.w900, |
|||
fontStyle: FontStyle.italic)), |
|||
new Text("Counter: " + counter, |
|||
style: new TextStyle(fontFamily: "roboto", fontSize: 18, fontWeight: FontWeight.w100)), |
|||
new Text("Counter: " + counter, |
|||
style: new TextStyle(fontFamily: "roboto", fontSize: 18, fontWeight: FontWeight.w900)), |
|||
new Text("-----"), |
|||
new Text("Counter: " + counter, |
|||
style: new TextStyle(fontFamily: "robotox", fontSize: 18, fontWeight: FontWeight.w200)), |
|||
new Text("Counter: " + counter, |
|||
style: new TextStyle(fontFamily: "robotox", fontSize: 18, fontWeight: FontWeight.w300)), |
|||
new Text("Counter: " + counter, |
|||
style: new TextStyle(fontFamily: "robotox", fontSize: 18, fontWeight: FontWeight.w400)), |
|||
new Text("Counter: " + counter, |
|||
style: new TextStyle(fontFamily: "robotox", fontSize: 18, fontWeight: FontWeight.w500)), |
|||
new Text("Counter: " + counter, |
|||
style: new TextStyle(fontFamily: "robotox", fontSize: 18, fontWeight: FontWeight.w600)), |
|||
new Text("Counter: " + counter, |
|||
style: new TextStyle(fontFamily: "robotox", fontSize: 18, fontWeight: FontWeight.w700)), |
|||
new Text("Counter: " + counter, |
|||
style: new TextStyle(fontFamily: "robotox", fontSize: 18, fontWeight: FontWeight.w800)), |
|||
new Text("Counter: " + counter, |
|||
style: new TextStyle(fontFamily: "robotox", fontSize: 18, fontWeight: FontWeight.w900)), |
|||
new Text("Counter: " + counter, |
|||
style: new TextStyle(fontFamily: "robotox", fontSize: 18, fontWeight: FontWeight.w900, |
|||
fontStyle: FontStyle.italic)), |
|||
new Text("Counter: " + counter + (char) 0xf472 + (char) 0xf442 + (char) 0xf43b, |
|||
style: new TextStyle(fontFamily: "CupertinoIcons", fontSize: 18)), |
|||
public override Widget build(BuildContext context) { |
|||
return new Container( |
|||
color: Colors.green, |
|||
child: new Column( |
|||
children: new List<Widget> { |
|||
new Text("Counter: " + this.counter), |
|||
new GestureDetector( |
|||
onTap: () => { |
|||
this.setState(() |
|||
=> { |
|||
this.counter++; |
|||
}); |
|||
}, |
|||
child: new Container( |
|||
padding: EdgeInsets.symmetric(20, 20), |
|||
color: this.counter % 2 == 0 ? Colors.blue : Colors.red, |
|||
child: new Text("Click Me") |
|||
) |
|||
) |
|||
} |
|||
new GestureDetector( |
|||
onTap: () => |
|||
{ |
|||
setState(() |
|||
=> |
|||
{ |
|||
counter++; |
|||
}); |
|||
}, |
|||
child: new Container( |
|||
padding: EdgeInsets.symmetric(20, 20), |
|||
color: counter % 2 == 0 ? Colors.blue : Colors.red, |
|||
child: new Text("Click Me", |
|||
style: new TextStyle(fontFamily: "racher", fontWeight: FontWeight.w100)) |
|||
) |
|||
) |
|||
} |
|||
); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 6d95e65550134a478f8f77093fc6d6f1 |
|||
timeCreated: 1535723558 |
|||
fileFormatVersion: 2 |
|||
guid: 009230d259197ba4ebf6f9590c8b6009 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 0e116be5168fd954b911f42dfdd513e0 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1001
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/CupertinoIcons.ttf
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 1d9b44ef4202d544689bb9a8322eb32e |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: e9d8d9b0e7292d944b164abae466da23 |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: e58e756ae69d77245ada723bd63636e8 |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: bb7f0fe585121134387b937c917fcba9 |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: c589e2cf933dc4042b07f7290e302402 |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 169ec79ce040653478e1a7725f34bbe1 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: dfc0e036c07e1441d8dbd3158bb6f923 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 575cf08436e24fa88feb437a5034d766 |
|||
timeCreated: 1602582475 |
|
|||
fileFormatVersion: 2 |
|||
guid: 7d3f82c412afe4d419f727fcdca86158 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: ab11c80750d2b144daf3455bc8ff7b19 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using Unity.UIWidgets.async2; |
|||
using Unity.UIWidgets.engine2; |
|||
using Unity.UIWidgets.ui; |
|||
using UnityEngine; |
|||
using Canvas = Unity.UIWidgets.ui.Canvas; |
|||
using Color = Unity.UIWidgets.ui.Color; |
|||
using Path = System.IO.Path; |
|||
using Rect = Unity.UIWidgets.ui.Rect; |
|||
|
|||
class TextTest : UIWidgetsPanel |
|||
{ |
|||
private bool check = true; |
|||
|
|||
void beginFrame(TimeSpan timeStamp) |
|||
{ |
|||
// The timeStamp argument to beginFrame indicates the timing information we
|
|||
// should use to clock our animations. It's important to use timeStamp rather
|
|||
// than reading the system time because we want all the parts of the system to
|
|||
// coordinate the timings of their animations. If each component read the
|
|||
// system clock independently, the animations that we processed later would be
|
|||
// slightly ahead of the animations we processed earlier.
|
|||
|
|||
// PAINT
|
|||
|
|||
Rect paintBounds = Offset.zero & (Window.instance.physicalSize / Window.instance.devicePixelRatio); |
|||
PictureRecorder recorder = new PictureRecorder(); |
|||
Canvas canvas = new Canvas(recorder, paintBounds); |
|||
canvas.translate(paintBounds.width / 2.0f, paintBounds.height / 2.0f); |
|||
|
|||
// Here we determine the rotation according to the timeStamp given to us by
|
|||
// the engine.
|
|||
float t = (float) timeStamp.TotalMilliseconds / 1800.0f; |
|||
canvas.rotate(Mathf.PI * (t % 2.0f)); |
|||
|
|||
var paint = new Paint(); |
|||
paint.color = Color.fromARGB(100, 100, 100, 0); |
|||
canvas.drawRect(Rect.fromLTRB(0, 0, 100.0f, 100.0f), paint); |
|||
Draw(canvas); |
|||
|
|||
Picture picture = recorder.endRecording(); |
|||
|
|||
// COMPOSITE
|
|||
|
|||
float devicePixelRatio = Window.instance.devicePixelRatio; |
|||
var deviceTransform = new float[16]; |
|||
deviceTransform[0] = devicePixelRatio; |
|||
deviceTransform[5] = devicePixelRatio; |
|||
deviceTransform[10] = 1.0f; |
|||
deviceTransform[15] = 1.0f; |
|||
SceneBuilder sceneBuilder = new SceneBuilder(); |
|||
|
|||
sceneBuilder.pushTransform(deviceTransform); |
|||
sceneBuilder.addPicture(Offset.zero, picture); |
|||
sceneBuilder.pop(); |
|||
Window.instance.render(sceneBuilder.build()); |
|||
|
|||
// After rendering the current frame of the animation, we ask the engine to
|
|||
// schedule another frame. The engine will call beginFrame again when its time
|
|||
// to produce the next frame.
|
|||
Window.instance.scheduleFrame(); |
|||
} |
|||
|
|||
void Draw(Canvas canvas) |
|||
{ |
|||
if (check) |
|||
{ |
|||
foreach (var font in fonts) |
|||
{ |
|||
var path = Path.Combine(Application.streamingAssetsPath, font.path); |
|||
var fontFile = File.ReadAllBytes(path); |
|||
ui_.loadFontFromList(fontFile, font.name).then(value => |
|||
{ |
|||
Debug.Log("finish loading"); |
|||
return FutureOr.nil; |
|||
}); |
|||
} |
|||
check = false; |
|||
} |
|||
|
|||
var style = new ParagraphStyle( |
|||
fontFamily: "Arial", |
|||
height: 4, |
|||
strutStyle: new StrutStyle(fontFamily: "ranchers", |
|||
fontFamilyFallback: new List<string>() {"Roboto-RegularB"}, |
|||
fontSize: 30), |
|||
ellipsis: "and so on..." |
|||
); |
|||
|
|||
|
|||
var pb = new ParagraphBuilder(style); |
|||
pb.addText("just for testxxx\n"); |
|||
var ts_roboto_regular = new TextStyle( |
|||
color: new Color(0xF000000F), |
|||
decoration: TextDecoration.lineThrough, |
|||
decorationStyle: TextDecorationStyle.doubleLine, |
|||
fontFamily: "Roboto-Regular", |
|||
fontFamilyFallback: new List<string>() {"ranchers"}, |
|||
fontSize: 30, |
|||
height: 1.5f |
|||
); |
|||
pb.pushStyle(ts_roboto_regular); |
|||
pb.addText("just for test\n"); |
|||
var ts_roboto_regular_bold = new TextStyle( |
|||
color: new Color(0xF000000F), |
|||
decoration: TextDecoration.lineThrough, |
|||
decorationStyle: TextDecorationStyle.doubleLine, |
|||
fontFamily: "Roboto-RegularB", |
|||
fontSize: 30, |
|||
height: 1.5f |
|||
); |
|||
pb.pushStyle(ts_roboto_regular_bold); |
|||
pb.addText("just for test\n"); |
|||
var ts_rachers = new TextStyle( |
|||
color: new Color(0xF000000F), |
|||
decoration: TextDecoration.lineThrough, |
|||
decorationStyle: TextDecorationStyle.doubleLine, |
|||
fontFamily: "ranchers", |
|||
fontSize: 30, |
|||
height: 1.5f |
|||
); |
|||
pb.pushStyle(ts_rachers); |
|||
pb.addText("just for test\n"); |
|||
var ts = new TextStyle( |
|||
color: new Color(0xFFFF00F0), |
|||
decoration: TextDecoration.lineThrough, |
|||
decorationStyle: TextDecorationStyle.doubleLine, |
|||
fontFamily: "Arial", |
|||
fontSize: 30, |
|||
height: 1.5f |
|||
); |
|||
pb.pushStyle(ts); |
|||
pb.addText("just for test\n 中文测试 分段测试 分段测试 分段测试 分段测试 分段测试 分段测试 分段测试\n1234"); |
|||
var ts2 = new TextStyle( |
|||
decoration: TextDecoration.underline, |
|||
decorationStyle: TextDecorationStyle.dashed, |
|||
fontFamily: "Arial", |
|||
fontSize: 40, |
|||
height: 1.5f, |
|||
background: new Paint() |
|||
{ |
|||
color = new Color(0xAAFF7F00), |
|||
}, |
|||
foreground: new Paint() |
|||
{ |
|||
color = new Color(0xAAFFFF00) |
|||
} |
|||
); |
|||
pb.pushStyle(ts2); |
|||
pb.addText("test push one more style"); |
|||
pb.pop(); |
|||
pb.addText("test pop style"); |
|||
pb.addPlaceholder(10, 10, PlaceholderAlignment.baseline, TextBaseline.alphabetic); |
|||
var p = pb.build(); |
|||
p.layout(new ParagraphConstraints(300)); |
|||
var wordBoundary = p.getWordBoundary(new TextPosition(10)); |
|||
Debug.Log(wordBoundary); |
|||
var positionForOffset = p.getPositionForOffset(new Offset(10, 1)); |
|||
Debug.Log(positionForOffset); |
|||
var lineBoundary = p.getLineBoundary(new TextPosition(10)); |
|||
Debug.Log(lineBoundary); |
|||
foreach (var textBox in p.getBoxesForPlaceholders()) |
|||
{ |
|||
Debug.Log($"{textBox.bottom} {textBox.direction} {textBox.left} {textBox.right}"); |
|||
} |
|||
foreach (var textBox in p.getBoxesForRange(1, 20)) |
|||
{ |
|||
Debug.Log($"{textBox.bottom} {textBox.direction} {textBox.left} {textBox.right}"); |
|||
} |
|||
|
|||
foreach (var lineMetrics in p.computeLineMetrics()) |
|||
{ |
|||
Debug.Log($"{lineMetrics.height} {lineMetrics.lineNumber}"); |
|||
} |
|||
|
|||
canvas.drawParagraph(p, new Offset(-100, -100)); |
|||
} |
|||
|
|||
protected override void main() |
|||
{ |
|||
Window.instance.onBeginFrame = beginFrame; |
|||
Window.instance.scheduleFrame(); |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue