浏览代码

Merge branch 'master' into yczhang_material

/main
Yuncong Zhang 6 年前
当前提交
97fc1ca3
共有 27 个文件被更改,包括 1910 次插入143 次删除
  1. 27
      Runtime/foundation/debug.cs
  2. 15
      Runtime/material/theme_data.cs
  3. 26
      Runtime/rendering/layer.cs
  4. 34
      Runtime/rendering/proxy_box.cs
  5. 8
      Runtime/ui/compositing.cs
  6. 201
      Runtime/ui/painting/canvas_impl.cs
  7. 52
      Runtime/ui/painting/canvas_shader.cs
  8. 3
      Runtime/ui/painting/painting.cs
  9. 6
      Runtime/widgets/app.cs
  10. 21
      Runtime/widgets/basic.cs
  11. 12
      Runtime/widgets/preferred_size.cs
  12. 81
      Samples/UIWidgetSample/MaterialSample.cs
  13. 56
      Tests/Editor/CanvasAndLayers.cs
  14. 24
      Tests/Editor/Widgets.cs
  15. 25
      Runtime/flow/backdrop_filter_layer.cs
  16. 11
      Runtime/flow/backdrop_filter_layer.cs.meta
  17. 107
      Runtime/material/tab_bar_theme.cs
  18. 11
      Runtime/material/tab_bar_theme.cs.meta
  19. 187
      Runtime/material/tab_controller.cs
  20. 11
      Runtime/material/tab_controller.cs.meta
  21. 90
      Runtime/material/tab_indicator.cs
  22. 11
      Runtime/material/tab_indicator.cs.meta
  23. 1001
      Runtime/material/tabs.cs
  24. 11
      Runtime/material/tabs.cs.meta
  25. 11
      Runtime/widgets/preferred_size.cs.meta
  26. 11
      Runtime/widgets/perferred_size.cs.meta
  27. 0
      /Runtime/widgets/preferred_size.cs

27
Runtime/foundation/debug.cs


