浏览代码

widget canvas

/main
fzhangtj 6 年前
当前提交
c9db4b3c
共有 25 个文件被更改,包括 1249 次插入304 次删除
  1. 2
      Assets/UIWidgets/Tests/EditableTextWiget.cs
  2. 2
      Assets/UIWidgets/Tests/Gestures.cs
  3. 2
      Assets/UIWidgets/Tests/Paragraph.cs
  4. 2
      Assets/UIWidgets/Tests/RenderBoxes.cs
  5. 2
      Assets/UIWidgets/Tests/RenderEditable.cs
  6. 6
      Assets/UIWidgets/Tests/SceneViewTests.cs
  7. 2
      Assets/UIWidgets/Tests/Widgets.cs
  8. 6
      Assets/UIWidgets/debugger/inpsector_panel.cs
  9. 6
      Assets/UIWidgets/debugger/inspector_treeview.cs
  10. 10
      Assets/UIWidgets/debugger/inspector_window.cs
  11. 300
      Assets/UIWidgets/editor/editor_window.cs
  12. 4
      Assets/UIWidgets/ui/painting/canvas_impl.cs
  13. 18
      Assets/UIWidgets/widgets/editable_text.cs
  14. 2
      Assets/UIWidgets/widgets/automatic_keep_alive.cs
  15. 25
      Assets/UIWidgets/editor/canvas_window.cs
  16. 3
      Assets/UIWidgets/editor/canvas_window.cs.meta
  17. 319
      Assets/UIWidgets/editor/window_adapter.cs
  18. 3
      Assets/UIWidgets/editor/window_adapter.cs.meta
  19. 682
      Assets/UIWidgets/engine/AsScreen.cs
  20. 3
      Assets/UIWidgets/engine/AsScreen.cs.meta
  21. 151
      Assets/UIWidgets/engine/WidgetCanvas.cs
  22. 3
      Assets/UIWidgets/engine/WidgetCanvas.cs.meta
  23. 0
      /Assets/UIWidgets/widgets/automatic_keep_alive.cs
  24. 0
      /Assets/UIWidgets/widgets/automatic_keep_alive.cs.meta

2
Assets/UIWidgets/Tests/EditableTextWiget.cs


private void OnEnable() {
this.paintingBinding = new PaintingBinding(null);
paintingBinding.initInstances();
this.windowAdapter = new WindowAdapter(this);
this.windowAdapter = new EditorWindowAdapter(this);
this.root = new widgets.Container(
width: 200,
height: 200,

2
Assets/UIWidgets/Tests/Gestures.cs


}
private void OnEnable() {
this.windowAdapter = new WindowAdapter(this);
this.windowAdapter = new EditorWindowAdapter(this);
this._tapRecognizer = new TapGestureRecognizer();
this._tapRecognizer.onTap = () => { Debug.Log("tap"); };

2
Assets/UIWidgets/Tests/Paragraph.cs


}
private void OnEnable() {
this.windowAdapter = new WindowAdapter(this);
this.windowAdapter = new EditorWindowAdapter(this);
}
void OnDestroy() {

2
Assets/UIWidgets/Tests/RenderBoxes.cs


}
private void OnEnable() {
this.windowAdapter = new WindowAdapter(this);
this.windowAdapter = new EditorWindowAdapter(this);
}
void OnDestroy() {

2
Assets/UIWidgets/Tests/RenderEditable.cs


}
private void OnEnable() {
this.windowAdapter = new WindowAdapter(this);
this.windowAdapter = new EditorWindowAdapter(this);
}
void OnDestroy() {

6
Assets/UIWidgets/Tests/SceneViewTests.cs


Handles.BeginGUI();
if (windowAdapter == null) {
windowAdapter = new WindowAdapter(sceneView);
windowAdapter = new EditorWindowAdapter(sceneView);
windowAdapter = new WindowAdapter(sceneView);
windowAdapter = new EditorWindowAdapter(sceneView);
}
var selected = EditorGUILayout.Popup("test case", _selected, _optionStrings);

}
}
private static WindowAdapter windowAdapter;
private static EditorWindowAdapter windowAdapter;
public static Widget none() {
return null;

2
Assets/UIWidgets/Tests/Widgets.cs


private void OnEnable() {
this.paintingBinding = new PaintingBinding(null);
paintingBinding.initInstances();
this.windowAdapter = new WindowAdapter(this);
this.windowAdapter = new EditorWindowAdapter(this);
}
void OnDestroy() {

6
Assets/UIWidgets/debugger/inpsector_panel.cs


using System;
#if UNITY_EDITOR
using System;
using System.Collections.Generic;
using System.Linq;
using UIWidgets.foundation;

public WidgetTreeType treeType;
public float splitOffset;
}
}
}
#endif

6
Assets/UIWidgets/debugger/inspector_treeview.cs


using System;
#if UNITY_EDITOR
using System;
using System.Collections.Generic;
using System.Reflection;
using UIWidgets.foundation;

color, 0, 0);
}
}
}
}
#endif

10
Assets/UIWidgets/debugger/inspector_window.cs


using System.Collections.Generic;
#if UNITY_EDITOR
using System.Collections.Generic;
using System.Linq;
using RSG.Promises;
using UIWidgets.editor;

