mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Add operator+ and operator- to EdgeDims
... and use them to improve the horizontal_scrolling example.
This commit is contained in:
parent
870376dab1
commit
fd68741fb3
@ -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,16 +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(margin: new EdgeDims.only(left: 10.0)),
|
||||
new Circle(),
|
||||
new Circle(),
|
||||
new Circle(),
|
||||
@ -38,9 +36,7 @@ class HorizontalScrollingApp extends App {
|
||||
new Circle(),
|
||||
new Circle(),
|
||||
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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user