public static class D {
public static void logError(string message, Exception ex = null) {
Debug.LogException(new ReportError(message, ex));
Debug.LogException(new AssertionError(message, ex));
}
[Conditional("UIWidgets_DEBUG")]
public static void assert(Func<bool> result, string message = null) {

[Serializable]
public class AssertionError : Exception {
readonly Exception innerException;
public override string StackTrace {
get {
var stackTrace = base.StackTrace;
var lines = stackTrace.Split('\n');
var strippedLines = lines.Skip(1);
return string.Join("\n", strippedLines);
}
}
}
public class ReportError : Exception {
Exception ex;
public ReportError(string message, Exception ex = null) : base(message) {
this.ex = ex;
public AssertionError(string message, Exception innerException = null) : base(message) {
this.innerException = innerException;
if (this.ex != null) {
return this.ex.StackTrace;
if (this.innerException != null) {
return this.innerException.StackTrace;
}
var stackTrace = base.StackTrace;

return string.Join("\n", strippedLines);
}
}
}
}

15
Runtime/material/theme_data.cs


IconThemeData iconTheme = null,
IconThemeData primaryIconTheme = null,
IconThemeData accentIconTheme = null,
TabBarTheme tabBarTheme = null,
RuntimePlatform? platform = null,
MaterialTapTargetSize? materialTapTargetSize = null,
PageTransitionsTheme pageTransitionsTheme = null,

? ThemeDataUtils._kDarkThemeSplashColor
: ThemeDataUtils._kLightThemeSplashColor);
tabBarTheme = tabBarTheme ?? new TabBarTheme();
dialogTheme = dialogTheme ?? new DialogTheme();
D.assert(brightness != null);

D.assert(colorScheme != null);
D.assert(typography != null);
D.assert(buttonColor != null);
D.assert(tabBarTheme != null);
D.assert(dialogTheme != null);
this.brightness = brightness ?? Brightness.light;

this.iconTheme = iconTheme;
this.primaryIconTheme = primaryIconTheme;
this.accentIconTheme = accentIconTheme;
this.tabBarTheme = tabBarTheme;
this.platform = platform.Value;
this.materialTapTargetSize = materialTapTargetSize ?? MaterialTapTargetSize.padded;
this.pageTransitionsTheme = pageTransitionsTheme;

IconThemeData iconTheme = null,
IconThemeData primaryIconTheme = null,
IconThemeData accentIconTheme = null,
TabBarTheme tabBarTheme = null,
RuntimePlatform? platform = null,
MaterialTapTargetSize? materialTapTargetSize = null,
PageTransitionsTheme pageTransitionsTheme = null,

D.assert(colorScheme != null);
D.assert(typography != null);
D.assert(buttonColor != null);
D.assert(tabBarTheme != null);
D.assert(dialogTheme != null);
return new ThemeData(

iconTheme: iconTheme,
primaryIconTheme: primaryIconTheme,
accentIconTheme: accentIconTheme,
tabBarTheme: tabBarTheme,
platform: platform,
materialTapTargetSize: materialTapTargetSize,
pageTransitionsTheme: pageTransitionsTheme,

public readonly IconThemeData accentIconTheme;
public readonly TabBarTheme tabBarTheme;
public readonly RuntimePlatform platform;
public readonly MaterialTapTargetSize materialTapTargetSize;

IconThemeData iconTheme = null,
IconThemeData primaryIconTheme = null,
IconThemeData accentIconTheme = null,
TabBarTheme tabBarTheme = null,
RuntimePlatform? platform = null,
MaterialTapTargetSize? materialTapTargetSize = null,
PageTransitionsTheme pageTransitionsTheme = null,

iconTheme: iconTheme ?? this.iconTheme,
primaryIconTheme: primaryIconTheme ?? this.primaryIconTheme,
accentIconTheme: accentIconTheme ?? this.accentIconTheme,
tabBarTheme: tabBarTheme ?? this.tabBarTheme,
platform: platform ?? this.platform,
materialTapTargetSize: materialTapTargetSize ?? this.materialTapTargetSize,
pageTransitionsTheme: pageTransitionsTheme ?? this.pageTransitionsTheme,

iconTheme: IconThemeData.lerp(a.iconTheme, b.iconTheme, t),
primaryIconTheme: IconThemeData.lerp(a.primaryIconTheme, b.primaryIconTheme, t),
accentIconTheme: IconThemeData.lerp(a.accentIconTheme, b.accentIconTheme, t),
tabBarTheme: TabBarTheme.lerp(a.tabBarTheme, b.tabBarTheme, t),
platform: t < 0.5 ? a.platform : b.platform,
materialTapTargetSize: t < 0.5 ? a.materialTapTargetSize : b.materialTapTargetSize,
pageTransitionsTheme: t < 0.5 ? a.pageTransitionsTheme : b.pageTransitionsTheme,

other.iconTheme == this.iconTheme &&
other.primaryIconTheme == this.primaryIconTheme &&
other.accentIconTheme == this.accentIconTheme &&
other.tabBarTheme == this.tabBarTheme &&
other.platform == this.platform &&
other.materialTapTargetSize == this.materialTapTargetSize &&
other.pageTransitionsTheme == this.pageTransitionsTheme &&

hashCode = (hashCode * 397) ^ this.iconTheme.GetHashCode();
hashCode = (hashCode * 397) ^ this.primaryIconTheme.GetHashCode();
hashCode = (hashCode * 397) ^ this.accentIconTheme.GetHashCode();
hashCode = (hashCode * 397) ^ this.tabBarTheme.GetHashCode();
hashCode = (hashCode * 397) ^ this.platform.GetHashCode();
hashCode = (hashCode * 397) ^ this.materialTapTargetSize.GetHashCode();
hashCode = (hashCode * 397) ^ this.pageTransitionsTheme.GetHashCode();

properties.add(new DiagnosticsProperty<IconThemeData>("iconTheme", this.iconTheme));
properties.add(new DiagnosticsProperty<IconThemeData>("primaryIconTheme", this.primaryIconTheme));
properties.add(new DiagnosticsProperty<IconThemeData>("accentIconTheme", this.accentIconTheme));
properties.add(new DiagnosticsProperty<TabBarTheme>("tabBarTheme", this.tabBarTheme));
properties.add(
new DiagnosticsProperty<MaterialTapTargetSize>("materialTapTargetSize", this.materialTapTargetSize));
properties.add(

26
Runtime/rendering/layer.cs


properties.add(new DiagnosticsProperty<Offset>("offset", this.offset));
}
}
public class BackdropFilterLayer : ContainerLayer {
public BackdropFilterLayer(ImageFilter filter = null) {
D.assert(filter != null);
this._filter = filter;
}
ImageFilter _filter;
public ImageFilter filter {
get { return this._filter; }
set {
if (value != this._filter) {
this._filter = value;
this.markNeedsAddToScene();
}
}
}
internal override flow.Layer addToScene(SceneBuilder builder, Offset layerOffset = null) {
builder.pushBackdropFilter(this.filter);
this.addChildrenToScene(builder, layerOffset);
builder.pop();
return null;
}
}
public class LayerLink {
public LeaderLayer leader {

34
Runtime/rendering/proxy_box.cs


}
}
public class RenderBackdropFilter : RenderProxyBox {
public RenderBackdropFilter(
RenderBox child = null,
ImageFilter filter = null
) : base(child) {
D.assert(filter != null);
this._filter = filter;
}
ImageFilter _filter;
public ImageFilter filter {
get { return this._filter; }
set {
D.assert(value != null);
if (this._filter == value) {
return;
}
this.markNeedsPaint();
}
}
protected override bool alwaysNeedsCompositing {
get { return this.child != null; }
}
public override void paint(PaintingContext context, Offset offset) {
if (this.child != null) {
D.assert(this.needsCompositing);
context.pushLayer(new BackdropFilterLayer(this.filter), base.paint, offset);
}
}
}
public abstract class CustomClipper<T> {
public CustomClipper(Listenable reclip = null) {

8
Runtime/ui/compositing.cs


return layer;
}
public Layer pushBackdropFilter(ImageFilter filter) {
var layer = new BackdropFilterLayer();
layer.filter = filter;
this._pushLayer(layer);
return layer;
}
public void addRetained(Layer layer) {
if (this._currentLayer == null) {
return;

201
Runtime/ui/painting/canvas_impl.cs


layerPaint = paint,
};
parentLayer.layers.Add(layer);
parentLayer.addLayer(layer);
if (paint.backdrop != null) {
if (paint.backdrop is _BlurImageFilter) {
var filter = (_BlurImageFilter) paint.backdrop;
if (!(filter.sigmaX == 0 && filter.sigmaY == 0)) {
var points = new[] {bounds.topLeft, bounds.bottomLeft, bounds.bottomRight, bounds.topRight};
state.matrix.mapPoints(points);
var parentBounds = parentLayer.layerBounds;
for (int i = 0; i < 4; i++) {
points[i] = new Offset(
(points[i].dx - parentBounds.left) / parentBounds.width,
(points[i].dy - parentBounds.top) / parentBounds.height
);
}
var mesh = ImageMeshGenerator.imageMesh(
null,
points[0], points[1], points[2], points[3],
bounds);
var renderDraw = CanvasShader.texRT(layer, layer.layerPaint, mesh, parentLayer);
layer.draws.Add(renderDraw);
var blurLayer = this._createBlurLayer(layer, filter.sigmaX, filter.sigmaY, layer);
var blurMesh = ImageMeshGenerator.imageMesh(null, Rect.one, bounds);
layer.draws.Add(CanvasShader.texRT(layer, paint, blurMesh, blurLayer));
}
} else if (paint.backdrop is _MatrixImageFilter) {
var filter = (_MatrixImageFilter) paint.backdrop;
if (!filter.transform.isIdentity()) {
layer.filterMode = filter.filterMode;
var points = new[] {bounds.topLeft, bounds.bottomLeft, bounds.bottomRight, bounds.topRight};
state.matrix.mapPoints(points);
var parentBounds = parentLayer.layerBounds;
for (int i = 0; i < 4; i++) {
points[i] = new Offset(
(points[i].dx - parentBounds.left) / parentBounds.width,
(points[i].dy - parentBounds.top) / parentBounds.height
);
}
var matrix = Matrix3.makeTrans(-bounds.left, -bounds.top);
matrix.postConcat(filter.transform);
matrix.postTranslate(bounds.left, bounds.top);
var mesh = ImageMeshGenerator.imageMesh(
matrix,
points[0], points[1], points[2], points[3],
bounds);
var renderDraw = CanvasShader.texRT(layer, layer.layerPaint, mesh, parentLayer);
layer.draws.Add(renderDraw);
}
}
}
}
void _restore() {

return;
}
layer.draws.Add(new RenderScissor {
layer.draws.Add(new CmdScissor {
deviceScissor = scissor,
});
layer.lastScissor = scissor;

filterMode = FilterMode.Bilinear,
};
parentLayer.layers.Add(maskLayer);
parentLayer.addLayer(maskLayer);
this._layers.Add(maskLayer);
this._currentLayer = maskLayer;

return maskLayer;
}
RenderLayer _createBlurLayer(RenderLayer maskLayer, float sigma, RenderLayer parentLayer) {
sigma = BlurUtils.adjustSigma(sigma, out var scaleFactor, out var radius);
RenderLayer _createBlurLayer(RenderLayer maskLayer, float sigmaX, float sigmaY, RenderLayer parentLayer) {
sigmaX = BlurUtils.adjustSigma(sigmaX, out var scaleFactorX, out var radiusX);
sigmaY = BlurUtils.adjustSigma(sigmaY, out var scaleFactorY, out var radiusY);
var textureWidth = Mathf.CeilToInt((float) maskLayer.width / scaleFactor);
var textureWidth = Mathf.CeilToInt((float) maskLayer.width / scaleFactorX);
var textureHeight = Mathf.CeilToInt((float) maskLayer.height / scaleFactor);
var textureHeight = Mathf.CeilToInt((float) maskLayer.height / scaleFactorY);
if (textureHeight < 1) {
textureHeight = 1;
}

filterMode = FilterMode.Bilinear,
};
parentLayer.layers.Add(blurXLayer);
parentLayer.addLayer(blurXLayer);
var blurYLayer = new RenderLayer {
rtID = Shader.PropertyToID("_rtID_" + this._layers.Count + "_" + parentLayer.layers.Count),

filterMode = FilterMode.Bilinear,
};
parentLayer.layers.Add(blurYLayer);
parentLayer.addLayer(blurYLayer);
var kernel = BlurUtils.get1DGaussianKernel(sigma, radius);
var kernelX = BlurUtils.get1DGaussianKernel(sigmaX, radiusX);
var kernelY = BlurUtils.get1DGaussianKernel(sigmaY, radiusY);
radius, new Vector2(1f / textureWidth, 0), kernel));
radiusX, new Vector2(1f / textureWidth, 0), kernelX));
radius, new Vector2(0, -1f / textureHeight), kernel));
radiusY, new Vector2(0, -1f / textureHeight), kernelY));
return blurYLayer;
}