private void DoSelectDropDown()
{
var currentWindow = m_InspectorService == null ? null : m_InspectorService.window;
var selectTitle = currentWindow != null ? currentWindow.editorWindow.titleContent : new GUIContent("<Please Select>");
var selectTitle = currentWindow != null ? currentWindow.titleContent : new GUIContent("<Please Select>");
if (GUILayout.Button(selectTitle, EditorStyles.toolbarDropDown))
{
var windows = new List<WindowAdapter>(WindowAdapter.windowAdapters.Where(w =>

labels[0] = new GUIContent("none");
for (int i = 0; i < windows.Count; i++)
{
labels[i + 1] = windows[i].editorWindow.titleContent;
labels[i + 1] = windows[i].titleContent;
if (windows[i] == currentWindow)
{
selectedIndex = i + 1;

}
}
}
}
#endif

300
Assets/UIWidgets/editor/editor_window.cs


using System;
using System.Collections.Generic;
using System.Diagnostics;
using UIWidgets.async;
using UIWidgets.flow;
using UIWidgets.service;
using UIWidgets.rendering;
using UIWidgets.ui;
using UIWidgets.widgets;
#if UNITY_EDITOR
namespace UIWidgets.editor {
public class WindowAdapter : Window {
private static List<WindowAdapter> _windowAdapters = new List<WindowAdapter>();
private bool _alive;
public static IEnumerable<WindowAdapter> windowAdapters
{
get { return _windowAdapters; }
}
namespace UIWidgets.editor {
public WindowAdapter(EditorWindow editorWindow)
{
this._alive = true;
this.editorWindow = editorWindow;
this.editorWindow.wantsMouseMove = true;
this.editorWindow.wantsMouseEnterLeaveWindow = true;
this._devicePixelRatio = EditorGUIUtility.pixelsPerPoint;
this._lastPosition = editorWindow.position;
this._physicalSize = new Size(
this._lastPosition.width * EditorGUIUtility.pixelsPerPoint,
this._lastPosition.height * EditorGUIUtility.pixelsPerPoint);
instance = this;
try {
this._binding = new WidgetsBinding();
}
finally {
instance = null;
}
this._rasterCache = new RasterCache();
_windowAdapters.Add(this);
}
public bool alive
{
get { return _alive; }
}
public void Destory()
{
var index = _windowAdapters.FindIndex(w => w == this);
if (index >= 0)
{
_windowAdapters.RemoveAt(index);
}
this._alive = false;
}
public class EditorWindowAdapter : WindowAdapter
{
public WidgetInspectorService widgetInspectorService
{
get { return _binding.widgetInspectorService; }
}
readonly WidgetsBinding _binding;
readonly RasterCache _rasterCache;
Rect _lastPosition;
readonly DateTime _epoch = new DateTime(Stopwatch.GetTimestamp());
readonly MicrotaskQueue _microtaskQueue = new MicrotaskQueue();
readonly TimerProvider _timerProvider = new TimerProvider();
readonly TextInput _textInput = new TextInput();
public void OnGUI() {
instance = this;
WidgetsBinding.instance = this._binding;
try {
this.doOnGUI();
}
finally {
instance = null;
WidgetsBinding.instance = null;
}
}
public void WithBinding(Action fn)
public EditorWindowAdapter(EditorWindow editorWindow):base(editorWindow.position, EditorGUIUtility.pixelsPerPoint)
instance = this;
WidgetsBinding.instance = this._binding;
try
{
fn();
}
finally {
instance = null;
WidgetsBinding.instance = null;
}
this.editorWindow = editorWindow;
editorWindow.wantsMouseMove = true;
editorWindow.wantsMouseEnterLeaveWindow = true;
public T WithBindingFunc<T>(Func<T> fn)
{
instance = this;
WidgetsBinding.instance = this._binding;
try
{
return fn();
}
finally {
instance = null;
WidgetsBinding.instance = null;
}
}
private void doOnGUI() {
var evt = Event.current;
if (evt.type == EventType.Repaint) {
if (this.onBeginFrame != null) {
this.onBeginFrame(new DateTime(Stopwatch.GetTimestamp()) - this._epoch);
}
this.flushMicrotasks();
if (this.onDrawFrame != null) {
this.onDrawFrame();
}
return;
}
if (this.onPointerEvent != null) {
PointerData pointerData = null;
if (evt.type == EventType.MouseDown) {
pointerData = new PointerData(
timeStamp: DateTime.Now,
change: PointerChange.down,
kind: PointerDeviceKind.mouse,
device: evt.button,
physicalX: evt.mousePosition.x * this._devicePixelRatio,
physicalY: evt.mousePosition.y * this._devicePixelRatio
);
} else if (evt.type == EventType.MouseUp || evt.rawType == EventType.MouseUp) {
pointerData = new PointerData(
timeStamp: DateTime.Now,
change: PointerChange.up,
kind: PointerDeviceKind.mouse,
device: evt.button,
physicalX: evt.mousePosition.x * this._devicePixelRatio,
physicalY: evt.mousePosition.y * this._devicePixelRatio
);
} else if (evt.type == EventType.MouseDrag) {
pointerData = new PointerData(
timeStamp: DateTime.Now,
change: PointerChange.move,
kind: PointerDeviceKind.mouse,
device: evt.button,
physicalX: evt.mousePosition.x * this._devicePixelRatio,
physicalY: evt.mousePosition.y * this._devicePixelRatio
);
} else if (evt.type == EventType.MouseMove)
{
pointerData = new PointerData(
timeStamp: DateTime.Now,
change: PointerChange.hover,
kind: PointerDeviceKind.mouse,
device: evt.button,
physicalX: evt.mousePosition.x * this._devicePixelRatio,
physicalY: evt.mousePosition.y * this._devicePixelRatio
);
}
if (pointerData != null) {
this.onPointerEvent(new PointerDataPacket(new List<PointerData> {
pointerData
}));
}
}
if (_textInput != null) {
_textInput.OnGUI();
}
}
public void Update() {
Window.instance = this;
WidgetsBinding.instance = this._binding;
try {
this.doUpdate();
}
finally {
Window.instance = null;
WidgetsBinding.instance = null;
}
}
private void doUpdate() {
this.flushMicrotasks();
this._timerProvider.update();
bool dirty = false;
if (this._devicePixelRatio != EditorGUIUtility.pixelsPerPoint) {
dirty = true;
}
if (this._lastPosition != this.editorWindow.position) {
dirty = true;
}
if (dirty) {
this._devicePixelRatio = EditorGUIUtility.pixelsPerPoint;
this._lastPosition = this.editorWindow.position;
this._physicalSize = new Size(
this._lastPosition.width * EditorGUIUtility.pixelsPerPoint,
this._lastPosition.height * EditorGUIUtility.pixelsPerPoint);
if (this.onMetricsChanged != null) {
this.onMetricsChanged();
}
}
}
public override void render(Scene scene) {
var layer = scene.takeLayer();
var prerollContext = new PrerollContext {
rasterCache = this._rasterCache
};
layer.preroll(prerollContext, Matrix4x4.identity);
var paintContext = new PaintContext {
canvas = new CanvasImpl()
};
layer.paint(paintContext);
this._rasterCache.sweepAfterFrame();
public override GUIContent titleContent
{
get { return editorWindow.titleContent; }
public override void scheduleMicrotask(Action callback) {
this._microtaskQueue.scheduleMicrotask(callback);
}
public override void flushMicrotasks() {
this._microtaskQueue.flushMicrotasks();
}
public override Timer run(TimeSpan duration, Action callback, bool periodic = false)
protected override void getWindowMetrics(out double devicePixelRatio, out Rect position)
return periodic
? this._timerProvider.periodic(duration, callback)
: this._timerProvider.run(duration, callback);
devicePixelRatio = EditorGUIUtility.pixelsPerPoint;
position = this.editorWindow.position;
public void attachRootRenderBox(RenderBox root) {
Window.instance = this;
WidgetsBinding.instance = this._binding;
}
try {
this._binding.renderView.child = root;
}
finally {
Window.instance = null;
WidgetsBinding.instance = null;
}
}
public void attachRootWidget(Widget root) {
Window.instance = this;
WidgetsBinding.instance = this._binding;
try {
this._binding.attachRootWidget(root);
}
finally {
Window.instance = null;
WidgetsBinding.instance = null;
}
}
public override TextInput textInput {
get { return _textInput; }
}
}
}
}
#endif

4
Assets/UIWidgets/ui/painting/canvas_impl.cs


guiRoundedRectMat.SetFloatArray("UIWidgets_CornerRadius",
borderRadius == null ? new[] {0f, 0f, 0f, 0f} : borderRadius.toFloatArray());
Graphics.DrawTexture(rect.toRect(), EditorGUIUtility.whiteTexture,
Graphics.DrawTexture(rect.toRect(), Texture2D.whiteTexture,
new UnityEngine.Rect(0.0f, 0.0f, 1f, 1f), 0, 0, 0, 0,
paint.color.toColor(), guiRoundedRectMat);
}

shadowRectMat.SetFloat("UIWidgets_sigma", (float) paint.blurSigma);
Graphics.DrawTexture(rect.toRect(), EditorGUIUtility.whiteTexture,
Graphics.DrawTexture(rect.toRect(), Texture2D.whiteTexture,
new UnityEngine.Rect(0.0f, 0.0f, 1f, 1f), 0, 0, 0, 0,
paint.color.toColor(), shadowRectMat);
}

18
Assets/UIWidgets/widgets/editable_text.cs


}
}
public class EditableTextState : State<EditableText>, TextInputClient
public class EditableTextState : AutomaticKeepAliveClientMixin<EditableText>, TextInputClient
{
const int _kObscureShowLatestCharCursorTicks = 3;
private static TimeSpan _kCursorBlinkHalfPeriod = TimeSpan.FromMilliseconds(500);

private bool _didAutoFocus = false;
public ScrollController _scrollController = new ScrollController();
TextInputConnection _textInputConnection;
private int _obscureShowCharTicksPending = 0;

protected override bool wantKeepAlive
{
get { return widget.focusNode.hasFocus; }
}
public override void initState()
{

{
oldWidget.focusNode.removeListener(_handleFocusChanged);
widget.focusNode.addListener(_handleFocusChanged);
updateKeepAlive();
}
}

{
widget.controller.selection = TextSelection.collapsed(offset: _value.text.Length);
}
updateKeepAlive();
}

public override Widget build(BuildContext context)
{
FocusScope.of(context).reparentIfNeeded(widget.focusNode);
// todo base.build(context); See AutomaticKeepAliveClientMixin.
base.build(context); // See AutomaticKeepAliveClientMixin.
// return new Scrollable(
// axisDirection: _isMultiline ? AxisDirection.down : AxisDirection.right
// // controller: _sc
// );
return new _Editable(
key: _editableKey,
textSpan: buildTextSpan(),

2
Assets/UIWidgets/widgets/automatic_keep_alive.cs


using UIWidgets.ui;
using UIWidgets.widgets;
namespace UIWidgets.rendering {
namespace UIWidgets.widgets {
public class AutomaticKeepAlive : StatefulWidget {
public AutomaticKeepAlive(
Key key = null,

25
Assets/UIWidgets/editor/canvas_window.cs


using UnityEngine;
namespace UIWidgets.editor
{
public class CanvasWindowAdapter : WindowAdapter
{
private Rect _position;
private double __devicePixelRatio;
public CanvasWindowAdapter(Rect position, double devicePixelRatio): base(position, devicePixelRatio)
{
this._position = position;
this.__devicePixelRatio = devicePixelRatio;
}
public override void scheduleFrame()
{
}
protected override void getWindowMetrics(out double devicePixelRatio, out Rect position)
{
devicePixelRatio = this.__devicePixelRatio;
position = this._position;
}
}
}

3
Assets/UIWidgets/editor/canvas_window.cs.meta


fileFormatVersion: 2
guid: a0bffa61dae34193b6c01986d6f7f22b
timeCreated: 1545211142

319
Assets/UIWidgets/editor/window_adapter.cs


using System;
using System.Collections.Generic;
using System.Diagnostics;
using UIWidgets.async;
using UIWidgets.flow;
using UIWidgets.rendering;
using UIWidgets.service;
using UIWidgets.ui;
using UIWidgets.widgets;
using UnityEngine;
using Rect = UnityEngine.Rect;
namespace UIWidgets.editor
{
public abstract class WindowAdapter : Window {
private static List<WindowAdapter> _windowAdapters = new List<WindowAdapter>();
private bool _alive;
public static IEnumerable<WindowAdapter> windowAdapters
{
get { return _windowAdapters; }
}
public WindowAdapter(Rect position, double devicePixelRatio)
{
this._alive = true;
this._lastPosition = position;
this._devicePixelRatio = devicePixelRatio;
this._physicalSize = new Size(
this._lastPosition.width * devicePixelRatio,
this._lastPosition.height * devicePixelRatio);
instance = this;
try {
this._binding = new WidgetsBinding();
}
finally {
instance = null;
}
this._rasterCache = new RasterCache();
_windowAdapters.Add(this);
}
public bool alive
{
get { return _alive; }
}
public void Destory()
{
var index = _windowAdapters.FindIndex(w => w == this);
if (index >= 0)
{
_windowAdapters.RemoveAt(index);
}
this._alive = false;
}
public WidgetInspectorService widgetInspectorService
{
get { return _binding.widgetInspectorService; }
}
public virtual GUIContent titleContent
{
get { return null; }
}
readonly WidgetsBinding _binding;
readonly RasterCache _rasterCache;
Rect _lastPosition;
readonly DateTime _epoch = new DateTime(Stopwatch.GetTimestamp());
readonly MicrotaskQueue _microtaskQueue = new MicrotaskQueue();
readonly TimerProvider _timerProvider = new TimerProvider();
readonly TextInput _textInput = new TextInput();
public void OnGUI() {
instance = this;
WidgetsBinding.instance = this._binding;
try {
this.doOnGUI();
}
finally {
instance = null;
WidgetsBinding.instance = null;
}
}
public void Paint()
{
instance = this;
WidgetsBinding.instance = this._binding;
try {
if (this.onBeginFrame != null) {
this.onBeginFrame(new DateTime(Stopwatch.GetTimestamp()) - this._epoch);
}
this.flushMicrotasks();
if (this.onDrawFrame != null) {
this.onDrawFrame();
}
}
finally {
instance = null;
WidgetsBinding.instance = null;
}
}
public void WithBinding(Action fn)
{
instance = this;
WidgetsBinding.instance = this._binding;
try
{
fn();
}
finally {
instance = null;
WidgetsBinding.instance = null;
}
}
public T WithBindingFunc<T>(Func<T> fn)
{
instance = this;
WidgetsBinding.instance = this._binding;
try
{
return fn();
}
finally {
instance = null;
WidgetsBinding.instance = null;
}
}
private void doOnGUI() {
var evt = Event.current;
if (evt.type == EventType.Repaint) {
if (this.onBeginFrame != null) {
this.onBeginFrame(new DateTime(Stopwatch.GetTimestamp()) - this._epoch);
}
this.flushMicrotasks();
if (this.onDrawFrame != null) {
this.onDrawFrame();
}
return;
}
if (this.onPointerEvent != null) {
PointerData pointerData = null;
if (evt.type == EventType.MouseDown) {
pointerData = new PointerData(
timeStamp: DateTime.Now,
change: PointerChange.down,
kind: PointerDeviceKind.mouse,
device: evt.button,
physicalX: evt.mousePosition.x * this._devicePixelRatio,
physicalY: evt.mousePosition.y * this._devicePixelRatio
);
} else if (evt.type == EventType.MouseUp || evt.rawType == EventType.MouseUp) {
pointerData = new PointerData(
timeStamp: DateTime.Now,
change: PointerChange.up,
kind: PointerDeviceKind.mouse,
device: evt.button,
physicalX: evt.mousePosition.x * this._devicePixelRatio,
physicalY: evt.mousePosition.y * this._devicePixelRatio
);
} else if (evt.type == EventType.MouseDrag) {
pointerData = new PointerData(
timeStamp: DateTime.Now,
change: PointerChange.move,
kind: PointerDeviceKind.mouse,
device: evt.button,
physicalX: evt.mousePosition.x * this._devicePixelRatio,
physicalY: evt.mousePosition.y * this._devicePixelRatio
);
} else if (evt.type == EventType.MouseMove)
{
pointerData = new PointerData(
timeStamp: DateTime.Now,
change: PointerChange.hover,
kind: PointerDeviceKind.mouse,
device: evt.button,
physicalX: evt.mousePosition.x * this._devicePixelRatio,
physicalY: evt.mousePosition.y * this._devicePixelRatio
);
}
if (pointerData != null) {
this.onPointerEvent(new PointerDataPacket(new List<PointerData> {
pointerData
}));
}
}
if (_textInput != null) {
_textInput.OnGUI();
}
}
public void Update() {
Window.instance = this;
WidgetsBinding.instance = this._binding;
try {
this.doUpdate();
}
finally {
Window.instance = null;
WidgetsBinding.instance = null;
}
}
protected abstract void getWindowMetrics(out double devicePixelRatio , out Rect position);
private void doUpdate() {
this.flushMicrotasks();
this._timerProvider.update();
double devicePixelRatio;
Rect newPosition;
getWindowMetrics(out devicePixelRatio, out newPosition);
bool dirty = false;
if (this._devicePixelRatio != devicePixelRatio) {
dirty = true;
}
if (this._lastPosition != newPosition) {
dirty = true;
}
if (dirty) {
this._devicePixelRatio = devicePixelRatio;
this._lastPosition = newPosition;
this._physicalSize = new Size(
this._lastPosition.width * devicePixelRatio,
this._lastPosition.height * devicePixelRatio);
if (this.onMetricsChanged != null) {
this.onMetricsChanged();
}
}
}
public override void render(Scene scene) {
var layer = scene.takeLayer();
var prerollContext = new PrerollContext {
rasterCache = this._rasterCache
};
layer.preroll(prerollContext, Matrix4x4.identity);
var paintContext = new PaintContext {
canvas = new CanvasImpl()
};
layer.paint(paintContext);
this._rasterCache.sweepAfterFrame();
}
public override void scheduleMicrotask(Action callback) {
this._microtaskQueue.scheduleMicrotask(callback);
}
public override void flushMicrotasks() {
this._microtaskQueue.flushMicrotasks();
}
public override Timer run(TimeSpan duration, Action callback, bool periodic = false)
{
return periodic
? this._timerProvider.periodic(duration, callback)
: this._timerProvider.run(duration, callback);
}
public void attachRootRenderBox(RenderBox root) {
Window.instance = this;
WidgetsBinding.instance = this._binding;
try {
this._binding.renderView.child = root;
}
finally {
Window.instance = null;
WidgetsBinding.instance = null;
}
}
public void attachRootWidget(Widget root) {
Window.instance = this;
WidgetsBinding.instance = this._binding;
try {
this._binding.attachRootWidget(root);
}
finally {
Window.instance = null;
WidgetsBinding.instance = null;
}
}
public override TextInput textInput {
get { return _textInput; }
}
}
}

3
Assets/UIWidgets/editor/window_adapter.cs.meta


fileFormatVersion: 2
guid: 90edd0938cfa49fd8d8f3ab6098e64e7
timeCreated: 1545209853

682
Assets/UIWidgets/engine/AsScreen.cs


using System.Collections.Generic;
using UIWidgets.foundation;
using UIWidgets.gestures;
using UIWidgets.painting;
using UIWidgets.rendering;
using UIWidgets.ui;
using UIWidgets.widgets;
using TextStyle = UIWidgets.painting.TextStyle;
namespace UIWidgets.engine
{
public class AsScreen : StatefulWidget
{
public AsScreen(Key key = null) : base(key)
{
}
public override State createState()
{
return new _AsScreenState();
}
}
class _AsScreenState : State<AsScreen>
{
const double headerHeight = 50.0;
Widget _buildHeader(BuildContext context)
{
return new Container(
padding: EdgeInsets.only(left: 16.0, right: 8.0),
height: headerHeight,
color: CLColors.header,
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: new List<Widget>
{
new Container(
child: new Text(
"All Assets",
style: new TextStyle(
fontSize: 16,
color: Color.fromARGB(100, 255, 255, 0)
)
)
),
new CustomButton(
padding: EdgeInsets.only(0.0, 0.0, 16.0, 0.0),
child: new Icon(
Icons.keyboard_arrow_down,
size: 18.0,
color: CLColors.icon2
)
),
new widgets.Container(
decoration: new BoxDecoration(
color: CLColors.white,
borderRadius: BorderRadius.all(3)
),
width: 320,
height: 36,
padding: EdgeInsets.all(10.0),
margin: EdgeInsets.only(right: 4),
child: new EditableText(
maxLines: 1,
controller: new TextEditingController("Type here to search assets"),
focusNode: new FocusNode(),
style: new TextStyle(
fontSize: 16
),
selectionColor: Color.fromARGB(255, 255, 0, 0),
cursorColor: Color.fromARGB(255, 0, 0, 0)
)
),
new Container(
decoration: new BoxDecoration(
color: CLColors.background4,
borderRadius: BorderRadius.all(2)
),
width: 36,
height: 36,
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: new List<Widget>
{
new CustomButton(
padding: EdgeInsets.only(8.0, 0.0, 8.0, 0.0),
child: new Icon(
Icons.search,
size: 18.0,
color: CLColors.white
)
)
}
)
),
new Container(
margin: EdgeInsets.only(left: 16, right: 16),
child: new Text(
"Learn Game Development",
style: new TextStyle(
fontSize: 12,
color: CLColors.white
)
)
),
new Container(
decoration: new BoxDecoration(
border: Border.all(
color: CLColors.white
)
),
margin: EdgeInsets.only(right: 16),
padding: EdgeInsets.all(4),
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: new List<Widget>
{
new Text(
"Plus/Pro",
style: new TextStyle(
fontSize: 11,
color: CLColors.white
)
)
}
)
),
new Container(
margin: EdgeInsets.only(right: 16),
child: new Text(
"Impressive New Assets",
style: new TextStyle(
fontSize: 12,
color: CLColors.white
)
)
),
new Container(
child: new Text(
"Shop On Old Store",
style: new TextStyle(
fontSize: 12,
color: CLColors.white
)
)
),
}
)
);
}
Widget _buildFooter(BuildContext context)
{
return new Container(
color: CLColors.header,
margin: EdgeInsets.only(top: 50),
height: 90,
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: new List<Widget>
{
new Container(
margin: EdgeInsets.only(right: 10),
child: new Text(
"Copyright © 2018 Unity Technologies",
style: new TextStyle(
fontSize: 12,
color: CLColors.text9
)
)
),
new Container(
margin: EdgeInsets.only(right: 10),
child: new Text(
"All prices are exclusive of tax",
style: new TextStyle(
fontSize: 12,
color: CLColors.text9
)
)
),
new Container(
margin: EdgeInsets.only(right: 10),
child: new Text(
"Terms of Service and EULA",
style: new TextStyle(
fontSize: 12,
color: CLColors.text10
)
)
),
new Container(
child: new Text(
"Cookies",
style: new TextStyle(
fontSize: 12,
color: CLColors.text10
)
)
),
}
)
);
}
Widget _buildBanner(BuildContext context)
{
return new Container(
height: 450,
color: CLColors.white,
child: widgets.Image.network(
"https://d2ujflorbtfzji.cloudfront.net/banner/5c57178c-4be6-4903-953b-85125bfb7154.jpg",
fit: BoxFit.cover
)
);
}
Widget _buildTopAssetsRow(BuildContext context, string title)
{
var testCard = new AssetCard(
"AI Template",
"INVECTOR",
45.0,
36.0,
true,
"https://d2ujflorbtfzji.cloudfront.net/key-image/46dc65c1-f605-4ccb-97e0-3d60b28cfdfe.jpg"
);
return new Container(
margin: EdgeInsets.only(left: 98),
child: new Column(
children: new List<Widget>
{
new Container(
child: new Container(
margin: EdgeInsets.only(top: 50, bottom: 20),
child: new Row(
crossAxisAlignment: CrossAxisAlignment.baseline,
children: new List<Widget>
{
new Container(
child: new Text(
title,
style: new TextStyle(
fontSize: 24,
color: CLColors.black
)
)
),
new Container(
margin: EdgeInsets.only(left: 15),
child:
new Text(
"See More",
style: new TextStyle(
fontSize: 16,
color: CLColors.text4
)
)
)
})
)
),
new Row(
children: new List<Widget>
{
testCard,
testCard,
testCard,
testCard,
testCard,
testCard
}
)
}
));
}
bool _onNotification(ScrollNotification notification, BuildContext context)
{
return true;
}
Widget _buildContentList(BuildContext context)
{
return new NotificationListener<ScrollNotification>(
onNotification: (ScrollNotification notification) =>
{
_onNotification(notification, context);
return true;
},
child: new Flexible(
child: new ListView(
physics: new AlwaysScrollableScrollPhysics(),
children: new List<Widget>
{
_buildBanner(context),
_buildTopAssetsRow(context, "Recommanded For You"),
_buildTopAssetsRow(context, "Beach Day"),
_buildTopAssetsRow(context, "Top Free Packages"),
_buildTopAssetsRow(context, "Top Paid Packages"),
_buildFooter(context)
}
)
)
);
}
public override Widget build(BuildContext context)
{
var container = new Container(
color: CLColors.background3,
child: new Container(
color: CLColors.background3,
child: new Column(
children: new List<Widget>
{
this._buildHeader(context),
this._buildContentList(context),
}
)
)
);
return container;
}
}
public class AssetCard : StatelessWidget
{
public AssetCard(
string name,
string category,
double price,
double priceDiscount,
bool showBadge,
string imageSrc
)
{
this.name = name;
this.category = category;
this.price = price;
this.priceDiscount = priceDiscount;
this.showBadge = showBadge;
this.imageSrc = imageSrc;
}
public string name;
public string category;
public double price;
public double priceDiscount;
public bool showBadge;
public string imageSrc;
public override Widget build(BuildContext context)
{
var card = new Container(
margin: EdgeInsets.only(right: 45),
child: new Container(
child: new Column(
children: new List<Widget>
{
new Container(
decoration: new BoxDecoration(
color: CLColors.white,
borderRadius: BorderRadius.only(topLeft: 3, topRight: 3)
),
width: 200,
height: 124,
child: widgets.Image.network(
this.imageSrc,
fit: BoxFit.fill
)
),
new Container(
color: CLColors.white,
width: 200,
height: 86,
padding: EdgeInsets.fromLTRB(14, 12, 14, 8),
child: new Column(
crossAxisAlignment: CrossAxisAlignment.baseline,
children: new List<Widget>
{
new Container(
height: 18,
padding: EdgeInsets.only(top: 3),
child:
new Text(
category,
style: new TextStyle(
fontSize: 11,
color: CLColors.text5
)
)
),
new Container(
height: 20,
padding: EdgeInsets.only(top: 2),
child:
new Text(
name,
style: new TextStyle(
fontSize: 14,
color: CLColors.text6
)
)
),
new Container(
height: 22,
padding: EdgeInsets.only(top: 4),
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: new List<Widget>
{
new Container(
child: new Row(
children: new List<Widget>
{
new Container(
margin: EdgeInsets.only(right: 10),
child: new Text(
"$" + this.price,
style: new TextStyle(
fontSize: 14,
color: CLColors.text7,
decoration: TextDecoration.lineThrough
)
)
),
new Container(
child: new Text(
"$" + this.priceDiscount,
style: new TextStyle(
fontSize: 14,
color: CLColors.text8
)
)
)
})
),
showBadge
? new Container(
width: 80,
height: 18,
color: CLColors.black,
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: new List<Widget>
{
new Text(
"Plus/Pro",
style: new TextStyle(
fontSize: 11,
color: CLColors.white
)
)
}
)
)
: new Container()
}
)
)
}
)
)
}
)
)
);
return card;
}
}
public class EventsWaterfallScreen : StatefulWidget
{
public EventsWaterfallScreen(Key key = null) : base(key: key)
{
}
public override State createState()
{
return new _EventsWaterfallScreenState();
}
}
class _EventsWaterfallScreenState : State<EventsWaterfallScreen>
{
const double headerHeight = 80.0;
double _offsetY = 0.0;
int _index = -1;
Widget _buildHeader(BuildContext context)
{
return new Container(
padding: EdgeInsets.only(left: 16.0, right: 8.0),
// color: CLColors.blue,
height: headerHeight - _offsetY,
child: new Row(
children: new List<Widget>
{
new Flexible(
flex: 1,
fit: FlexFit.tight,
child: new Text(
"Today",
style: new TextStyle(
fontSize: (34.0 / headerHeight) * (headerHeight - _offsetY),
color: CLColors.white
)
)),
new CustomButton(
padding: EdgeInsets.only(8.0, 0.0, 8.0, 0.0),
child: new Icon(
Icons.notifications,
size: 18.0,
color: CLColors.icon2
)
),
new CustomButton(
padding: EdgeInsets.only(8.0, 0.0, 16.0, 0.0),
child: new Icon(
Icons.account_circle,
size: 18.0,
color: CLColors.icon2
)
)
}
)
);
}
bool _onNotification(ScrollNotification notification, BuildContext context)
{
double pixels = notification.metrics.pixels;
if (pixels >= 0.0)
{
if (pixels <= headerHeight)
{
setState(() => { _offsetY = pixels / 2.0; });
}
}
else
{
if (_offsetY != 0.0)
{
setState(() => { _offsetY = 0.0; });
}
}
return true;
}
Widget _buildContentList(BuildContext context)
{
return new NotificationListener<ScrollNotification>(
onNotification: (ScrollNotification notification) =>
{
_onNotification(notification, context);
return true;
},
child: new Flexible(
child: new Container(
// color: CLColors.green,
child: ListView.builder(
itemCount: 20,
itemExtent: 100,
physics: new AlwaysScrollableScrollPhysics(),
itemBuilder: (BuildContext context1, int index) =>
{
return new Container(
color: Color.fromARGB(255, (index * 10) % 256, (index * 20) % 256,
(index * 30) % 256)
);
}
)
)
)
);
}
public override Widget build(BuildContext context)
{
var container = new Container(
// color: CLColors.background1,
child: new Container(
// color: CLColors.background1,
child: new Column(
children: new List<Widget>
{
this._buildHeader(context),
this._buildContentList(context)
}
)
)
);
return container;
}
}
public class CustomButton : StatelessWidget
{
public CustomButton(
Key key = null,
GestureTapCallback onPressed = null,
EdgeInsets padding = null,
Color backgroundColor = null,
Widget child = null
) : base(key: key)
{
this.onPressed = onPressed;
this.padding = padding ?? EdgeInsets.all(8.0);
this.backgroundColor = backgroundColor ?? CLColors.transparent;
this.child = child;
}
public readonly GestureTapCallback onPressed;
public readonly EdgeInsets padding;
public readonly Widget child;
public readonly Color backgroundColor;
public override Widget build(BuildContext context)
{
return new GestureDetector(
onTap: this.onPressed,
child: new Container(
padding: this.padding,
color: this.backgroundColor,
child: this.child
)
);
}
}
public static class Icons
{
public static readonly IconData notifications = new IconData(0xe7f4, fontFamily: "Material Icons");
public static readonly IconData account_circle = new IconData(0xe853, fontFamily: "Material Icons");
public static readonly IconData search = new IconData(0xe8b6, fontFamily: "Material Icons");
public static readonly IconData keyboard_arrow_down = new IconData(0xe313, fontFamily: "Material Icons");
}
public static class CLColors
{
public static readonly Color primary = new Color(0xFFE91E63);
public static readonly Color secondary1 = new Color(0xFF00BCD4);
public static readonly Color secondary2 = new Color(0xFFF0513C);
public static readonly Color background1 = new Color(0xFF292929);
public static readonly Color background2 = new Color(0xFF383838);
public static readonly Color background3 = new Color(0xFFF5F5F5);
public static readonly Color background4 = new Color(0xFF00BCD4);
public static readonly Color icon1 = new Color(0xFFFFFFFF);
public static readonly Color icon2 = new Color(0xFFA4A4A4);
public static readonly Color text1 = new Color(0xFFFFFFFF);
public static readonly Color text2 = new Color(0xFFD8D8D8);
public static readonly Color text3 = new Color(0xFF959595);
public static readonly Color text4 = new Color(0xFF002835);
public static readonly Color text5 = new Color(0xFF9E9E9E);
public static readonly Color text6 = new Color(0xFF002835);
public static readonly Color text7 = new Color(0xFF5A5A5B);
public static readonly Color text8 = new Color(0xFF239988);
public static readonly Color text9 = new Color(0xFFB3B5B6);
public static readonly Color text10 = new Color(0xFF00BCD4);
public static readonly Color dividingLine1 = new Color(0xFF666666);
public static readonly Color dividingLine2 = new Color(0xFF404040);
public static readonly Color transparent = new Color(0x00000000);
public static readonly Color white = new Color(0xFFFFFFFF);
public static readonly Color black = new Color(0xFF000000);
public static readonly Color red = new Color(0xFFFF0000);
public static readonly Color green = new Color(0xFF00FF00);
public static readonly Color blue = new Color(0xFF0000FF);
public static readonly Color header = new Color(0xFF060B0C);
}
}

3
Assets/UIWidgets/engine/AsScreen.cs.meta


fileFormatVersion: 2
guid: 2c3cc71d76704a998af01c99da3be173
timeCreated: 1545115345

151
Assets/UIWidgets/engine/WidgetCanvas.cs


using UIWidgets.editor;
using UIWidgets.painting;
using UIWidgets.widgets;
using UnityEditor;
using UnityEngine;
using Color = UIWidgets.ui.Color;
namespace UIWidgets.engine
{
public class WidgetCanvas: MonoBehaviour
{
[SerializeField]
private int _canvasWidth = 1000;
[SerializeField]
private int _canvasHeight = 800;
private WindowAdapter _windowAdapter;
private PaintingBinding _paintingBinding;
private RenderTexture _renderTexture;
void OnEnable()
{
if (_windowAdapter == null)
{
this._paintingBinding = new PaintingBinding(null);
_paintingBinding.initInstances();
_windowAdapter = new CanvasWindowAdapter(new Rect(0, 0, _canvasWidth, _canvasHeight), EditorGUIUtility.pixelsPerPoint);
_windowAdapter.attachRootWidget(new AsScreen());
}
setupMeshRenderer();
}
private void setupMeshRenderer()
{
var meshRenderer = GetComponent<MeshRenderer>();
meshRenderer = gameObject.AddComponent(typeof(MeshRenderer)) as MeshRenderer;
var shader = Shader.Find("UI/Default"); // todo
var material = new Material(shader);
meshRenderer.material = material;
var meshFilter = gameObject.AddComponent(typeof(MeshFilter)) as MeshFilter;
var mesh = new Mesh();
meshFilter.mesh = mesh;
var vertices = new Vector3[4];
float minX = -0.5f;
float minY = -0.5f;
float maxX = 0.5f;
float maxY = 0.5f;
vertices[0] = new Vector3(minX, minY, 0);
vertices[1] = new Vector3(maxX, minY, 0);
vertices[2] = new Vector3(minX, maxY, 0);
vertices[3] = new Vector3(maxX, maxY, 0);
mesh.vertices = vertices;
var tri = new int[6];
tri[0] = 0;
tri[1] = 2;
tri[2] = 1;
tri[3] = 2;
tri[4] = 3;
tri[5] = 1;
mesh.triangles = tri;
var uv = new Vector2[4];
uv[0] = new Vector2(0, 0);
uv[1] = new Vector2(1, 0);
uv[2] = new Vector2(0, 1);
uv[3] = new Vector2(1, 1);
mesh.uv = uv;
}
private void OnDestroy()
{
if (_renderTexture != null)
{
_renderTexture.Release();
_renderTexture = null;
}
Destroy(GetComponent<MeshRenderer>());
Destroy(GetComponent<MeshFilter>());
}
private void Update() {
if (this._windowAdapter != null) {
this._windowAdapter.Update();
}
}
private void ensureRenderTexture()
{
if (_renderTexture != null && _renderTexture.IsCreated() &&
_renderTexture.width == _canvasWidth && _renderTexture.height == _canvasHeight)
{
return;
}
if (_renderTexture != null)
{
_renderTexture.Release();
}
_renderTexture = new RenderTexture(_canvasWidth, _canvasHeight, 24);
}
private void OnGUI()
{
if (Event.current.type == EventType.Repaint)
{
GL.PushMatrix();
GL.LoadIdentity();
Matrix4x4 m =Matrix4x4.Scale(new Vector3(2.0f / _canvasWidth, -2.0f / _canvasHeight, 1.0f))
* Matrix4x4.Translate(new Vector3(-_canvasWidth / 2.0f, -_canvasHeight / 2.0f, 0));
GL.LoadProjectionMatrix(m);
ensureRenderTexture();
var renderer = GetComponent<MeshRenderer>();
renderer.material.mainTexture = _renderTexture;
RenderTexture currentActiveRT = RenderTexture.active;
try
{
RenderTexture.active = _renderTexture;
GL.Clear(true, true, new UnityEngine.Color(0,0,0,0));
this._windowAdapter.OnGUI();
}
finally
{
RenderTexture.active = currentActiveRT;
}
GL.PopMatrix();
return;
}
if (this._windowAdapter != null) {
this._windowAdapter.OnGUI();
}
}
}
}

3
Assets/UIWidgets/engine/WidgetCanvas.cs.meta


fileFormatVersion: 2
guid: 8ddcbbf7b3ab463692e623f84581e29a
timeCreated: 1545112466

/Assets/UIWidgets/rendering/automatic_keep_alive.cs → /Assets/UIWidgets/widgets/automatic_keep_alive.cs

/Assets/UIWidgets/rendering/automatic_keep_alive.cs.meta → /Assets/UIWidgets/widgets/automatic_keep_alive.cs.meta

正在加载...
取消
保存