Commit 9e111d18 authored by Adam Barth's avatar Adam Barth Committed by GitHub

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.
parent 0f15263c
...@@ -6,6 +6,15 @@ import 'dart:ui' as ui show lerpDouble, WindowPadding; ...@@ -6,6 +6,15 @@ import 'dart:ui' as ui show lerpDouble, WindowPadding;
import 'basic_types.dart'; 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. /// 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 /// Typically used for an offset from each of the four sides of a box. For
...@@ -56,6 +65,18 @@ class EdgeInsets { ...@@ -56,6 +65,18 @@ class EdgeInsets {
/// The total offset in the horizontal direction. /// The total offset in the horizontal direction.
double get vertical => top + bottom; 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. /// The size that this EdgeInsets would occupy with an empty interior.
Size get collapsedSize => new Size(horizontal, vertical); Size get collapsedSize => new Size(horizontal, vertical);
......
...@@ -19,15 +19,6 @@ class _DebugSize extends Size { ...@@ -19,15 +19,6 @@ class _DebugSize extends Size {
final bool _canBeUsedByParent; 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. /// Immutable layout constraints for box layout.
/// ///
/// A size respects a BoxConstraints if, and only if, all of the following /// A size respects a BoxConstraints if, and only if, all of the following
...@@ -130,10 +121,10 @@ class BoxConstraints extends Constraints { ...@@ -130,10 +121,10 @@ class BoxConstraints extends Constraints {
BoxConstraints deflate(EdgeInsets edges) { BoxConstraints deflate(EdgeInsets edges) {
assert(edges != null); assert(edges != null);
assert(debugAssertIsValid()); assert(debugAssertIsValid());
double horizontal = edges.left + edges.right; final double horizontal = edges.horizontal;
double vertical = edges.top + edges.bottom; final double vertical = edges.vertical;
double deflatedMinWidth = math.max(0.0, minWidth - horizontal); final double deflatedMinWidth = math.max(0.0, minWidth - horizontal);
double deflatedMinHeight = math.max(0.0, minHeight - vertical); final double deflatedMinHeight = math.max(0.0, minHeight - vertical);
return new BoxConstraints( return new BoxConstraints(
minWidth: deflatedMinWidth, minWidth: deflatedMinWidth,
maxWidth: math.max(deflatedMinWidth, maxWidth - horizontal), maxWidth: math.max(deflatedMinWidth, maxWidth - horizontal),
...@@ -1144,7 +1135,7 @@ abstract class RenderBox extends RenderObject { ...@@ -1144,7 +1135,7 @@ abstract class RenderBox extends RenderObject {
/// The caller is responsible for transforming [position] into the local /// The caller is responsible for transforming [position] into the local
/// coordinate space of the callee. The callee is responsible for checking /// coordinate space of the callee. The callee is responsible for checking
/// whether the given position is within its bounds. /// whether the given position is within its bounds.
bool hitTest(HitTestResult result, { Point position }) { bool hitTest(HitTestResult result, { @required Point position }) {
assert(() { assert(() {
if (needsLayout) { if (needsLayout) {
throw new FlutterError( throw new FlutterError(
......
...@@ -75,17 +75,6 @@ class RenderList extends RenderVirtualViewport<ListParentData> { ...@@ -75,17 +75,6 @@ class RenderList extends RenderVirtualViewport<ListParentData> {
child.parentData = new 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 { double get _preferredExtent {
if (itemExtent == null) if (itemExtent == null)
return double.INFINITY; return double.INFINITY;
...@@ -94,7 +83,7 @@ class RenderList extends RenderVirtualViewport<ListParentData> { ...@@ -94,7 +83,7 @@ class RenderList extends RenderVirtualViewport<ListParentData> {
return double.INFINITY; return double.INFINITY;
double extent = itemExtent * count; double extent = itemExtent * count;
if (padding != null) if (padding != null)
extent += _scrollAxisPadding; extent += padding.along(mainAxis);
return extent; return extent;
} }
......
...@@ -274,7 +274,7 @@ class RenderViewport extends RenderViewportBase with RenderObjectWithChildMixin< ...@@ -274,7 +274,7 @@ class RenderViewport extends RenderViewportBase with RenderObjectWithChildMixin<
@override @override
void performLayout() { void performLayout() {
ViewportDimensions oldDimensions = dimensions; final ViewportDimensions oldDimensions = dimensions;
if (child != null) { if (child != null) {
child.layout(_getInnerConstraints(constraints), parentUsesSize: true); child.layout(_getInnerConstraints(constraints), parentUsesSize: true);
size = constraints.constrain(child.size); size = constraints.constrain(child.size);
......
...@@ -315,18 +315,7 @@ class LazyBlockViewport extends RenderObjectWidget { ...@@ -315,18 +315,7 @@ class LazyBlockViewport extends RenderObjectWidget {
/// See [LazyBlockDelegate] for details. /// See [LazyBlockDelegate] for details.
final LazyBlockDelegate delegate; final LazyBlockDelegate delegate;
double get _mainAxisPadding { double get _mainAxisPadding => padding == null ? 0.0 : padding.along(mainAxis);
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;
}
@override @override
_LazyBlockElement createElement() => new _LazyBlockElement(this); _LazyBlockElement createElement() => new _LazyBlockElement(this);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment