diff --git a/README-ZH.md b/README-ZH.md index 3d717275..a1ce68a6 100644 --- a/README-ZH.md +++ b/README-ZH.md @@ -1,3 +1,5 @@ +⚠️ 本项目的开发与维护目前已转移至https://github.com/Unity-Technologies/com.unity.uiwidgets. 如果您遇到Issue或者对UIWidgets有任何意见和建议,请移步我们的新仓库。谢谢您的关注! + # UIWidgets diff --git a/README.md b/README.md index 485a94c8..e561546f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +⚠️ The main repository of UIWidgets has been moved to https://github.com/Unity-Technologies/com.unity.uiwidgets. Please visit the new site if you have an issue or want to contribute. Thanks! + # UIWidgets [中文](README-ZH.md) diff --git a/Runtime/Resources/shaders/UIWidgets_canvas.cginc b/Runtime/Resources/shaders/UIWidgets_canvas.cginc index 3f4fdaed..2f73499e 100644 --- a/Runtime/Resources/shaders/UIWidgets_canvas.cginc +++ b/Runtime/Resources/shaders/UIWidgets_canvas.cginc @@ -30,6 +30,18 @@ struct v2f { float2 fpos : TEXCOORD1; }; +inline half3 gamma_to_linear_space(half3 sRGB) { + return sRGB * (sRGB * (sRGB * 0.305306011h + 0.682171111h) + 0.012522878h); +} + +inline half4 adjust_color(half4 color) { +#ifdef UNITY_COLORSPACE_GAMMA + return color; +#else + color.rgb = gamma_to_linear_space(color.rgb); + return color; +#endif +} half shader_gradient_layout(half2 pos) { half4 p4 = half4(pos, 0.0, 1.0); @@ -50,9 +62,9 @@ half shader_gradient_layout(half2 pos) { half4 shader_gradient_colorize(half pt) { if (_tileMode == 0) { // clamp if (pt <= 0.0) { - return _leftColor; + return adjust_color(_leftColor); } else if (pt >= 1.0) { - return _rightColor; + return adjust_color(_rightColor); } half2 coord = half2(pt, 0.5); @@ -107,7 +119,7 @@ half4 shader_color (v2f i) { half4 c; #if defined(UIWIDGETS_COLOR) - c = _color; + c = adjust_color(_color); #elif defined(UIWIDGETS_IMAGE) half2 pt = shader_image_layout(i.fpos); c = shader_image_colorize(pt); diff --git a/Runtime/engine/UIWidgetsPanel.cs b/Runtime/engine/UIWidgetsPanel.cs index a72ffabf..c886fea3 100644 --- a/Runtime/engine/UIWidgetsPanel.cs +++ b/Runtime/engine/UIWidgetsPanel.cs @@ -138,6 +138,13 @@ void _handleViewMetricsChanged(string method, List args) { this._displayMetrics.onViewMetricsChanged(); } + protected virtual void InitWindowAdapter() { + D.assert(this._windowAdapter == null); + this._windowAdapter = new UIWidgetWindowAdapter(this); + + this._windowAdapter.OnEnable(); + } + protected override void OnEnable() { base.OnEnable(); @@ -153,10 +160,7 @@ protected override void OnEnable() { _repaintEvent = new Event {type = EventType.Repaint}; } - D.assert(this._windowAdapter == null); - this._windowAdapter = new UIWidgetWindowAdapter(this); - - this._windowAdapter.OnEnable(); + this.InitWindowAdapter(); Widget root; using (this._windowAdapter.getScope()) { diff --git a/Runtime/engine/raycastable.meta b/Runtime/engine/raycastable.meta new file mode 100644 index 00000000..4b305bd7 --- /dev/null +++ b/Runtime/engine/raycastable.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d8e15e1221dae40e68226ec6d8ed8ddb +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/engine/raycastable/RaycastManager.cs b/Runtime/engine/raycastable/RaycastManager.cs new file mode 100644 index 00000000..f9c7aca8 --- /dev/null +++ b/Runtime/engine/raycastable/RaycastManager.cs @@ -0,0 +1,125 @@ +using System.Collections.Generic; +using Unity.UIWidgets.foundation; +using Unity.UIWidgets.ui; +using UnityEngine; + +namespace Unity.UIWidgets.engine.raycast { + public class RaycastableRect { + bool _isDirty = true; + + public bool isDirty { + get { return this._isDirty; } + } + + public float left; + public float right; + public float top; + public float bottom; + + public void MarkDirty() { + this._isDirty = true; + } + + public void UnmarkDirty() { + this._isDirty = false; + } + + public void UpdateRect(float left, float top, float width, float height) { + this.left = left; + this.right = left + width; + this.top = top; + this.bottom = top + height; + } + + public bool CheckInRect(Vector2 pos) { + return pos.x >= this.left && + pos.x < this.right && + pos.y >= this.top && + pos.y < this.bottom; + } + } + + public class RaycastManager { + static RaycastManager _instance; + + public static RaycastManager instance { + get { + if (_instance == null) { + _instance = new RaycastManager(); + } + + return _instance; + } + } + + public readonly Dictionary> raycastHandlerMap = + new Dictionary>(); + + public static void NewWindow(int windowHashCode) { + if (!instance.raycastHandlerMap.ContainsKey(windowHashCode)) { + instance.raycastHandlerMap.Add(windowHashCode, new Dictionary()); + } + } + + public static void DisposeWindow(int windowHashCode) { + if (instance.raycastHandlerMap.ContainsKey(windowHashCode)) { + instance.raycastHandlerMap.Remove(windowHashCode); + } + } + + public static void AddToList(int widgetHashCode, int windowHashCode) { + D.assert(instance.raycastHandlerMap.ContainsKey(windowHashCode), () => + $"Raycast Handler Map doesn't contain Window {windowHashCode}, " + + $"Make sure using UIWidgetsRaycastablePanel instead of UIWidgetsPanel " + + $"while using RaycastableContainer."); + D.assert(!instance.raycastHandlerMap[windowHashCode].ContainsKey(widgetHashCode), () => + $"Raycast Handler Map already contains Widget {widgetHashCode} at Window {windowHashCode}"); + + instance.raycastHandlerMap[windowHashCode][widgetHashCode] = new RaycastableRect(); + } + + public static void MarkDirty(int widgetHashCode, int windowHashCode) { + D.assert(instance.raycastHandlerMap.ContainsKey(windowHashCode), () => + $"Raycast Handler Map doesn't contain Window {windowHashCode}"); + D.assert(instance.raycastHandlerMap[windowHashCode].ContainsKey(widgetHashCode), () => + $"Raycast Handler Map doesn't contain Widget {widgetHashCode} at Window {windowHashCode}"); + + instance.raycastHandlerMap[windowHashCode][widgetHashCode].MarkDirty(); + } + + public static void UpdateSizeOffset(int widgetHashCode, int windowHashCode, Size size, Offset offset) { + D.assert(instance.raycastHandlerMap.ContainsKey(windowHashCode), () => + $"Raycast Handler Map doesn't contain Window {windowHashCode}"); + D.assert(instance.raycastHandlerMap[windowHashCode].ContainsKey(widgetHashCode), () => + $"Raycast Handler Map doesn't contain Widget {widgetHashCode} at Window {windowHashCode}"); + + if (instance.raycastHandlerMap[windowHashCode][widgetHashCode].isDirty) { + instance.raycastHandlerMap[windowHashCode][widgetHashCode] + .UpdateRect(offset.dx, offset.dy, size.width, size.height); + instance.raycastHandlerMap[windowHashCode][widgetHashCode].UnmarkDirty(); + } + } + + public static void RemoveFromList(int widgetHashCode, int windowHashCode) { + D.assert(instance.raycastHandlerMap.ContainsKey(windowHashCode), () => + $"Raycast Handler Map doesn't contain Window {windowHashCode}"); + D.assert(instance.raycastHandlerMap[windowHashCode].ContainsKey(widgetHashCode), () => + $"Raycast Handler Map doesn't contain Widget {widgetHashCode} at Window {windowHashCode}"); + + instance.raycastHandlerMap[windowHashCode].Remove(widgetHashCode); + } + + public static bool CheckCastThrough(int windowHashCode, Vector2 pos) { + D.assert(instance.raycastHandlerMap.ContainsKey(windowHashCode), () => + $"Raycast Handler Map doesn't contain Window {windowHashCode}"); + + foreach (var item in instance.raycastHandlerMap[windowHashCode]) { + if (item.Value.CheckInRect(pos)) { + return false; + } + } + + return true; + } + } +} \ No newline at end of file diff --git a/Runtime/engine/raycastable/RaycastManager.cs.meta b/Runtime/engine/raycastable/RaycastManager.cs.meta new file mode 100644 index 00000000..74519d43 --- /dev/null +++ b/Runtime/engine/raycastable/RaycastManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9574f12b230354e6f87fc5fc0c98c96e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/engine/raycastable/RaycastableContainer.cs b/Runtime/engine/raycastable/RaycastableContainer.cs new file mode 100644 index 00000000..429d6524 --- /dev/null +++ b/Runtime/engine/raycastable/RaycastableContainer.cs @@ -0,0 +1,106 @@ +using Unity.UIWidgets.foundation; +using Unity.UIWidgets.rendering; +using Unity.UIWidgets.ui; +using Unity.UIWidgets.widgets; + +namespace Unity.UIWidgets.engine.raycast { + class RaycastableBox : SingleChildRenderObjectWidget { + public RaycastableBox( + Key key = null, + Widget child = null + ) : base(key, child) { + this.windowHashCode = Window.instance.GetHashCode(); + } + + readonly int windowHashCode; + + public override RenderObject createRenderObject(BuildContext context) { + return new RenderRaycastableBox( + windowHashCode: this.windowHashCode, + widget: this + ); + } + + public override Element createElement() { + return new _RaycastableBoxRenderElement(windowHashCode: this.windowHashCode, widget: this); + } + } + + class RenderRaycastableBox : RenderProxyBox { + public RenderRaycastableBox( + int windowHashCode, + RaycastableBox widget + ) { + this.widgetHashCode = widget.GetHashCode(); + this.windowHashCode = windowHashCode; + } + + readonly int widgetHashCode; + readonly int windowHashCode; + + public override void paint(PaintingContext context, Offset offset) { + RaycastManager.UpdateSizeOffset(this.widgetHashCode, this.windowHashCode, this.size, offset); + + base.paint(context, offset); + } + } + + class _RaycastableBoxRenderElement : SingleChildRenderObjectElement { + public _RaycastableBoxRenderElement( + int windowHashCode, + RaycastableBox widget + ) : base(widget) { + this.windowHashCode = windowHashCode; + } + + public new RaycastableBox widget { + get { return base.widget as RaycastableBox; } + } + + int widgetHashCode; + int windowHashCode; + + public override void mount(Element parent, object newSlot) { + this.widgetHashCode = this.widget.GetHashCode(); + RaycastManager.AddToList(this.widgetHashCode, this.windowHashCode); + base.mount(parent, newSlot); + } + + public override void update(Widget newWidget) { + RaycastManager.MarkDirty(this.widgetHashCode, this.windowHashCode); + base.update(newWidget); + } + + public override void unmount() { + RaycastManager.RemoveFromList(this.widgetHashCode, this.windowHashCode); + base.unmount(); + } + } + + public class RaycastableContainer : StatelessWidget { + public RaycastableContainer( + Widget child = null, + Key key = null + ) : base(key) { + this.child = child; + } + + public readonly Widget child; + + public override Widget build(BuildContext context) { + Widget current = this.child; + + if (this.child == null) { + current = new LimitedBox( + maxWidth: 0.0f, + maxHeight: 0.0f, + child: new ConstrainedBox(constraints: BoxConstraints.expand()) + ); + } + + current = new RaycastableBox(child: current); + + return current; + } + } +} \ No newline at end of file diff --git a/Runtime/engine/raycastable/RaycastableContainer.cs.meta b/Runtime/engine/raycastable/RaycastableContainer.cs.meta new file mode 100644 index 00000000..3bb75ef0 --- /dev/null +++ b/Runtime/engine/raycastable/RaycastableContainer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9af0c7d6aab134f5ba187ff34acf2377 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/engine/raycastable/UIWidgetsRaycastablePanel.cs b/Runtime/engine/raycastable/UIWidgetsRaycastablePanel.cs new file mode 100644 index 00000000..2fc70de1 --- /dev/null +++ b/Runtime/engine/raycastable/UIWidgetsRaycastablePanel.cs @@ -0,0 +1,40 @@ +using Unity.UIWidgets.engine; +using UnityEngine; + +namespace Unity.UIWidgets.engine.raycast { + [RequireComponent(typeof(RectTransform))] + public class UIWidgetsRaycastablePanel : UIWidgetsPanel, ICanvasRaycastFilter { + int windowHashCode; + + protected override void InitWindowAdapter() { + base.InitWindowAdapter(); + this.windowHashCode = this.window.GetHashCode(); + RaycastManager.NewWindow(this.windowHashCode); + } + + protected override void OnDisable() { + base.OnDisable(); + RaycastManager.DisposeWindow(this.windowHashCode); + } + + public bool IsRaycastLocationValid(Vector2 screenPoint, Camera eventCamera) { + if (!this.enabled) { + return true; + } + + Vector2 local; + RectTransformUtility.ScreenPointToLocalPointInRectangle(this.rectTransform, screenPoint, eventCamera, + out local); + + Rect rect = this.rectTransform.rect; + + // Convert top left corner as reference origin point. + local.x += this.rectTransform.pivot.x * rect.width; + local.y -= this.rectTransform.pivot.y * rect.height; + local.x = local.x / this.devicePixelRatio; + local.y = -local.y / this.devicePixelRatio; + + return !RaycastManager.CheckCastThrough(this.windowHashCode, local); + } + } +} \ No newline at end of file diff --git a/Runtime/engine/raycastable/UIWidgetsRaycastablePanel.cs.meta b/Runtime/engine/raycastable/UIWidgetsRaycastablePanel.cs.meta new file mode 100644 index 00000000..f5ff1f78 --- /dev/null +++ b/Runtime/engine/raycastable/UIWidgetsRaycastablePanel.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e5265d12f7193408b90993bdf987f058 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/external/RTree.cs b/Runtime/external/RTree.cs index 9e20da44..a1bbd8e4 100644 --- a/Runtime/external/RTree.cs +++ b/Runtime/external/RTree.cs @@ -3,7 +3,7 @@ using System.Linq; using Unity.UIWidgets.ui; -namespace Unity.UIWidgets.Runtime.external +namespace Unity.UIWidgets.external { public interface ISpatialData { diff --git a/Runtime/external/SplayTree.cs b/Runtime/external/SplayTree.cs index f35515ac..ac19690b 100644 --- a/Runtime/external/SplayTree.cs +++ b/Runtime/external/SplayTree.cs @@ -2,7 +2,7 @@ using System.Collections; using System.Collections.Generic; -namespace Unity.UIWidgets.Runtime.external +namespace Unity.UIWidgets.external { class SplayTree : IDictionary where TKey : IComparable { SplayTreeNode root; int count; diff --git a/Runtime/material/app.cs b/Runtime/material/app.cs index 0cdf9369..5cac48b1 100644 --- a/Runtime/material/app.cs +++ b/Runtime/material/app.cs @@ -39,7 +39,7 @@ public MaterialApp( ThemeData theme = null, ThemeData darkTheme = null, Locale locale = null, - List> localizationsDelegates = null, + List localizationsDelegates = null, LocaleListResolutionCallback localeListResolutionCallback = null, LocaleResolutionCallback localeResolutionCallback = null, List supportedLocales = null, @@ -92,7 +92,7 @@ public MaterialApp( public readonly Locale locale; - public readonly List> localizationsDelegates; + public readonly List localizationsDelegates; public readonly LocaleListResolutionCallback localeListResolutionCallback; diff --git a/Runtime/painting/gradient.cs b/Runtime/painting/gradient.cs index a4eafd51..b5feb006 100644 --- a/Runtime/painting/gradient.cs +++ b/Runtime/painting/gradient.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; using Unity.UIWidgets.foundation; -using Unity.UIWidgets.Runtime.external; +using Unity.UIWidgets.external; using Unity.UIWidgets.ui; using UnityEngine; using Color = Unity.UIWidgets.ui.Color; diff --git a/Runtime/rendering/sliver_fill.cs b/Runtime/rendering/sliver_fill.cs index bacf8abc..3562377b 100644 --- a/Runtime/rendering/sliver_fill.cs +++ b/Runtime/rendering/sliver_fill.cs @@ -81,7 +81,6 @@ protected override void performLayout() { } float paintedChildSize = this.calculatePaintOffset(this.constraints, from: 0.0f, to: extent); - Debug.Log("size" + paintedChildSize); D.assert(paintedChildSize.isFinite()); D.assert(paintedChildSize >= 0.0); this.geometry = new SliverGeometry( diff --git a/Runtime/rendering/table.cs b/Runtime/rendering/table.cs index f2022b3b..c0774716 100644 --- a/Runtime/rendering/table.cs +++ b/Runtime/rendering/table.cs @@ -841,12 +841,17 @@ List _computeColumnWidths(BoxConstraints constraints) { float deficit = tableWidth - maxWidthConstraint; int availableColumns = this.columns; - float minimumDeficit = 0.00000001f; - while (deficit > 0.0f && totalFlex > minimumDeficit) { + + //(Xingwei Zhu) this deficit is double and set to be 0.00000001f in flutter. + //since we use float by default, making it larger should make sense in most cases + float minimumDeficit = 0.0001f; + while (deficit > minimumDeficit && totalFlex > minimumDeficit) { float newTotalFlex = 0.0f; for (int x = 0; x < this.columns; x++) { if (flexes[x] != null) { - float newWidth = widths[x] - deficit * flexes[x].Value / totalFlex; + //(Xingwei Zhu) in case deficit * flexes[x].Value / totalFlex => 0 if deficit is really small, leading to dead loop, + //we amend it with a default larger value to ensure that this loop will eventually end + float newWidth = widths[x] - Mathf.Max(minimumDeficit, deficit * flexes[x].Value / totalFlex); D.assert(newWidth.isFinite()); if (newWidth <= minWidths[x]) { deficit -= widths[x] - minWidths[x]; diff --git a/Runtime/ui/painting/picture.cs b/Runtime/ui/painting/picture.cs index d8e03c83..81e189f3 100644 --- a/Runtime/ui/painting/picture.cs +++ b/Runtime/ui/painting/picture.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using Unity.UIWidgets.foundation; -using Unity.UIWidgets.Runtime.external; +using Unity.UIWidgets.external; namespace Unity.UIWidgets.ui { public class Picture { diff --git a/Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_impl.cs b/Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_impl.cs index 1441b1c9..3532a0bf 100644 --- a/Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_impl.cs +++ b/Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_impl.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; using Unity.UIWidgets.foundation; -using Unity.UIWidgets.Runtime.external; +using Unity.UIWidgets.external; using UnityEngine; using UnityEngine.Rendering; @@ -772,16 +772,16 @@ void _drawPicture(Picture picture, bool needsSave = true) { .mapRect(this._currentLayer.layerBounds) ?? this._currentLayer.layerBounds; - if (!uiRectHelper.contains(queryBound, uiRectHelper.fromRect(picture.paintBounds).Value)) { - var indices = picture.bbh.Search(queryBound).Select(bound => bound.index); - List cmdIndices = indices.ToList(); - cmdIndices.AddRange(picture.stateUpdatesIndices); - cmdIndices.Sort(); - drawCmds = new List(); - for (int i = 0; i < cmdIndices.Count; i++) { - drawCmds.Add(picture.drawCmds[cmdIndices[i]]); - } - } + // if (!uiRectHelper.contains(queryBound, uiRectHelper.fromRect(picture.paintBounds).Value)) { + // var indices = picture.bbh.Search(queryBound).Select(bound => bound.index); + // List cmdIndices = indices.ToList(); + // cmdIndices.AddRange(picture.stateUpdatesIndices); + // cmdIndices.Sort(); + // drawCmds = new List(); + // for (int i = 0; i < cmdIndices.Count; i++) { + // drawCmds.Add(picture.drawCmds[cmdIndices[i]]); + // } + // } foreach (var drawCmd in drawCmds) { switch (drawCmd) { @@ -920,19 +920,19 @@ void _drawUIPicture(uiPicture picture, bool needsSave = true) { .mapRect(this._currentLayer.layerBounds) ?? this._currentLayer.layerBounds; - if (!uiRectHelper.contains(queryBound, picture.paintBounds)) { - var indices = picture.bbh.Search(queryBound).Select(bound => bound.index); - List cmdIndices = indices.ToList(); - cmdIndices.Capacity += picture.stateUpdatesIndices.Count; - for (int i = 0; i < picture.stateUpdatesIndices.Count; i++) { - cmdIndices.Add(picture.stateUpdatesIndices[i]); - } - cmdIndices.Sort(); - drawCmds = new List(); - for (int i = 0; i < cmdIndices.Count; i++) { - drawCmds.Add(picture.drawCmds[cmdIndices[i]]); - } - } + // if (!uiRectHelper.contains(queryBound, picture.paintBounds)) { + // var indices = picture.bbh.Search(queryBound).Select(bound => bound.index); + // List cmdIndices = indices.ToList(); + // cmdIndices.Capacity += picture.stateUpdatesIndices.Count; + // for (int i = 0; i < picture.stateUpdatesIndices.Count; i++) { + // cmdIndices.Add(picture.stateUpdatesIndices[i]); + // } + // cmdIndices.Sort(); + // drawCmds = new List(); + // for (int i = 0; i < cmdIndices.Count; i++) { + // drawCmds.Add(picture.drawCmds[cmdIndices[i]]); + // } + // } foreach (var drawCmd in drawCmds) { switch (drawCmd) { diff --git a/Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shader.cs b/Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shader.cs index 970a48d0..914a863d 100644 --- a/Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shader.cs +++ b/Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shader.cs @@ -425,7 +425,7 @@ public static PictureFlusher.CmdDraw tex(PictureFlusher.RenderLayer layer, uiPai image.texture.filterMode = paint.filterMode; props.SetTexture(_texId, image.texture); - props.SetInt(_texModeId, image.texture is RenderTexture ? 1 : 0); // pre alpha if RT else post alpha + props.SetInt(_texModeId, image.texture is RenderTexture || image.isDynamic ? 1 : 0); // pre alpha if RT else post alpha return PictureFlusher.CmdDraw.create( mesh: mesh, diff --git a/Runtime/ui/renderer/common/picture.cs b/Runtime/ui/renderer/common/picture.cs index 15496bdd..92ed8da5 100644 --- a/Runtime/ui/renderer/common/picture.cs +++ b/Runtime/ui/renderer/common/picture.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using Unity.UIWidgets.foundation; -using Unity.UIWidgets.Runtime.external; +using Unity.UIWidgets.external; namespace Unity.UIWidgets.ui { public class uiPicture : PoolObject { diff --git a/Runtime/ui/txt/paragraph.cs b/Runtime/ui/txt/paragraph.cs index 8304485f..4394344a 100644 --- a/Runtime/ui/txt/paragraph.cs +++ b/Runtime/ui/txt/paragraph.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using Unity.UIWidgets.foundation; -using Unity.UIWidgets.Runtime.external; +using Unity.UIWidgets.external; using UnityEngine; namespace Unity.UIWidgets.ui { diff --git a/Runtime/widgets/implicit_animations.cs b/Runtime/widgets/implicit_animations.cs index 82c8caee..9bff67c3 100644 --- a/Runtime/widgets/implicit_animations.cs +++ b/Runtime/widgets/implicit_animations.cs @@ -437,6 +437,275 @@ public override void debugFillProperties(DiagnosticPropertiesBuilder description } } + public class AnimatedAlign : ImplicitlyAnimatedWidget { + public AnimatedAlign( + Key key = null, + Alignment alignment = null, + Widget child = null, + Curve curve = null, + TimeSpan? duration = null + ) : base(key: key, curve: curve ?? Curves.linear, duration: duration) { + D.assert(alignment != null); + this.alignment = alignment; + this.child = child; + } + + public readonly Alignment alignment; + + public readonly Widget child; + + public override State createState() { + return new _AnimatedAlignState(); + } + + public override void debugFillProperties(DiagnosticPropertiesBuilder properties) { + base.debugFillProperties(properties: properties); + properties.add(new DiagnosticsProperty("alignment", value: this.alignment)); + } + } + + class _AnimatedAlignState : AnimatedWidgetBaseState { + AlignmentTween _alignment; + + protected override void forEachTween(TweenVisitor visitor) { + this._alignment = (AlignmentTween) visitor.visit(this, tween: this._alignment, + targetValue: this.widget.alignment, constructor: value => new AlignmentTween(begin: value)); + } + + public override Widget build(BuildContext context) { + return new Align( + alignment: this._alignment.evaluate(animation: this.animation), + child: this.widget.child + ); + } + + public override void debugFillProperties(DiagnosticPropertiesBuilder description) { + base.debugFillProperties(properties: description); + description.add(new DiagnosticsProperty("alignment", value: this._alignment, defaultValue: null)); + } + } + + public class AnimatedPositioned : ImplicitlyAnimatedWidget { + public AnimatedPositioned( + Key key = null, + Widget child = null, + float? left = null, + float? top = null, + float? right = null, + float? bottom = null, + float? width = null, + float? height = null, + Curve curve = null, + TimeSpan? duration = null + ) : base(key: key, curve: curve ?? Curves.linear, duration: duration) { + D.assert(left == null || right == null || width == null); + D.assert(top == null || bottom == null || height == null); + this.child = child; + this.left = left; + this.top = top; + this.right = right; + this.bottom = bottom; + this.width = width; + this.height = height; + } + + public static AnimatedPositioned fromRect( + Key key = null, + Widget child = null, + Rect rect = null, + Curve curve = null, + TimeSpan? duration = null + ) { + return new AnimatedPositioned( + child: child, + duration: duration, + left: rect.left, + top: rect.top, + right: null, + bottom: null, + width: rect.width, + height: rect.height, + curve: curve ?? Curves.linear, + key: key + ); + } + + public readonly Widget child; + + public readonly float? left; + + public readonly float? top; + + public readonly float? right; + + public readonly float? bottom; + + public readonly float? width; + + public readonly float? height; + + public override State createState() { + return new _AnimatedPositionedState(); + } + + public override void debugFillProperties(DiagnosticPropertiesBuilder properties) { + base.debugFillProperties(properties: properties); + properties.add(new FloatProperty("left", value: this.left, defaultValue: null)); + properties.add(new FloatProperty("top", value: this.top, defaultValue: null)); + properties.add(new FloatProperty("right", value: this.right, defaultValue: null)); + properties.add(new FloatProperty("bottom", value: this.bottom, defaultValue: null)); + properties.add(new FloatProperty("width", value: this.width, defaultValue: null)); + properties.add(new FloatProperty("height", value: this.height, defaultValue: null)); + } + } + + class _AnimatedPositionedState : AnimatedWidgetBaseState { + Tween _left; + Tween _top; + Tween _right; + Tween _bottom; + Tween _width; + Tween _height; + + protected override void forEachTween(TweenVisitor visitor) { + this._left = visitor.visit(this, tween: this._left, targetValue: this.widget.left, + constructor: value => new NullableFloatTween(begin: value)); + this._top = visitor.visit(this, tween: this._top, targetValue: this.widget.top, + constructor: value => new NullableFloatTween(begin: value)); + this._right = visitor.visit(this, tween: this._right, targetValue: this.widget.right, + constructor: value => new NullableFloatTween(begin: value)); + this._bottom = visitor.visit(this, tween: this._bottom, targetValue: this.widget.bottom, + constructor: value => new NullableFloatTween(begin: value)); + this._width = visitor.visit(this, tween: this._width, targetValue: this.widget.width, + constructor: value => new NullableFloatTween(begin: value)); + this._height = visitor.visit(this, tween: this._height, targetValue: this.widget.height, + constructor: value => new NullableFloatTween(begin: value)); + } + + public override Widget build(BuildContext context) { + return new Positioned( + child: this.widget.child, + left: this._left?.evaluate(animation: this.animation), + top: this._top?.evaluate(animation: this.animation), + right: this._right?.evaluate(animation: this.animation), + bottom: this._bottom?.evaluate(animation: this.animation), + width: this._width?.evaluate(animation: this.animation), + height: this._height?.evaluate(animation: this.animation) + ); + } + + public override void debugFillProperties(DiagnosticPropertiesBuilder description) { + base.debugFillProperties(properties: description); + description.add(ObjectFlagProperty>.has("left", value: this._left)); + description.add(ObjectFlagProperty>.has("top", value: this._top)); + description.add(ObjectFlagProperty>.has("right", value: this._right)); + description.add(ObjectFlagProperty>.has("bottom", value: this._bottom)); + description.add(ObjectFlagProperty>.has("width", value: this._width)); + description.add(ObjectFlagProperty>.has("height", value: this._height)); + } + } + + public class AnimatedPositionedDirectional : ImplicitlyAnimatedWidget { + public AnimatedPositionedDirectional( + Key key = null, + Widget child = null, + float? start = null, + float? top = null, + float? end = null, + float? bottom = null, + float? width = null, + float? height = null, + Curve curve = null, + TimeSpan? duration = null + ) : base(key: key, curve: curve, duration: duration) { + D.assert(start == null || end == null || width == null); + D.assert(top == null || bottom == null || height == null); + this.child = child; + this.start = start; + this.top = top; + this.end = end; + this.bottom = bottom; + this.width = width; + this.height = height; + } + + public readonly Widget child; + + public readonly float? start; + + public readonly float? top; + + public readonly float? end; + + public readonly float? bottom; + + public readonly float? width; + + public readonly float? height; + + public override State createState() { + return new _AnimatedPositionedDirectionalState(); + } + + public override void debugFillProperties(DiagnosticPropertiesBuilder properties) { + base.debugFillProperties(properties: properties); + properties.add(new FloatProperty("start", value: this.start, defaultValue: null)); + properties.add(new FloatProperty("top", value: this.top, defaultValue: null)); + properties.add(new FloatProperty("end", value: this.end, defaultValue: null)); + properties.add(new FloatProperty("bottom", value: this.bottom, defaultValue: null)); + properties.add(new FloatProperty("width", value: this.width, defaultValue: null)); + properties.add(new FloatProperty("height", value: this.height, defaultValue: null)); + } + } + + class _AnimatedPositionedDirectionalState : AnimatedWidgetBaseState { + Tween _start; + Tween _top; + Tween _end; + Tween _bottom; + Tween _width; + Tween _height; + + protected override void forEachTween(TweenVisitor visitor) { + this._start = visitor.visit(this, tween: this._start, targetValue: this.widget.start, + constructor: value => new NullableFloatTween(begin: value)); + this._top = visitor.visit(this, tween: this._top, targetValue: this.widget.top, + constructor: value => new NullableFloatTween(begin: value)); + this._end = visitor.visit(this, tween: this._end, targetValue: this.widget.end, + constructor: value => new NullableFloatTween(begin: value)); + this._bottom = visitor.visit(this, tween: this._bottom, targetValue: this.widget.bottom, + constructor: value => new NullableFloatTween(begin: value)); + this._width = visitor.visit(this, tween: this._width, targetValue: this.widget.width, + constructor: value => new NullableFloatTween(begin: value)); + this._height = visitor.visit(this, tween: this._height, targetValue: this.widget.height, + constructor: value => new NullableFloatTween(begin: value)); + } + + public override Widget build(BuildContext context) { + D.assert(WidgetsD.debugCheckHasDirectionality(context)); + return Positioned.directional( + textDirection: Directionality.of(context: context), + child: this.widget.child, + start: this._start?.evaluate(animation: this.animation), + top: this._top?.evaluate(animation: this.animation), + end: this._end?.evaluate(animation: this.animation), + bottom: this._bottom?.evaluate(animation: this.animation), + width: this._width?.evaluate(animation: this.animation), + height: this._height?.evaluate(animation: this.animation) + ); + } + + public override void debugFillProperties(DiagnosticPropertiesBuilder description) { + base.debugFillProperties(properties: description); + description.add(ObjectFlagProperty>.has("start", value: this._start)); + description.add(ObjectFlagProperty>.has("top", value: this._top)); + description.add(ObjectFlagProperty>.has("end", value: this._end)); + description.add(ObjectFlagProperty>.has("bottom", value: this._bottom)); + description.add(ObjectFlagProperty>.has("width", value: this._width)); + description.add(ObjectFlagProperty>.has("height", value: this._height)); + } + } + public class AnimatedOpacity : ImplicitlyAnimatedWidget { public AnimatedOpacity( Key key = null, diff --git a/Runtime/widgets/list_wheel_scroll_view.cs b/Runtime/widgets/list_wheel_scroll_view.cs index 9aae4085..94b4f324 100644 --- a/Runtime/widgets/list_wheel_scroll_view.cs +++ b/Runtime/widgets/list_wheel_scroll_view.cs @@ -6,7 +6,7 @@ using Unity.UIWidgets.painting; using Unity.UIWidgets.physics; using Unity.UIWidgets.rendering; -using Unity.UIWidgets.Runtime.external; +using Unity.UIWidgets.external; using Unity.UIWidgets.scheduler; using Unity.UIWidgets.ui; using UnityEngine; diff --git a/Runtime/widgets/sliver.cs b/Runtime/widgets/sliver.cs index 8a52d4eb..6e8970ce 100644 --- a/Runtime/widgets/sliver.cs +++ b/Runtime/widgets/sliver.cs @@ -5,7 +5,7 @@ using Unity.UIWidgets.foundation; using Unity.UIWidgets.painting; using Unity.UIWidgets.rendering; -using Unity.UIWidgets.Runtime.external; +using Unity.UIWidgets.external; using Unity.UIWidgets.ui; namespace Unity.UIWidgets.widgets { @@ -587,7 +587,7 @@ public override void debugVisitOnstageChildren(ElementVisitor visitor) { } } - class SliverFillRemaining : SingleChildRenderObjectWidget { + public class SliverFillRemaining : SingleChildRenderObjectWidget { public SliverFillRemaining( Key key = null, Widget child = null @@ -632,4 +632,4 @@ public override void debugFillProperties(DiagnosticPropertiesBuilder properties) properties.add(new DiagnosticsProperty("keepAlive", this.keepAlive)); } } -} \ No newline at end of file +}