Commit fd68741f authored by Adam Barth's avatar Adam Barth

Add operator+ and operator- to EdgeDims

... and use them to improve the horizontal_scrolling example.
parent 870376da
......@@ -6,10 +6,14 @@ import 'package:sky/painting/box_painter.dart';
import 'package:sky/widgets.dart';
class Circle extends Component {
Circle({ this.margin: EdgeDims.zero });
final EdgeDims margin;
Widget build() {
return new Container(
width: 50.0,
margin: new EdgeDims.symmetric(horizontal: 2.0),
margin: margin + new EdgeDims.symmetric(horizontal: 2.0),
decoration: new BoxDecoration(
shape: Shape.circle,
backgroundColor: const Color(0xFF00FF00)
......@@ -18,18 +22,10 @@ class Circle extends Component {
}
}
class Pad extends Component {
Widget build() {
return new SizedBox(width: 10.0);
}
}
class HorizontalScrollingApp extends App {
Widget build() {
List<Widget> circles = [
new Pad(),
new Circle(),
new Circle(),
new Circle(margin: new EdgeDims.only(left: 10.0)),
new Circle(),
new Circle(),
new Circle(),
......@@ -40,7 +36,7 @@ class HorizontalScrollingApp extends App {
new Circle(),
new Circle(),
new Circle(),
new Pad(),
new Circle(margin: new EdgeDims.only(right: 10.0)),
];
return new Center(
......
......@@ -52,6 +52,22 @@ class EdgeDims {
&& 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;
......
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