1
+ using System . Collections . Generic ;
2
+ using Unity . UIWidgets . foundation ;
3
+ using Unity . UIWidgets . material ;
4
+ using Unity . UIWidgets . painting ;
5
+ using Unity . UIWidgets . rendering ;
6
+ using Unity . UIWidgets . ui ;
7
+ using Unity . UIWidgets . widgets ;
8
+ using UnityEngine ;
9
+ using Color = Unity . UIWidgets . ui . Color ;
10
+ using FontStyle = Unity . UIWidgets . ui . FontStyle ;
11
+ using Material = Unity . UIWidgets . material . Material ;
12
+
13
+ namespace UIWidgetsSample
14
+ {
15
+ public class BenchMarkLayout : UIWidgetsSamplePanel
16
+ {
17
+ protected override Widget createWidget ( )
18
+ {
19
+ return new MaterialApp (
20
+ showPerformanceOverlay : false ,
21
+ home : new Material (
22
+ child : new BenchMarkLayoutWidget ( ) ) ,
23
+ builder : ( _ , child ) =>
24
+ {
25
+ return new Builder ( builder :
26
+ context =>
27
+ {
28
+ return new MediaQuery (
29
+ data : MediaQuery . of ( context ) . copyWith (
30
+ textScaleFactor : 1.0f
31
+ ) ,
32
+ child : child ) ;
33
+ } ) ;
34
+ } ) ;
35
+ }
36
+
37
+ protected override void OnEnable ( )
38
+ {
39
+ base . OnEnable ( ) ;
40
+ FontManager . instance . addFont ( Resources . Load < Font > ( path : "MaterialIcons-Regular" ) , "Material Icons" ) ;
41
+ }
42
+ }
43
+
44
+ internal class BenchMarkLayoutWidget : StatefulWidget
45
+ {
46
+ public BenchMarkLayoutWidget ( Key key = null ) : base ( key )
47
+ {
48
+ }
49
+
50
+ public override State createState ( )
51
+ {
52
+ return new BenchMarkLayoutWidgetState ( ) ;
53
+ }
54
+ }
55
+
56
+ internal class BenchMarkLayoutWidgetState : State < BenchMarkLayoutWidget >
57
+ {
58
+ private int width = 260 ;
59
+ private bool visible = true ;
60
+
61
+ private Widget richtext = new Container (
62
+ child : new RichText (
63
+ text : new TextSpan ( "" , children :
64
+ new List < TextSpan > ( )
65
+ {
66
+ new TextSpan ( "Real-time 3D revolutioni\t 淡粉色的方式地方\t zes the animation pipeline " ) ,
67
+ new TextSpan ( style : new TextStyle ( color : Color . fromARGB ( 255 , 255 , 0 , 0 ) ) ,
68
+ text : "for Disney Television Animation's\t “Baymax Dreams" ) ,
69
+ new TextSpan ( "\t " , style : new TextStyle ( color : Colors . black ) ) ,
70
+ new TextSpan ( " Unity Widgets" ) ,
71
+ new TextSpan ( " Text" ) ,
72
+ new TextSpan ( "Real-time 3D revolutionizes the animation pipeline " ) ,
73
+ new TextSpan ( style : new TextStyle ( color : Color . fromARGB ( 125 , 255 , 0 , 0 ) ) ,
74
+ text : "Transparent Red Text\n \n " ) ,
75
+ new TextSpan ( "Bold Text Test Bold Textfs Test: FontWeight.w70\n \n " ) ,
76
+ new TextSpan ( style : new TextStyle ( fontStyle : FontStyle . italic ) ,
77
+ text : "This is FontStyle.italic Text This is FontStyle.italic Text\n \n " ) ,
78
+ new TextSpan (
79
+ style : new TextStyle ( fontStyle : FontStyle . italic , fontWeight : FontWeight . w700 ) ,
80
+ text :
81
+ "This is FontStyle.italic And 发撒放豆腐sad 发生的 Bold Text This is FontStyle.italic And Bold Text\n \n " ) ,
82
+ new TextSpan ( style : new TextStyle ( fontSize : 18 ) ,
83
+ text : "FontSize 18: Get a named matrix value from the shader.\n \n " ) ,
84
+ new TextSpan ( style : new TextStyle ( fontSize : 24 ) ,
85
+ text : "Emoji \ud83d \ude0a \ud83d \ude0b \t \ud83d \ude0d \ud83d \ude0e \ud83d \ude00 " ) ,
86
+ new TextSpan ( style : new TextStyle ( fontSize : 14 ) ,
87
+ text : "Emoji \ud83d \ude0a \ud83d \ude0b \ud83d \ude0d \ud83d \ude0e \ud83d \ude00 Emoji" ) ,
88
+ new TextSpan ( style : new TextStyle ( fontSize : 18 ) ,
89
+ text : "Emoji \ud83d \ude01 \ud83d \ude02 \ud83d \ude03 \ud83d \ude04 \ud83d \ude05 " ) ,
90
+ new TextSpan ( style : new TextStyle ( fontSize : 18 ) ,
91
+ text : "\ud83d \ude01 \ud83d \ude02 \ud83d \ude03 \ud83d \ude04 \ud83d \ude05 " ) ,
92
+ new TextSpan ( style : new TextStyle ( fontSize : 18 ) ,
93
+ text : "\ud83d \ude01 \ud83d \ude02 \ud83d \ude03 \ud83d \ude04 \ud83d \ude05 " ) ,
94
+ new TextSpan ( style : new TextStyle ( fontSize : 18 ) ,
95
+ text : "\ud83d \ude01 \ud83d \ude02 \ud83d \ude03 \ud83d \ude04 \ud83d \ude05 " ) ,
96
+ new TextSpan ( style : new TextStyle ( fontSize : 18 ) ,
97
+ text : "\ud83d \ude01 \ud83d \ude02 \ud83d \ude03 \ud83d \ude04 \ud83d \ude05 " ) ,
98
+ new TextSpan ( style : new TextStyle ( fontSize : 24 ) ,
99
+ text :
100
+ "Emoji \ud83d \ude06 \ud83d \ude1C \ud83d \ude18 \ud83d \ude2D \ud83d \ude0C \ud83d \ude1E \n \n " ) ,
101
+ new TextSpan ( style : new TextStyle ( fontSize : 14 ) ,
102
+ text : "FontSize 14" ) ,
103
+ } )
104
+ )
105
+ ) ;
106
+
107
+ public override Widget build ( BuildContext context )
108
+ {
109
+ Widget buttons = new Column (
110
+ mainAxisAlignment : MainAxisAlignment . end ,
111
+ children : new List < Widget >
112
+ {
113
+ new Text ( $ "Width: { width } ") ,
114
+ new RaisedButton (
115
+ onPressed : ( ) => { setState ( ( ) => { width += 10 ; } ) ; } ,
116
+ child : new Text ( "Add Width" )
117
+ ) ,
118
+ new Divider ( ) ,
119
+ new RaisedButton (
120
+ onPressed : ( ) => { setState ( ( ) => { width -= 10 ; } ) ; } ,
121
+ child : new Text ( "Dec Width" )
122
+ ) ,
123
+ new Divider ( ) ,
124
+ new RaisedButton (
125
+ onPressed : ( ) => { setState ( ( ) => { visible = true ; } ) ; } ,
126
+ child : new Text ( "Show" )
127
+ ) ,
128
+ new Divider ( ) ,
129
+ new RaisedButton (
130
+ onPressed : ( ) => { setState ( ( ) => { visible = false ; } ) ; } ,
131
+ child : new Text ( "Hide" )
132
+ )
133
+ }
134
+ ) ;
135
+ Widget child = new Column (
136
+ children : new List < Widget >
137
+ {
138
+ visible ? richtext : new Text ( "" ) ,
139
+ visible
140
+ ? new Text (
141
+ "Very Very Very Very Very Very Very Very Very Very Very Very Very Very\n Very Very Very Very Very Very Very Very Very Very Very Long Text" ,
142
+ maxLines : 3 , overflow : TextOverflow . ellipsis , textAlign : TextAlign . justify
143
+ )
144
+ : new Text ( "" )
145
+ } ) ;
146
+ child = new Stack (
147
+ children : new List < Widget > {
148
+ child ,
149
+ buttons
150
+ }
151
+ ) ;
152
+ child = new Container (
153
+ width : width ,
154
+ color : Colors . black12 ,
155
+ child : child
156
+ ) ;
157
+ child = new Center (
158
+ child : child
159
+ ) ;
160
+ return child ;
161
+ }
162
+ }
163
+ }
0 commit comments