Commit 6cc103cf authored by Adam Barth's avatar Adam Barth

Borders on Containers shouldn't overlap the content

This CL inflates the padding of Container to account for the borders so that
the borders are allocated space in the layout and don't draw behind the
Container's child.
parent a16ee23f
...@@ -10,6 +10,61 @@ import 'package:sky/base/image_resource.dart'; ...@@ -10,6 +10,61 @@ import 'package:sky/base/image_resource.dart';
import 'package:sky/base/lerp.dart'; import 'package:sky/base/lerp.dart';
import 'package:sky/painting/shadows.dart'; import 'package:sky/painting/shadows.dart';
class EdgeDims {
// used for e.g. padding
const EdgeDims(this.top, this.right, this.bottom, this.left);
const EdgeDims.all(double value)
: top = value, right = value, bottom = value, left = value;
const EdgeDims.only({ this.top: 0.0,
this.right: 0.0,
this.bottom: 0.0,
this.left: 0.0 });
const EdgeDims.symmetric({ double vertical: 0.0,
double horizontal: 0.0 })
: top = vertical, left = horizontal, bottom = vertical, right = horizontal;
final double top;
final double right;
final double bottom;
final double left;
bool operator ==(other) {
if (identical(this, other))
return true;
return other is EdgeDims
&& top == other.top
&& right == other.right
&& bottom == other.bottom
&& left == other.left;
}
EdgeDims operator+(EdgeDims other) {
return new EdgeDims(top + other.top,
right + other.right,
bottom + other.bottom,
left + other.left);
}
EdgeDims operator-(EdgeDims other) {
return new EdgeDims(top - other.top,
right - other.right,
bottom - other.bottom,
left - other.left);
}
static const EdgeDims zero = const EdgeDims(0.0, 0.0, 0.0, 0.0);
int get hashCode {
int value = 373;
value = 37 * value + top.hashCode;
value = 37 * value + left.hashCode;
value = 37 * value + bottom.hashCode;
value = 37 * value + right.hashCode;
return value;
}
String toString() => "EdgeDims($top, $right, $bottom, $left)";
}
class BorderSide { class BorderSide {
const BorderSide({ const BorderSide({
this.color: const Color(0xFF000000), this.color: const Color(0xFF000000),
...@@ -50,6 +105,10 @@ class Border { ...@@ -50,6 +105,10 @@ class Border {
final BorderSide bottom; final BorderSide bottom;
final BorderSide left; final BorderSide left;
EdgeDims get dimensions {
return new EdgeDims(top.width, right.width, bottom.width, left.width);
}
int get hashCode { int get hashCode {
int value = 373; int value = 373;
value = 37 * value * top.hashCode; value = 37 * value * top.hashCode;
......
...@@ -25,61 +25,6 @@ class _DebugSize extends Size { ...@@ -25,61 +25,6 @@ class _DebugSize extends Size {
final bool _canBeUsedByParent; final bool _canBeUsedByParent;
} }
class EdgeDims {
// used for e.g. padding
const EdgeDims(this.top, this.right, this.bottom, this.left);
const EdgeDims.all(double value)
: top = value, right = value, bottom = value, left = value;
const EdgeDims.only({ this.top: 0.0,
this.right: 0.0,
this.bottom: 0.0,
this.left: 0.0 });
const EdgeDims.symmetric({ double vertical: 0.0,
double horizontal: 0.0 })
: top = vertical, left = horizontal, bottom = vertical, right = horizontal;
final double top;
final double right;
final double bottom;
final double left;
bool operator ==(other) {
if (identical(this, other))
return true;
return other is EdgeDims
&& top == other.top
&& right == other.right
&& bottom == other.bottom
&& left == other.left;
}
EdgeDims operator+(EdgeDims other) {
return new EdgeDims(top + other.top,
right + other.right,
bottom + other.bottom,
left + other.left);
}
EdgeDims operator-(EdgeDims other) {
return new EdgeDims(top - other.top,
right - other.right,
bottom - other.bottom,
left - other.left);
}
static const EdgeDims zero = const EdgeDims(0.0, 0.0, 0.0, 0.0);
int get hashCode {
int value = 373;
value = 37 * value + top.hashCode;
value = 37 * value + left.hashCode;
value = 37 * value + bottom.hashCode;
value = 37 * value + right.hashCode;
return value;
}
String toString() => "EdgeDims($top, $right, $bottom, $left)";
}
class BoxConstraints extends Constraints { class BoxConstraints extends Constraints {
const BoxConstraints({ const BoxConstraints({
this.minWidth: 0.0, this.minWidth: 0.0,
......
...@@ -336,14 +336,24 @@ class Container extends Component { ...@@ -336,14 +336,24 @@ class Container extends Component {
final double width; final double width;
final double height; final double height;
EdgeDims get _paddingIncludingBorder {
if (decoration == null || decoration.border == null)
return padding;
EdgeDims borderPadding = decoration.border.dimensions;
if (padding == null)
return borderPadding;
return padding + borderPadding;
}
Widget build() { Widget build() {
Widget current = child; Widget current = child;
if (child == null && (width == null || height == null)) if (child == null && (width == null || height == null))
current = new ConstrainedBox(constraints: BoxConstraints.expand); current = new ConstrainedBox(constraints: BoxConstraints.expand);
if (padding != null) EdgeDims effectivePadding = _paddingIncludingBorder;
current = new Padding(padding: padding, child: current); if (effectivePadding != null)
current = new Padding(padding: effectivePadding, child: current);
if (decoration != null) if (decoration != null)
current = new DecoratedBox(decoration: decoration, child: current); current = new DecoratedBox(decoration: decoration, child: current);
......
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