forked from UnityTech/UIWidgets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDragDropSample.cs
More file actions
151 lines (137 loc) · 5.8 KB
/
DragDropSample.cs
File metadata and controls
151 lines (137 loc) · 5.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using System.Collections.Generic;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEngine;
namespace UIWidgetsSample {
public class DragDropSample : UIWidgetsSamplePanel {
protected override Widget createWidget() {
return new WidgetsApp(
home: new DragDropApp(),
pageRouteBuilder: this.pageRouteBuilder
);
}
class DragDropApp : StatefulWidget {
public DragDropApp(Key key = null) : base(key) {
}
public override State createState() {
return new DragDropState();
}
}
class DragTargetWidget : StatefulWidget {
public DragTargetWidget(Key key = null) : base(key) {
}
public override State createState() {
return new DragTargetWidgetState();
}
}
class DragTargetWidgetState : State<DragTargetWidget> {
int value;
public override Widget build(BuildContext context) {
return new Positioned(
left: 40.0f,
bottom: 40.0f,
child: new DragTarget<int>(
onAccept: obj => {
Debug.Log("ON ACCEPTED ..." + obj);
this.setState(() => { this.value += obj; });
},
builder: (inner_context2, accepted, rejected) => {
return new Container(
width: 40.0f,
height: 40.0f,
constraints: BoxConstraints.tight(new Size(40, 40)),
color: CLColors.red,
child: new Center(child: new Text("" + this.value))
);
}
)
);
}
}
class DragDropState : State<DragDropApp> {
public override Widget build(BuildContext context) {
var entries = new List<OverlayEntry>();
var entry_bg = new OverlayEntry(
inner_context => new Container(
color: CLColors.white
));
var entry = new OverlayEntry(
inner_context => new Positioned(
left: 0.0f,
bottom: 0.0f,
child: new GestureDetector(
onTap: () => { },
child: new Draggable<int>(
5,
child: new Container(
color: CLColors.blue,
width: 30.0f,
height: 30.0f,
constraints: BoxConstraints.tight(new Size(30, 30)),
child: new Center(child: new Text("5"))
),
feedback: new Container(
color: CLColors.green,
width: 30.0f,
height: 30.0f),
//maxSimultaneousDrags: 1,
childWhenDragging: new Container(
color: CLColors.black,
width: 30.0f,
height: 30.0f,
constraints: BoxConstraints.tight(new Size(30, 30))
)
)
)
)
);
var entry3 = new OverlayEntry(
inner_context => new Positioned(
left: 0.0f,
bottom: 40.0f,
child: new GestureDetector(
onTap: () => { },
child:
new Draggable<int>(
8,
child: new Container(
color: CLColors.background4,
width: 30.0f,
height: 30.0f,
constraints: BoxConstraints.tight(new Size(30, 30)),
child: new Center(child: new Text("8")))
,
feedback: new Container(
color: CLColors.green,
width: 30.0f,
height: 30.0f),
maxSimultaneousDrags: 1,
childWhenDragging: new Container(
color: CLColors.black,
width: 30.0f,
height: 30.0f,
constraints: BoxConstraints.tight(new Size(30, 30))
)
)
)
)
);
var entry2 = new OverlayEntry(
inner_context => new DragTargetWidget()
);
entries.Add(entry_bg);
entries.Add(entry);
entries.Add(entry2);
entries.Add(entry3);
return new Container(
color: CLColors.white,
child: new Overlay(
initialEntries: entries
)
);
}
}
}
}