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.
This commit is contained in:
parent
a16ee23f0e
commit
6cc103cf07
@ -10,6 +10,61 @@ import 'package:sky/base/image_resource.dart';
|
||||
import 'package:sky/base/lerp.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 {
|
||||
const BorderSide({
|
||||
this.color: const Color(0xFF000000),
|
||||
@ -50,6 +105,10 @@ class Border {
|
||||
final BorderSide bottom;
|
||||
final BorderSide left;
|
||||
|
||||
EdgeDims get dimensions {
|
||||
return new EdgeDims(top.width, right.width, bottom.width, left.width);
|
||||
}
|
||||
|
||||
int get hashCode {
|
||||
int value = 373;
|
||||
value = 37 * value * top.hashCode;
|
||||
|
@ -25,61 +25,6 @@ class _DebugSize extends Size {
|
||||
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 {
|
||||
const BoxConstraints({
|
||||
this.minWidth: 0.0,
|
||||
|
@ -336,14 +336,24 @@ class Container extends Component {
|
||||
final double width;
|
||||
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 current = child;
|
||||
|
||||
if (child == null && (width == null || height == null))
|
||||
current = new ConstrainedBox(constraints: BoxConstraints.expand);
|
||||
|
||||
if (padding != null)
|
||||
current = new Padding(padding: padding, child: current);
|
||||
EdgeDims effectivePadding = _paddingIncludingBorder;
|
||||
if (effectivePadding != null)
|
||||
current = new Padding(padding: effectivePadding, child: current);
|
||||
|
||||
if (decoration != null)
|
||||
current = new DecoratedBox(decoration: decoration, child: current);
|
||||
|
Loading…
x
Reference in New Issue
Block a user