|
|
|
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Text; |
|
|
|
using Unity.UIWidgets.foundation; |
|
|
|
using Unity.UIWidgets.gestures; |
|
|
|
|
|
|
InformationCollector informationCollector = null |
|
|
|
) { |
|
|
|
D.assert(() => { |
|
|
|
bool hasErrors = false; |
|
|
|
StringBuilder errorMessage = new StringBuilder("\n"); |
|
|
|
|
|
|
|
var information = new StringBuilder(); |
|
|
|
if (informationCollector != null) { |
|
|
|
informationCollector(information); |
|
|
|
} |
|
|
|
|
|
|
|
throw new UIWidgetsError( |
|
|
|
$"{GetType()} is not valid: {message}\n{information}The offending constraints were: \n {this}"); |
|
|
|
hasErrors = true; |
|
|
|
errorMessage.AppendLine($" {message}"); |
|
|
|
}); |
|
|
|
|
|
|
|
verify(scrollOffset >= 0.0f, "The \"scrollOffset\" is negative."); |
|
|
|
|
|
|
verify(remainingCacheExtent >= 0.0f, "The \"remainingCacheExtent\" is negative."); |
|
|
|
verify(cacheOrigin <= 0.0f, "The \"cacheOrigin\" is positive."); |
|
|
|
verify(isNormalized, "The constraints are not normalized."); |
|
|
|
|
|
|
|
if (hasErrors) { |
|
|
|
List<DiagnosticsNode> diagnosticInfo = new List<DiagnosticsNode>(); |
|
|
|
diagnosticInfo.Add(new ErrorSummary($"{GetType()} is not valid: {errorMessage}")); |
|
|
|
if (informationCollector != null) { |
|
|
|
diagnosticInfo.AddRange(informationCollector.Invoke()); |
|
|
|
} |
|
|
|
diagnosticInfo.Add(new DiagnosticsProperty<SliverConstraints>("The offending constraints were", this, style: DiagnosticsTreeStyle.errorProperty)); |
|
|
|
|
|
|
|
throw new UIWidgetsError( |
|
|
|
diagnosticInfo); |
|
|
|
} |
|
|
|
return true; |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
public readonly float cacheExtent; |
|
|
|
public const float precisionErrorTolerance = 1e-10f; |
|
|
|
|
|
|
|
internal static string _debugCompareFloats(string labelA, float valueA, string labelB, float valueB) { |
|
|
|
internal static List<DiagnosticsNode> _debugCompareFloats(string labelA, float valueA, string labelB, float valueB) { |
|
|
|
List<DiagnosticsNode> diagnosticInfo = new List<DiagnosticsNode>(); |
|
|
|
return $"The {labelA} is {valueA:F1}, but the {labelB} is {valueB:F1}. "; |
|
|
|
diagnosticInfo.Add(new ErrorDescription($"The {labelA} is {valueA:F1}, but the {labelB} is {valueB:F1}. ")); |
|
|
|
} |
|
|
|
else { |
|
|
|
diagnosticInfo.Add(new ErrorDescription($"The {labelA} is {valueA}, but the {labelB} is {valueB}.")); |
|
|
|
diagnosticInfo.Add(new ErrorHint("Maybe you have fallen prey to floating point rounding errors, and should explicitly " + |
|
|
|
$"apply the min() or max() functions, or the clamp() method, to the {labelB}? ")); |
|
|
|
return string.Format( |
|
|
|
"The {0} is {1}, but the {2} is {3}. " + |
|
|
|
"Maybe you have fallen prey to floating point rounding errors, and should explicitly " + |
|
|
|
"apply the min() or max() functions, or the clamp() method, to the {2}? ", |
|
|
|
labelA, valueA, labelB, valueB); |
|
|
|
return diagnosticInfo; |
|
|
|
var verify = new Action<bool, string>((bool check, string message) => { |
|
|
|
void verify(bool check, string summary, List<DiagnosticsNode> details = null) { |
|
|
|
|
|
|
|
List<DiagnosticsNode> diagnosticInfo = new List<DiagnosticsNode>(); |
|
|
|
diagnosticInfo.Add(new ErrorSummary($"{GetType()} is not valid: {summary}")); |
|
|
|
if (details != null) { |
|
|
|
diagnosticInfo.AddRange(details); |
|
|
|
} |
|
|
|
var information = new StringBuilder(); |
|
|
|
informationCollector(information); |
|
|
|
diagnosticInfo.AddRange(informationCollector.Invoke()); |
|
|
|
throw new UIWidgetsError($"{GetType()} is not valid: {message}\n{information}"); |
|
|
|
}); |
|
|
|
throw new UIWidgetsError(diagnosticInfo); |
|
|
|
}; |
|
|
|
|
|
|
|
verify(scrollExtent >= 0.0f, "The \"scrollExtent\" is negative."); |
|
|
|
verify(paintExtent >= 0.0f, "The \"paintExtent\" is negative."); |
|
|
|
|
|
|
verify(false, |
|
|
|
"The \"layoutExtent\" exceeds the \"paintExtent\".\n" + |
|
|
|
_debugCompareFloats("paintExtent", paintExtent, "layoutExtent", |
|
|
|
"The \"layoutExtent\" exceeds the \"paintExtent\".", |
|
|
|
details: _debugCompareFloats("paintExtent", paintExtent, "layoutExtent", |
|
|
|
var details = _debugCompareFloats("maxPaintExtent", maxPaintExtent, "paintExtent", |
|
|
|
paintExtent); |
|
|
|
details.Add(new ErrorDescription("By definition, a sliver can\"t paint more than the maximum that it can paint!")); |
|
|
|
"The \"maxPaintExtent\" is less than the \"paintExtent\".\n" + |
|
|
|
_debugCompareFloats("maxPaintExtent", maxPaintExtent, "paintExtent", |
|
|
|
paintExtent) + |
|
|
|
"By definition, a sliver can\"t paint more than the maximum that it can paint!" |
|
|
|
"The \"maxPaintExtent\" is less than the \"paintExtent\".", |
|
|
|
details: details |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
protected override void debugAssertDoesMeetConstraints() { |
|
|
|
D.assert(geometry.debugAssertIsValid( |
|
|
|
informationCollector: (information) => { |
|
|
|
information.AppendLine("The RenderSliver that returned the offending geometry was:"); |
|
|
|
information.AppendLine(" " + toStringShallow(joiner: "\n ")); |
|
|
|
})); |
|
|
|
D.assert( |
|
|
|
() => { |
|
|
|
IEnumerable<DiagnosticsNode> infoCollector() { |
|
|
|
yield return describeForError("The RenderSliver that returned the offending geometry was"); |
|
|
|
} |
|
|
|
|
|
|
|
return geometry.debugAssertIsValid( |
|
|
|
informationCollector: infoCollector); |
|
|
|
}); |
|
|
|
List<DiagnosticsNode> diagnosticInfo = new List<DiagnosticsNode>(); |
|
|
|
diagnosticInfo.Add(new ErrorSummary("SliverGeometry has a paintOffset that exceeds the remainingPaintExtent from the constraints.")); |
|
|
|
diagnosticInfo.Add(describeForError("The render object whose geometry violates the constraints is the following:")); |
|
|
|
diagnosticInfo.AddRange(SliverGeometry._debugCompareFloats("remainingPaintExtent", constraints.remainingPaintExtent, |
|
|
|
"paintExtent", geometry.paintExtent)); |
|
|
|
diagnosticInfo.Add(new ErrorDescription("The paintExtent must cause the child sliver to paint within the viewport, and so " + |
|
|
|
"cannot exceed the remainingPaintExtent.")); |
|
|
|
|
|
|
|
"SliverGeometry has a paintOffset that exceeds the remainingPaintExtent from the constraints.\n" + |
|
|
|
"The render object whose geometry violates the constraints is the following:\n" + |
|
|
|
" " + toStringShallow(joiner: "\n ") + "\n" + |
|
|
|
SliverGeometry._debugCompareFloats( |
|
|
|
"remainingPaintExtent", constraints.remainingPaintExtent, |
|
|
|
"paintExtent", geometry.paintExtent) + |
|
|
|
"The paintExtent must cause the child sliver to paint within the viewport, and so " + |
|
|
|
"cannot exceed the remainingPaintExtent." |
|
|
|
diagnosticInfo |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|