forked from firka/flutter
Cleanup axis-aligned padding (#4845)
We now have an EdgeInsets.along function that projects the padding onto the given Axis rather than repeating this function in several places.
This commit is contained in:
@@ -6,6 +6,15 @@ import 'dart:ui' as ui show lerpDouble, WindowPadding;
|
||||
|
||||
import 'basic_types.dart';
|
||||
|
||||
/// The two cardinal directions in two dimensions.
|
||||
enum Axis {
|
||||
/// Left and right
|
||||
horizontal,
|
||||
|
||||
/// Up and down
|
||||
vertical,
|
||||
}
|
||||
|
||||
/// An immutable set of offsets in each of the four cardinal directions.
|
||||
///
|
||||
/// Typically used for an offset from each of the four sides of a box. For
|
||||
@@ -56,6 +65,18 @@ class EdgeInsets {
|
||||
/// The total offset in the horizontal direction.
|
||||
double get vertical => top + bottom;
|
||||
|
||||
/// The total offset in the given direction.
|
||||
double along(Axis axis) {
|
||||
assert(axis != null);
|
||||
switch (axis) {
|
||||
case Axis.horizontal:
|
||||
return horizontal;
|
||||
case Axis.vertical:
|
||||
return vertical;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// The size that this EdgeInsets would occupy with an empty interior.
|
||||
Size get collapsedSize => new Size(horizontal, vertical);
|
||||
|
||||
|
||||
@@ -19,15 +19,6 @@ class _DebugSize extends Size {
|
||||
final bool _canBeUsedByParent;
|
||||
}
|
||||
|
||||
/// The two cardinal directions in two dimensions.
|
||||
enum Axis {
|
||||
/// Left and right
|
||||
horizontal,
|
||||
|
||||
/// Up and down
|
||||
vertical,
|
||||
}
|
||||
|
||||
/// Immutable layout constraints for box layout.
|
||||
///
|
||||
/// A size respects a BoxConstraints if, and only if, all of the following
|
||||
@@ -130,10 +121,10 @@ class BoxConstraints extends Constraints {
|
||||
BoxConstraints deflate(EdgeInsets edges) {
|
||||
assert(edges != null);
|
||||
assert(debugAssertIsValid());
|
||||
double horizontal = edges.left + edges.right;
|
||||
double vertical = edges.top + edges.bottom;
|
||||
double deflatedMinWidth = math.max(0.0, minWidth - horizontal);
|
||||
double deflatedMinHeight = math.max(0.0, minHeight - vertical);
|
||||
final double horizontal = edges.horizontal;
|
||||
final double vertical = edges.vertical;
|
||||
final double deflatedMinWidth = math.max(0.0, minWidth - horizontal);
|
||||
final double deflatedMinHeight = math.max(0.0, minHeight - vertical);
|
||||
return new BoxConstraints(
|
||||
minWidth: deflatedMinWidth,
|
||||
maxWidth: math.max(deflatedMinWidth, maxWidth - horizontal),
|
||||
@@ -1144,7 +1135,7 @@ abstract class RenderBox extends RenderObject {
|
||||
/// The caller is responsible for transforming [position] into the local
|
||||
/// coordinate space of the callee. The callee is responsible for checking
|
||||
/// whether the given position is within its bounds.
|
||||
bool hitTest(HitTestResult result, { Point position }) {
|
||||
bool hitTest(HitTestResult result, { @required Point position }) {
|
||||
assert(() {
|
||||
if (needsLayout) {
|
||||
throw new FlutterError(
|
||||
|
||||
@@ -75,17 +75,6 @@ class RenderList extends RenderVirtualViewport<ListParentData> {
|
||||
child.parentData = new ListParentData();
|
||||
}
|
||||
|
||||
double get _scrollAxisPadding {
|
||||
switch (mainAxis) {
|
||||
case Axis.vertical:
|
||||
return padding.vertical;
|
||||
case Axis.horizontal:
|
||||
return padding.horizontal;
|
||||
}
|
||||
assert(mainAxis != null);
|
||||
return null;
|
||||
}
|
||||
|
||||
double get _preferredExtent {
|
||||
if (itemExtent == null)
|
||||
return double.INFINITY;
|
||||
@@ -94,7 +83,7 @@ class RenderList extends RenderVirtualViewport<ListParentData> {
|
||||
return double.INFINITY;
|
||||
double extent = itemExtent * count;
|
||||
if (padding != null)
|
||||
extent += _scrollAxisPadding;
|
||||
extent += padding.along(mainAxis);
|
||||
return extent;
|
||||
}
|
||||
|
||||
|
||||
@@ -274,7 +274,7 @@ class RenderViewport extends RenderViewportBase with RenderObjectWithChildMixin<
|
||||
|
||||
@override
|
||||
void performLayout() {
|
||||
ViewportDimensions oldDimensions = dimensions;
|
||||
final ViewportDimensions oldDimensions = dimensions;
|
||||
if (child != null) {
|
||||
child.layout(_getInnerConstraints(constraints), parentUsesSize: true);
|
||||
size = constraints.constrain(child.size);
|
||||
|
||||
@@ -315,18 +315,7 @@ class LazyBlockViewport extends RenderObjectWidget {
|
||||
/// See [LazyBlockDelegate] for details.
|
||||
final LazyBlockDelegate delegate;
|
||||
|
||||
double get _mainAxisPadding {
|
||||
if (padding == null)
|
||||
return 0.0;
|
||||
switch (mainAxis) {
|
||||
case Axis.horizontal:
|
||||
return padding.horizontal;
|
||||
case Axis.vertical:
|
||||
return padding.vertical;
|
||||
}
|
||||
assert(mainAxis != null);
|
||||
return null;
|
||||
}
|
||||
double get _mainAxisPadding => padding == null ? 0.0 : padding.along(mainAxis);
|
||||
|
||||
@override
|
||||
_LazyBlockElement createElement() => new _LazyBlockElement(this);
|
||||
|
||||
Reference in New Issue
Block a user