浏览代码

update widget

/main
gewentao 6 年前
当前提交
079a76fa
共有 8 个文件被更改,包括 247 次插入27 次删除
  1. 7
      Assets/UIWidgets/ui/window.cs
  2. 145
      Assets/UIWidgets/widgets/binding.cs
  3. 33
      Assets/UIWidgets/widgets/framework.cs
  4. 8
      Assets/UIWidgets/widgets/image.cs
  5. 45
      Assets/UIWidgets/rendering/error.cs
  6. 3
      Assets/UIWidgets/rendering/error.cs.meta
  7. 30
      Assets/UIWidgets/widgets/ticker_provider.cs
  8. 3
      Assets/UIWidgets/widgets/ticker_provider.cs.meta

7
Assets/UIWidgets/ui/window.cs


private VoidCallback _onLocaleChanged;
public VoidCallback onAccessibilityFeaturesChanged {
get { return this._onAccessibilityFeaturesChanged; }
set { this._onAccessibilityFeaturesChanged = value; }
}
private VoidCallback _onAccessibilityFeaturesChanged;
public FrameCallback onBeginFrame {
get { return this._onBeginFrame; }
set { this._onBeginFrame = value; }

145
Assets/UIWidgets/widgets/binding.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.Assertions;
abstract class WidgetsBinding : RendererBinding {
interface WidgetsBindingObserver {
void didChangeMetrics();
}
abstract class WidgetsBinding : RendererBinding {
window.onAccessibilityFeaturesChanged += handleAccessibilityFeaturesChanged;
public BuildOwner buildOwner {
get { return this._buildOwner; }
}

public Element renderViewElement {
get { return this._renderViewElement; }
}
public List<WidgetsBindingObserver> _observers = new List<WidgetsBindingObserver>();
void addObserver(WidgetsBindingObserver observer) {
_observers.Add(observer);
}
protected override void handleMetricsChanged() {
base.handleMetricsChanged();
foreach (WidgetsBindingObserver observer in _observers) {
observer.didChangeMetrics();
}
}
bool removeObserver(WidgetsBindingObserver observer) {
return _observers.Remove(observer);
}
void handleAccessibilityFeaturesChanged() {
// for (WidgetsBindingObserver observer in _observers) {
// observer.didChangeAccessibilityFeatures();
// }
}
}
void attachRootWidget(Widget rootWidget) {
_renderViewElement = new RenderObjectToWidgetAdapter<RenderBox>(
container: renderView,
child: rootWidget
).attachToRenderTree(buildOwner, _renderViewElement as RenderObjectToWidgetElement<RenderBox>);
}
}
public class RenderObjectToWidgetAdapter<T> : RenderObjectWidget where T : RenderObject {
public RenderObjectToWidgetAdapter(Widget child, RenderObjectWithChildMixinRenderObject<T> container) : base(
new GlobalObjectKey(container)) {
this.child = child;
this.container = container;
}
public Widget child;
public RenderObjectWithChildMixinRenderObject<T> container;
public String debugShortDescription;
public override Element createElement() {
return new RenderObjectToWidgetElement<T>(this);
}
public override RenderObject createRenderObject(BuildContext context) {
return container;
}
public void updateRenderObject(BuildContext context, RenderObject renderObject) {
}
public RenderObjectToWidgetElement<T> attachToRenderTree(BuildOwner owner, RenderObjectToWidgetElement<T> element) {
if (element == null) {
// lock state?
element = (RenderObjectToWidgetElement<T>) createElement();
element.assignOwner(owner);
owner.buildScope(element, () => { element.mount(null, null); });
}
else {
element._newWidget = this;
element.markNeedsBuild();
}
return element;
}
}
public class RenderObjectToWidgetElement<T> : RootRenderObjectElement where T : RenderObject {
public RenderObjectToWidgetElement(RenderObjectWidget widget) : base(widget) {
}
public RenderObjectToWidgetAdapter<T> widget {
get { return (RenderObjectToWidgetAdapter<T>) base.widget; }
}
Element _child;
static readonly object _rootChildSlot = new object();
public Widget _newWidget;
public override void visitChildren(ElementVisitor visitor) {
if (_child != null)
visitor(_child);
}
public override void forgetChild(Element child) {
D.assert(child == _child);
_child = null;
}
public override void mount(Element parent, object newSlot) {
D.assert(parent == null);
base.mount(parent, newSlot);
_rebuild();
}
public override void update(Widget newWidget) {
base.update(newWidget);
D.assert(widget == newWidget);
_rebuild();
}
public override void performRebuild() {
if (_newWidget != null) {
Widget newWidget = _newWidget;
_newWidget = null;
update(newWidget);
}
base.performRebuild();
D.assert(_newWidget == null);
}
void _rebuild() {
try {
_child = updateChild(_child, widget.child, _rootChildSlot);
D.assert(_child != null);
}
catch (Exception e) {
Widget error = ErrorWidget.builder(e);
_child = updateChild(null, error, _rootChildSlot);
}
}
}
}