var maskLayer = this._createMaskLayer(layer, maskBounds, drawAction, paint);
var blurLayer = this._createBlurLayer(maskLayer, sigma, layer);
var blurLayer = this._createBlurLayer(maskLayer, sigma, sigma, layer);
var blurMesh = ImageMeshGenerator.imageMesh(null, Rect.one, maskBounds);
if (!this._applyClip(blurMesh.bounds)) {

}
void _drawLayer(RenderLayer layer, CommandBuffer cmdBuf) {
foreach (var subLayer in layer.layers) {
var desc = new RenderTextureDescriptor(
subLayer.width, subLayer.height,
RenderTextureFormat.Default, 24) {
useMipMap = false,
autoGenerateMips = false,
};
if (layer.rtID == 0) {
cmdBuf.SetRenderTarget(this._renderTexture,
RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store);
cmdBuf.ClearRenderTarget(true, true, UnityEngine.Color.clear);
}
else {
cmdBuf.SetRenderTarget(layer.rtID,
RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store);
cmdBuf.ClearRenderTarget(true, true, UnityEngine.Color.clear);
}
foreach (var cmdObj in layer.draws) {
switch (cmdObj) {
case CmdLayer cmd:
var subLayer = cmd.layer;
var desc = new RenderTextureDescriptor(
subLayer.width, subLayer.height,
RenderTextureFormat.Default, 24) {
useMipMap = false,
autoGenerateMips = false,
};
if (QualitySettings.antiAliasing != 0) {
desc.msaaSamples = QualitySettings.antiAliasing;
}
if (QualitySettings.antiAliasing != 0) {
desc.msaaSamples = QualitySettings.antiAliasing;
}
cmdBuf.GetTemporaryRT(subLayer.rtID, desc, subLayer.filterMode);
this._drawLayer(subLayer, cmdBuf);
}
if (layer.rtID == 0) {
cmdBuf.SetRenderTarget(this._renderTexture,
RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store);
cmdBuf.ClearRenderTarget(true, true, UnityEngine.Color.clear);
}
else {
cmdBuf.SetRenderTarget(layer.rtID,
RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store);
cmdBuf.ClearRenderTarget(true, true, UnityEngine.Color.clear);
}
cmdBuf.GetTemporaryRT(subLayer.rtID, desc, subLayer.filterMode);
this._drawLayer(subLayer, cmdBuf);
if (layer.rtID == 0) {
cmdBuf.SetRenderTarget(this._renderTexture,
RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store);
}
else {
cmdBuf.SetRenderTarget(layer.rtID,
RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store);
}
foreach (var cmdObj in layer.draws) {
switch (cmdObj) {
case RenderDraw cmd:
break;
case CmdDraw cmd:
cmdBuf.SetGlobalTexture(RenderDraw.texId, cmd.layer.rtID);
if (cmd.layer.rtID == 0) {
cmdBuf.SetGlobalTexture(CmdDraw.texId, this._renderTexture);
} else {
cmdBuf.SetGlobalTexture(CmdDraw.texId, cmd.layer.rtID);
}
}
D.assert(cmd.meshObj == null);

if (mesh == null) {
continue;
}
D.assert(mesh.vertices.Count > 0);
cmd.meshObj.SetVertices(mesh.vertices);

if (mesh.matrix == null) {
cmd.properties.SetFloatArray(RenderDraw.matId, RenderDraw.idMat3.fMat);
cmd.properties.SetFloatArray(CmdDraw.matId, CmdDraw.idMat3.fMat);
cmd.properties.SetFloatArray(RenderDraw.matId, mesh.matrix.fMat);
cmd.properties.SetFloatArray(CmdDraw.matId, mesh.matrix.fMat);
cmdBuf.DrawMesh(cmd.meshObj, RenderDraw.idMat, cmd.material, 0, cmd.pass, cmd.properties);
cmdBuf.DrawMesh(cmd.meshObj, CmdDraw.idMat, cmd.material, 0, cmd.pass, cmd.properties);
cmdBuf.SetGlobalTexture(RenderDraw.texId, BuiltinRenderTextureType.None);
cmdBuf.SetGlobalTexture(CmdDraw.texId, BuiltinRenderTextureType.None);
case RenderScissor cmd:
case CmdScissor cmd:
if (cmd.deviceScissor == null) {
cmdBuf.DisableScissorRect();
} else {

void _clearLayer(RenderLayer layer) {
foreach (var cmdObj in layer.draws) {
switch (cmdObj) {
case RenderDraw cmd:
case CmdDraw cmd:
if (cmd.meshObjCreated) {
this._meshPool.returnMesh(cmd.meshObj);
cmd.meshObj = null;

public uint lastClipGenId;
public Rect lastClipBounds;
public Rect lastScissor;
public bool ignoreClip;
public bool ignoreClip = true;
Vector4? _viewport;

this.currentState = new State();
this.states.Add(this.currentState);
}
public void addLayer(RenderLayer layer) {
this.layers.Add(layer);
this.draws.Add(new CmdLayer {layer = layer});
}
}
internal class State {

}
}
internal class RenderDraw {
internal class CmdLayer {
public RenderLayer layer;
}
internal class CmdDraw {
public MeshMesh mesh;
public TextBlobMesh textMesh;
public int pass;

public static readonly int matId = Shader.PropertyToID("_mat");
}
internal class RenderScissor {
internal class CmdScissor {
public Rect deviceScissor;
}
}

10, 11, 14, 11, 15, 14,
};
public static MeshMesh imageMesh(Matrix3 matrix,
Offset srcTL, Offset srcBL, Offset srcBR, Offset srcTR,
Rect dst) {
var vertices = new List<Vector3>(4);
var uv = new List<Vector2>(4);
vertices.Add(new Vector2(dst.left, dst.top));
uv.Add(new Vector2(srcTL.dx, 1.0f - srcTL.dy));
vertices.Add(new Vector2(dst.left, dst.bottom));
uv.Add(new Vector2(srcBL.dx, 1.0f - srcBL.dy));
vertices.Add(new Vector2(dst.right, dst.bottom));
uv.Add(new Vector2(srcBR.dx, 1.0f - srcBR.dy));
vertices.Add(new Vector2(dst.right, dst.top));
uv.Add(new Vector2(srcTR.dx, 1.0f - srcTR.dy));
return new MeshMesh(matrix, vertices, _imageTriangles, uv);
}
public static MeshMesh imageMesh(Matrix3 matrix, Rect src, Rect dst) {
var vertices = new List<Vector3>(4);
var uv = new List<Vector2>(4);

52
Runtime/ui/painting/canvas_shader.cs


}
}
public static PictureFlusher.RenderDraw convexFill(PictureFlusher.RenderLayer layer, Paint paint,
public static PictureFlusher.CmdDraw convexFill(PictureFlusher.RenderLayer layer, Paint paint,
return new PictureFlusher.RenderDraw {
return new PictureFlusher.CmdDraw {
mesh = mesh,
pass = pass,
material = mat,

public static PictureFlusher.RenderDraw fill0(PictureFlusher.RenderLayer layer, MeshMesh mesh) {
public static PictureFlusher.CmdDraw fill0(PictureFlusher.RenderLayer layer, MeshMesh mesh) {
Vector4 viewport = layer.viewport;
var mat = _fill0Mat.getMaterial(layer.ignoreClip);

return new PictureFlusher.RenderDraw {
return new PictureFlusher.CmdDraw {
mesh = mesh,
pass = pass,
material = mat,

public static PictureFlusher.RenderDraw fill1(PictureFlusher.RenderLayer layer, Paint paint,
public static PictureFlusher.CmdDraw fill1(PictureFlusher.RenderLayer layer, Paint paint,
return new PictureFlusher.RenderDraw {
return new PictureFlusher.CmdDraw {
mesh = mesh.boundsMesh,
pass = pass,
material = mat,

public static PictureFlusher.RenderDraw stroke0(PictureFlusher.RenderLayer layer, Paint paint,
public static PictureFlusher.CmdDraw stroke0(PictureFlusher.RenderLayer layer, Paint paint,
return new PictureFlusher.RenderDraw {
return new PictureFlusher.CmdDraw {
mesh = mesh,
pass = pass,
material = mat,

public static PictureFlusher.RenderDraw stroke1(PictureFlusher.RenderLayer layer, MeshMesh mesh) {
public static PictureFlusher.CmdDraw stroke1(PictureFlusher.RenderLayer layer, MeshMesh mesh) {
Vector4 viewport = layer.viewport;
var mat = _stroke1Mat;

return new PictureFlusher.RenderDraw {
return new PictureFlusher.CmdDraw {
mesh = mesh,
pass = pass,
material = mat,

public static PictureFlusher.RenderDraw stencilClear(
public static PictureFlusher.CmdDraw stencilClear(
PictureFlusher.RenderLayer layer, MeshMesh mesh) {
Vector4 viewport = layer.viewport;
var mat = _stencilMat;

props.SetVector("_viewport", viewport);
return new PictureFlusher.RenderDraw {
return new PictureFlusher.CmdDraw {
mesh = mesh,
pass = pass,
material = mat,

public static PictureFlusher.RenderDraw stencil0(PictureFlusher.RenderLayer layer, MeshMesh mesh) {
public static PictureFlusher.CmdDraw stencil0(PictureFlusher.RenderLayer layer, MeshMesh mesh) {
Vector4 viewport = layer.viewport;
var mat = _stencilMat;

return new PictureFlusher.RenderDraw {
return new PictureFlusher.CmdDraw {
mesh = mesh,
pass = pass,
material = mat,

public static PictureFlusher.RenderDraw stencil1(PictureFlusher.RenderLayer layer, MeshMesh mesh) {
public static PictureFlusher.CmdDraw stencil1(PictureFlusher.RenderLayer layer, MeshMesh mesh) {
Vector4 viewport = layer.viewport;
var mat = _stencilMat;

return new PictureFlusher.RenderDraw {
return new PictureFlusher.CmdDraw {
mesh = mesh,
pass = pass,
material = mat,

public static PictureFlusher.RenderDraw tex(PictureFlusher.RenderLayer layer, Paint paint,
public static PictureFlusher.CmdDraw tex(PictureFlusher.RenderLayer layer, Paint paint,
MeshMesh mesh, Image image) {
var mat = _texMat.getMaterial(paint.blendMode, layer.ignoreClip);
_getShaderPassAndProps(layer, paint, mesh, 1.0f, out var pass, out var props);

props.SetInt("_texMode", image.texture is RenderTexture ? 1 : 0); // pre alpha if RT else post alpha
return new PictureFlusher.RenderDraw {
return new PictureFlusher.CmdDraw {
mesh = mesh,
pass = pass,
material = mat,

}
public static PictureFlusher.RenderDraw texRT(PictureFlusher.RenderLayer layer, Paint paint,
public static PictureFlusher.CmdDraw texRT(PictureFlusher.RenderLayer layer, Paint paint,
return new PictureFlusher.RenderDraw {
return new PictureFlusher.CmdDraw {
mesh = mesh,
pass = pass,
material = mat,

}
public static PictureFlusher.RenderDraw texAlpha(PictureFlusher.RenderLayer layer, Paint paint,
public static PictureFlusher.CmdDraw texAlpha(PictureFlusher.RenderLayer layer, Paint paint,
public static PictureFlusher.RenderDraw texAlpha(PictureFlusher.RenderLayer layer, Paint paint,
public static PictureFlusher.CmdDraw texAlpha(PictureFlusher.RenderLayer layer, Paint paint,
public static PictureFlusher.RenderDraw texAlpha(PictureFlusher.RenderLayer layer, Paint paint,
public static PictureFlusher.CmdDraw texAlpha(PictureFlusher.RenderLayer layer, Paint paint,
MeshMesh mesh, TextBlobMesh textMesh, Texture tex) {
var mat = _texMat.getMaterial(paint.blendMode, layer.ignoreClip);

props.SetInt("_texMode", 2); // alpha only
return new PictureFlusher.RenderDraw {
return new PictureFlusher.CmdDraw {
mesh = mesh,
textMesh = textMesh,
pass = pass,

}
public static PictureFlusher.RenderDraw maskFilter(PictureFlusher.RenderLayer layer, MeshMesh mesh,
public static PictureFlusher.CmdDraw maskFilter(PictureFlusher.RenderLayer layer, MeshMesh mesh,
PictureFlusher.RenderLayer renderLayer, float radius, Vector2 imgInc, float[] kernel) {
Vector4 viewport = layer.viewport;
var mat = _filterMat;

props.SetVector("_mf_imgInc", imgInc);
props.SetFloatArray("_mf_kernel", kernel);
return new PictureFlusher.RenderDraw {
return new PictureFlusher.CmdDraw {
mesh = mesh,
pass = pass,
material = mat,

3
Runtime/ui/painting/painting.cs


public MaskFilter maskFilter = null;
public ImageFilter backdrop = null;
public PaintShader shader = null;
public bool invertColors = false;

this.filterMode = paint.filterMode;
this.colorFilter = paint.colorFilter;
this.maskFilter = paint.maskFilter;
this.backdrop = paint.backdrop;
this.shader = paint.shader;
this.invertColors = paint.invertColors;
}

6
Runtime/widgets/app.cs


public readonly Dictionary<string, WidgetBuilder> routes;
public readonly TextStyle textStyle;
public readonly Window window;
public readonly bool showPerformanceoverlay;
public readonly bool showPerformanceOverlay;
public readonly Locale locale;
public readonly List<LocalizationsDelegate> localizationsDelegates;
public readonly LocaleListResolutionCallback localeListResolutionCallback;

this.localeListResolutionCallback = localeListResolutionCallback;
this.localeResolutionCallback = localeResolutionCallback;
this.supportedLocales = supportedLocales;
this.showPerformanceoverlay = showPerformanceOverlay;
this.showPerformanceOverlay = showPerformanceOverlay;
D.assert(
home == null ||

}
PerformanceOverlay performanceOverlay = null;
if (this.widget.showPerformanceoverlay) {
if (this.widget.showPerformanceOverlay) {
performanceOverlay = PerformanceOverlay.allEnabled();
}

21
Runtime/widgets/basic.cs


}
}
public class BackdropFilter : SingleChildRenderObjectWidget {
public BackdropFilter(
Key key = null,
ImageFilter filter = null,
Widget child = null)
: base(key, child) {
D.assert(filter != null);
this.filter = filter;
}
public readonly ImageFilter filter;
public override RenderObject createRenderObject(BuildContext context) {
return new RenderBackdropFilter(filter: this.filter);
}
public override void updateRenderObject(BuildContext context, RenderObject renderObject) {
((RenderBackdropFilter) renderObject).filter = this.filter;
}
}
public class Opacity : SingleChildRenderObjectWidget {
public Opacity(float opacity, Key key = null, Widget child = null) : base(key, child) {
this.opacity = opacity;

12
Runtime/widgets/preferred_size.cs


}
public class PreferredSize : StatelessWidget, SizePreferred {
public class PreferredSize : PreferredSizeWidget {
public PreferredSize(
Key key = null,
Widget child = null,

public readonly Widget child;
public Size preferredSize { get; }
public override Size preferredSize { get; }
public override State createState() {
return new _PreferredSizeState();
}
}
class _PreferredSizeState : State<PreferredSize> {
return this.child;
return this.widget.child;
}
}
}

81
Samples/UIWidgetSample/MaterialSample.cs


namespace UIWidgetsSample {
public class MaterialSample : UIWidgetsSamplePanel {
int testCaseId = 2;
int testCaseId = 3;
new MaterialAppBarWidget()
new MaterialAppBarWidget(),
new MaterialTabBarWidget()
showPerformanceOverlay: true,
showPerformanceOverlay: false,
home: this.testCases[this.testCaseId]);
}

}
}
class MaterialTabBarWidget : StatefulWidget {
public MaterialTabBarWidget(Key key = null) : base(key) {
}
public override State createState() {
return new MaterialTabBarWidgetState();
}
}
class MaterialTabBarWidgetState : SingleTickerProviderStateMixin<MaterialTabBarWidget> {
TabController _tabController;
public override void initState() {
base.initState();
this._tabController = new TabController(vsync: this, length: Choice.choices.Count);
}
public override void dispose() {
this._tabController.dispose();
base.dispose();
}
void _nextPage(int delta) {
int newIndex = this._tabController.index + delta;
if (newIndex < 0 || newIndex >= this._tabController.length) {
return;
}
this._tabController.animateTo(newIndex);
}
public override Widget build(BuildContext context) {
List<Widget> tapChildren = new List<Widget>();
foreach (Choice choice in Choice.choices) {
tapChildren.Add(
new Padding(
padding: EdgeInsets.all(16.0f),
child: new ChoiceCard(choice: choice)));
}
return new Scaffold(
appBar: new AppBar(
title: new Center(
child: new Text("AppBar Bottom Widget")
),
leading: new IconButton(
tooltip: "Previous choice",
icon: new Icon(Unity.UIWidgets.material.Icons.arrow_back),
onPressed: () => { this._nextPage(-1); }
),
actions: new List<Widget> {
new IconButton(
icon: new Icon(Unity.UIWidgets.material.Icons.arrow_forward),
tooltip: "Next choice",
onPressed: () => { this._nextPage(1); })
},
bottom: new PreferredSize(
preferredSize: Size.fromHeight(48.0f),
child: new Theme(
data: Theme.of(context).copyWith(accentColor: Colors.white),
child: new Container(
height: 48.0f,
alignment: Alignment.center,
child: new TabPageSelector(
controller: this._tabController))))
),
body: new TabBarView(
controller: this._tabController,
children: tapChildren
));
}
}

56
Tests/Editor/CanvasAndLayers.cs


void saveLayer() {
var pictureRecorder = new PictureRecorder();
var canvas = new RecorderCanvas(pictureRecorder);
var paint1 = new Paint {
color = new Color(0xFFFFFFFF),
};
var path1 = new Path();
path1.moveTo(0, 0);
path1.lineTo(0, 90);
path1.lineTo(90, 90);
path1.lineTo(90, 0);
path1.close();
canvas.drawPath(path1, paint1);
path.moveTo(10, 10);
path.lineTo(10, 110);
path.lineTo(90, 110);
path.lineTo(110, 10);
path.moveTo(20, 20);
path.lineTo(20, 70);
path.lineTo(70, 70);
path.lineTo(70, 20);
paint = new Paint {
var paint2 = new Paint {
var rect = Unity.UIWidgets.ui.Rect.fromLTWH(10, 150, 100, 100);
var rrect = RRect.fromRectAndCorners(rect, 0, 4, 8, 16);
var rect1 = Unity.UIWidgets.ui.Rect.fromLTWH(18, 152, 88, 92);
var rrect1 = RRect.fromRectAndCorners(rect1, 0, 4, 8, 16);
canvas.drawDRRect(rrect, rrect1, paint);
canvas.rotate(-45 * Mathf.PI / 180.0f, new Offset(150, 150));
var path2 = new Path();
path2.moveTo(30, 30);
path2.lineTo(30, 60);
path2.lineTo(60, 60);
path2.lineTo(60, 30);
path2.close();
// paint = new Paint {
// color = new Color(0xFF00FFFF),
// blurSigma = 3,
// };
// canvas.drawRectShadow(
// Rect.fromLTWH(150, 150, 110, 120),
// paint);
canvas.drawPath(path2, paint2);
Debug.Log("picture.paintBounds: " + picture.paintBounds);
editorCanvas.saveLayer(picture.paintBounds, new Paint {color = new Color(0x7FFFFFFF)});
editorCanvas.saveLayer(
picture.paintBounds, new Paint {
color = new Color(0xFFFFFFFF),
});
editorCanvas.translate(150, 0);
editorCanvas.saveLayer(picture.paintBounds, new Paint {color = new Color(0xFFFFFFFF)});
editorCanvas.drawPicture(picture);
editorCanvas.saveLayer(Unity.UIWidgets.ui.Rect.fromLTWH(45, 45, 90, 90), new Paint {
color = new Color(0xFFFFFFFF),
backdrop = ImageFilter.blur(3f, 3f)
});
editorCanvas.restore();
editorCanvas.flush();

24
Tests/Editor/Widgets.cs


child: new Container(
color: CLColors.background3,
child: new Transform(
transform: Matrix3.makeRotate(Mathf.PI/180 * 5, px, py),
transform: Matrix3.makeRotate(Mathf.PI / 180 * 5, px, py),
child:
new Column(
children: new List<Widget> {

)
)
);
return container;
var stack = new Stack(
children: new List<Widget> {
container,
new Positioned(
top: 50,
right: 50,
child: new BackdropFilter(
filter: ImageFilter.blur(10, 10),
child: new Container(
width: 300, height: 300,
decoration: new BoxDecoration(
color: Colors.transparent
)
)
)
)
}
);
return stack;
}
}

25
Runtime/flow/backdrop_filter_layer.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;
namespace Unity.UIWidgets.flow {
public class BackdropFilterLayer : ContainerLayer {
ImageFilter _filter;
public ImageFilter filter {
set { this._filter = value; }
}
public override void paint(PaintContext context) {
D.assert(this.needsPainting);
var canvas = context.canvas;
canvas.saveLayer(this.paintBounds, new Paint {backdrop = this._filter});
try {
this.paintChildren(context);
} finally {
canvas.restore();
}
}
}
}

11
Runtime/flow/backdrop_filter_layer.cs.meta


fileFormatVersion: 2
guid: 13a0ce179081f4b35b10fac26f568cc8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

107
Runtime/material/tab_bar_theme.cs


using System;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
namespace Unity.UIWidgets.material {
public class TabBarTheme : Diagnosticable, IEquatable<TabBarTheme> {
public TabBarTheme(
Decoration indicator = null,
TabBarIndicatorSize? indicatorSize = null,
Color labelColor = null,
Color unselectedLabelColor = null) {
this.indicator = indicator;
this.indicatorSize = indicatorSize;
this.labelColor = labelColor;
this.unselectedLabelColor = unselectedLabelColor;
}
public readonly Decoration indicator;
public readonly TabBarIndicatorSize? indicatorSize;
public readonly Color labelColor;
public readonly Color unselectedLabelColor;
public TabBarTheme copyWith(
Decoration indicator = null,
TabBarIndicatorSize? indicatorSize = null,
Color labelColor = null,
Color unselectedLabelColor = null
) {
return new TabBarTheme(
indicator: indicator ?? this.indicator,
indicatorSize: indicatorSize ?? this.indicatorSize,
labelColor: labelColor ?? this.labelColor,
unselectedLabelColor: unselectedLabelColor ?? this.unselectedLabelColor);
}
public static TabBarTheme of(BuildContext context) {
return Theme.of(context).tabBarTheme;
}
public static TabBarTheme lerp(TabBarTheme a, TabBarTheme b, float t) {
D.assert(a != null);
D.assert(b != null);
return new TabBarTheme(
indicator: Decoration.lerp(a.indicator, b.indicator, t),
indicatorSize: t < 0.5 ? a.indicatorSize : b.indicatorSize,
labelColor: Color.lerp(a.labelColor, b.labelColor, t),
unselectedLabelColor: Color.lerp(a.unselectedLabelColor, b.unselectedLabelColor, t)
);
}
public override int GetHashCode() {
unchecked {
var hashCode = this.indicator != null ? this.indicator.GetHashCode() : 0;
hashCode = (hashCode * 397) ^ (this.indicatorSize != null ? this.indicatorSize.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this.labelColor != null ? this.labelColor.GetHashCode() : 0);
hashCode = (hashCode * 397) ^
(this.unselectedLabelColor != null ? this.unselectedLabelColor.GetHashCode() : 0);
return hashCode;
}
}
public bool Equals(TabBarTheme other) {
if (ReferenceEquals(null, other)) {
return false;
}
if (ReferenceEquals(this, other)) {
return true;
}
return other.indicator == this.indicator &&
other.indicatorSize == this.indicatorSize &&
other.labelColor == this.labelColor &&
other.unselectedLabelColor == this.unselectedLabelColor;
}
public override bool Equals(object obj) {
if (ReferenceEquals(null, obj)) {
return false;
}
if (ReferenceEquals(this, obj)) {
return true;
}
if (obj.GetType() != this.GetType()) {
return false;
}
return this.Equals((TabBarTheme) obj);
}
public static bool operator ==(TabBarTheme left, TabBarTheme right) {
return Equals(left, right);
}
public static bool operator !=(TabBarTheme left, TabBarTheme right) {
return !Equals(left, right);
}
}
}

11
Runtime/material/tab_bar_theme.cs.meta


fileFormatVersion: 2
guid: e5dde8f06134e4f07a597b48fa14a6eb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

187
Runtime/material/tab_controller.cs


using System;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.scheduler;
using Unity.UIWidgets.widgets;
namespace Unity.UIWidgets.material {
public class TabController : ChangeNotifier {
public TabController(
int initialIndex = 0,
int? length = null,
TickerProvider vsync = null) {
D.assert(length != null && length >= 0);
D.assert(initialIndex >= 0 && (length == 0 || initialIndex < length));
D.assert(vsync != null);
this.length = length.Value;
this._index = initialIndex;
this._previousIndex = initialIndex;
this._animationController = length < 2
? null
: new AnimationController(
value: initialIndex,
upperBound: length.Value - 1,
vsync: vsync);
}
public Animation<float> animation {
get { return this._animationController?.view ?? Animations.kAlwaysCompleteAnimation; }
}
readonly AnimationController _animationController;
public readonly int length;
void _changeIndex(int value, TimeSpan? duration = null, Curve curve = null) {
D.assert(value >= 0 && (value < this.length || this.length == 0));
D.assert(duration == null ? curve == null : true);
D.assert(this._indexIsChangingCount >= 0);
if (value == this._index || this.length < 2) {
return;
}
this._previousIndex = this.index;
this._index = value;
if (duration != null) {
this._indexIsChangingCount++;
this.notifyListeners();
this._animationController.animateTo(
this._index, duration: duration, curve: curve).whenCompleteOrCancel(() => {
this._indexIsChangingCount--;
this.notifyListeners();
});
}
else {
this._indexIsChangingCount++;
this._animationController.setValue(this._index);
this._indexIsChangingCount--;
this.notifyListeners();
}
}
public int index {
get { return this._index; }
set { this._changeIndex(value); }
}
int _index;
public int previousIndex {
get { return this._previousIndex; }
}
int _previousIndex;
public bool indexIsChanging {
get { return this._indexIsChangingCount != 0; }
}
int _indexIsChangingCount = 0;
public void animateTo(int value, TimeSpan? duration = null, Curve curve = null) {
duration = duration ?? Constants.kTabScrollDuration;
curve = curve ?? Curves.ease;
this._changeIndex(value, duration: duration, curve: curve);
}
public float offset {
get { return this.length > 1 ? this._animationController.value - this._index : 0.0f; }
set {
D.assert(this.length > 1);
D.assert(value >= -1.0f && value <= 1.0f);
D.assert(!this.indexIsChanging);
if (value == this.offset) {
return;
}
this._animationController.setValue(value + this._index);
}
}
public override void dispose() {
this._animationController?.dispose();
base.dispose();
}
}
class _TabControllerScope : InheritedWidget {
public _TabControllerScope(
Key key = null,
TabController controller = null,
bool? enabled = null,
Widget child = null
) : base(key: key, child: child) {
this.controller = controller;
this.enabled = enabled;
}
public readonly TabController controller;
public readonly bool? enabled;
public override bool updateShouldNotify(InheritedWidget old) {
_TabControllerScope _old = (_TabControllerScope) old;
return this.enabled != _old.enabled
|| this.controller != _old.controller;
}
}
class DefaultTabController : StatefulWidget {
public DefaultTabController(
Key key = null,
int? length = null,
int initialIndex = 0,
Widget child = null
) : base(key: key) {
D.assert(length != null);
D.assert(child != null);
this.length = length;
this.initialIndex = initialIndex;
this.child = child;
}
public readonly int? length;
public readonly int initialIndex;
public readonly Widget child;
public static TabController of(BuildContext context) {
_TabControllerScope scope =
(_TabControllerScope) context.inheritFromWidgetOfExactType(typeof(_TabControllerScope));
return scope?.controller;
}
public override State createState() {
return new _DefaultTabControllerState();
}
}
class _DefaultTabControllerState : SingleTickerProviderStateMixin<DefaultTabController> {
TabController _controller;
public override void initState() {
base.initState();
this._controller = new TabController(
vsync: this,
length: this.widget.length,
initialIndex: this.widget.initialIndex
);
}
public override void dispose() {
this._controller.dispose();
base.dispose();
}
public override Widget build(BuildContext context) {
return new _TabControllerScope(
controller: this._controller,
enabled: TickerMode.of(context),
child: this.widget.child
);
}
}
}

11
Runtime/material/tab_controller.cs.meta


fileFormatVersion: 2
guid: f6cf1d3578f4a4effa3b0988822e3b2e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

90
Runtime/material/tab_indicator.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;
namespace Unity.UIWidgets.material {
public class UnderlineTabIndicator : Decoration {
public UnderlineTabIndicator(
BorderSide borderSide = null,
EdgeInsets insets = null) {
borderSide = borderSide ?? new BorderSide(width: 2.0f, color: Colors.white);
insets = insets ?? EdgeInsets.zero;
this.borderSide = borderSide;
this.insets = insets;
}
public readonly BorderSide borderSide;
public readonly EdgeInsets insets;
public override Decoration lerpFrom(Decoration a, float t) {
if (a is UnderlineTabIndicator) {
UnderlineTabIndicator _a = (UnderlineTabIndicator) a;
return new UnderlineTabIndicator(
borderSide: BorderSide.lerp(_a.borderSide, this.borderSide, t),
insets: EdgeInsets.lerp(_a.insets, this.insets, t)
);
}
return base.lerpFrom(a, t);
}
public override Decoration lerpTo(Decoration b, float t) {
if (b is UnderlineTabIndicator) {
UnderlineTabIndicator _b = (UnderlineTabIndicator) b;
return new UnderlineTabIndicator(
borderSide: BorderSide.lerp(this.borderSide, _b.borderSide, t),
insets: EdgeInsets.lerp(this.insets, _b.insets, t)
);
}
return base.lerpTo(b, t);
}
public override BoxPainter createBoxPainter(VoidCallback onChanged) {
return new _UnderlinePainter(this, onChanged);
}
}
class _UnderlinePainter : BoxPainter {
public _UnderlinePainter(
UnderlineTabIndicator decoration = null,
VoidCallback onChanged = null
) : base(onChanged: onChanged) {
D.assert(decoration != null);
this.decoration = decoration;
}
public readonly UnderlineTabIndicator decoration;
public BorderSide borderSide {
get { return this.decoration.borderSide; }
}
public EdgeInsets insets {
get { return this.decoration.insets; }
}
Rect _indicatorRectFor(Rect rect) {
D.assert(rect != null);
Rect indicator = this.insets.deflateRect(rect);
return Rect.fromLTWH(
indicator.left,
indicator.bottom - this.borderSide.width,
indicator.width,
this.borderSide.width);
}
public override void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) {
D.assert(configuration != null);
D.assert(configuration.size != null);
Rect rect = offset & configuration.size;
Rect indicator = this._indicatorRectFor(rect).deflate(this.borderSide.width / 2.0f);
Paint paint = this.borderSide.toPaint();
paint.strokeCap = StrokeCap.square;
canvas.drawLine(indicator.bottomLeft, indicator.bottomRight, paint);
}
}
}

11
Runtime/material/tab_indicator.cs.meta


fileFormatVersion: 2
guid: 07582ba5529ac435f98f69a5eea30831
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

1001
Runtime/material/tabs.cs
文件差异内容过多而无法显示
查看文件

11
Runtime/material/tabs.cs.meta


fileFormatVersion: 2
guid: 27058ed141c4f4476a7db65aacfda644
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

11
Runtime/widgets/preferred_size.cs.meta


fileFormatVersion: 2
guid: 47c0eb9f305f0431a9a06da1a3f19875
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

11
Runtime/widgets/perferred_size.cs.meta


fileFormatVersion: 2
guid: 60513bb9173ce47ad8d4c7840bcfe836
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

/Runtime/widgets/perferred_size.cs → /Runtime/widgets/preferred_size.cs

正在加载...
取消
保存