1
+ using System . Collections . Generic ;
2
+ using Unity . UIWidgets . gestures ;
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
+
10
+ namespace UIWidgetsSample {
11
+ public class HoverRecognizerSample : UIWidgetsSamplePanel {
12
+ protected override Widget createWidget ( ) {
13
+ return new MaterialApp (
14
+ showPerformanceOverlay : false ,
15
+ home : new HoverMainPanel ( )
16
+ ) ;
17
+ }
18
+
19
+ protected override void OnEnable ( ) {
20
+ FontManager . instance . addFont ( Resources . Load < Font > ( path : "MaterialIcons-Regular" ) , "Material Icons" ) ;
21
+ base . OnEnable ( ) ;
22
+ }
23
+ }
24
+
25
+ class HoverMainPanel : StatefulWidget {
26
+ public override State createState ( ) {
27
+ return new HoverMainPanelState ( ) ;
28
+ }
29
+ }
30
+
31
+ class HoverMainPanelState : State < HoverMainPanel > {
32
+ bool hoverActivated = false ;
33
+
34
+ public override Widget build ( BuildContext context ) {
35
+ return new Scaffold (
36
+ appBar : new AppBar (
37
+ title : new Center (
38
+ child : new Text ( "Test Hover Widget" )
39
+ )
40
+ ) ,
41
+ body : new Card (
42
+ color : Colors . white ,
43
+ child : new Center (
44
+ child : new Column (
45
+ mainAxisSize : MainAxisSize . min ,
46
+ crossAxisAlignment : CrossAxisAlignment . center ,
47
+ children : new List < Widget > {
48
+ new Icon ( this . hoverActivated ? Unity . UIWidgets . material . Icons . pool : Unity . UIWidgets . material . Icons . directions_walk , size : 128.0f ) ,
49
+ new RichText (
50
+ text : new TextSpan (
51
+ text : "Test <" ,
52
+ style : new TextStyle ( color : Colors . black ) ,
53
+ children : new List < TextSpan > ( ) {
54
+ new TextSpan (
55
+ text : "Hover Me" ,
56
+ style : new TextStyle (
57
+ color : Colors . green ,
58
+ decoration : TextDecoration . underline
59
+ ) ,
60
+ hoverRecognizer : new HoverRecognizer {
61
+ OnPointerEnter = evt => {
62
+ this . setState ( ( ) => { this . hoverActivated = true ; } ) ;
63
+ } ,
64
+ OnPointerLeave = ( ) => {
65
+ this . setState ( ( ) => { this . hoverActivated = false ; } ) ;
66
+ }
67
+ }
68
+ ) ,
69
+ new TextSpan (
70
+ text : ">"
71
+ )
72
+ }
73
+ )
74
+ )
75
+ }
76
+ )
77
+ )
78
+ )
79
+ ) ;
80
+ }
81
+ }
82
+ }
0 commit comments