33
Assets/UIWidgets/widgets/framework.cs


public abstract void performRebuild();
}
public delegate Widget ErrorWidgetBuilder(object exception);
public class ErrorWidget : LeafRenderObjectWidget {
public ErrorWidget(object exception) : base(new UniqueKey()) {
message = _stringify(exception);
}
public static ErrorWidgetBuilder builder = exception => { return new ErrorWidget(exception); };
public String message;
static String _stringify(object exception) {
try {
return exception.ToString();
}
catch (Exception e) {
} // ignore: empty_catches
return "Error";
}
public override RenderObject createRenderObject(BuildContext context) {
return new RenderErrorBox(message);
}
}
public abstract class ComponentElement : Element {
protected ComponentElement(Widget widget) : base(widget) {

public abstract class ProxyElement : ComponentElement {
protected ProxyElement(Widget widget) : base(widget) {
}
public ProxyWidget widget {
get { return (ProxyWidget) base.widget; }
}

public class InheritedElement : ProxyElement {
public InheritedElement(Widget widget) : base(widget) {
}
public HashSet<Element> _dependents = new HashSet<Element>();
public void _updateInheritance() {

8
Assets/UIWidgets/widgets/image.cs


public override void didChangeDependencies() {
_resolveImage();
// if (TickerMode.of(context))
// _listenToStream();
// else
// _stopListeningToStream();
if (TickerMode.of(context))
_listenToStream();
else
_stopListeningToStream();
}
public override void didUpdateWidget(StatefulWidget oldWidget) {

45
Assets/UIWidgets/rendering/error.cs


using System;
using System.Collections.Generic;
using UIWidgets.foundation;
using UIWidgets.gestures;
using UIWidgets.painting;
using UIWidgets.ui;
using UnityEngine;
using Rect = UIWidgets.ui.Rect;
namespace UIWidgets.rendering {
public class RenderErrorBox : RenderBox {
const double _kMaxWidth = 100000.0;
const double _kMaxHeight = 100000.0;
const string _kLine = "\n\n────────────────────\n\n";
public RenderErrorBox(string message = "") {
this.message = message;
if (message == "") return;
ui.ParagraphBuilder builder = new ui.ParagraphBuilder(paragraphStyle);
builder.pushStyle(textStyle);
builder.addText(
string.Format(
"{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}{16}{17}{18}{19}{20}{21}{22}{23}",
message, _kLine, message, _kLine, message, _kLine, message, _kLine, message, _kLine, message,
_kLine, message, _kLine, message, _kLine, message, _kLine, message, _kLine, message, _kLine,
message, _kLine)
);
_paragraph = builder.build();
}
private string message;
ui.Paragraph _paragraph;
static ui.TextStyle textStyle = new ui.TextStyle(
color: new ui.Color(0xFFFFFF66),
fontFamily: "monospace",
fontSize: 14.0,
fontWeight: FontWeight.w700
);
static ui.ParagraphStyle paragraphStyle = new ui.ParagraphStyle(
lineHeight: 1.0
);
}
}

3
Assets/UIWidgets/rendering/error.cs.meta


fileFormatVersion: 2
guid: 64dfb38ea47d49c7b9f3d0debeee4409
timeCreated: 1536819405

30
Assets/UIWidgets/widgets/ticker_provider.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UIWidgets.foundation;
using UIWidgets.rendering;
using UIWidgets.ui;
using UnityEngine.Assertions;
namespace UIWidgets.widgets {
public class TickerMode : InheritedWidget {
public TickerMode(string key, bool enabled, Widget child) : base(key, child) {
this.enabled = enabled;
}
public readonly bool enabled;
public static bool of(BuildContext context) {
var widget = context.inheritFromWidgetOfExactType(typeof(TickerMode));
return widget is TickerMode ? (widget as TickerMode).enabled : true;
}
public override bool updateShouldNotify(InheritedWidget oldWidget) {
return this.enabled != ((TickerMode)oldWidget).enabled;
}
public override Element createElement() {
throw new NotImplementedException();
}
}
}

3
Assets/UIWidgets/widgets/ticker_provider.cs.meta


fileFormatVersion: 2
guid: aa6922a60d7945ffb3b92dede5941836
timeCreated: 1536807803
正在加载...
取消
保存