mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Flesh out Rect/Point/Size classes in dart:sky
R=mpcomplete@chromium.org Review URL: https://codereview.chromium.org/1152213003
This commit is contained in:
parent
f0c5ab0b82
commit
ae7e807f61
@ -1138,8 +1138,9 @@ core_idl_files = get_path_info([
|
||||
"abspath")
|
||||
|
||||
core_dart_files = get_path_info([
|
||||
"painting/Rect.dart",
|
||||
"painting/Point.dart",
|
||||
"painting/Rect.dart",
|
||||
"painting/Size.dart",
|
||||
],
|
||||
"abspath")
|
||||
|
||||
|
||||
@ -10,4 +10,3 @@ class Point {
|
||||
|
||||
Point(this.x, this.y);
|
||||
}
|
||||
|
||||
|
||||
@ -11,7 +11,38 @@ class Rect {
|
||||
double get right => _value[2];
|
||||
double get bottom => _value[3];
|
||||
|
||||
Rect() : new Float32List(4);
|
||||
|
||||
Rect.fromPointAndSize(Point point, Size size) {
|
||||
_value = new Float32List(4)
|
||||
..[0] = point.x
|
||||
..[1] = point.y
|
||||
..[2] = point.x + size.width
|
||||
..[3] = point.y + size.height;
|
||||
}
|
||||
|
||||
Rect.fromLTRB(double left, double top, double right, double bottom) {
|
||||
_value = new Float32List(4)
|
||||
..[0] = left
|
||||
..[1] = top
|
||||
..[2] = right
|
||||
..[3] = bottom;
|
||||
}
|
||||
|
||||
Point get upperLeft => new Point(left, top);
|
||||
Point get lowerRight => new Point(right, bottom);
|
||||
|
||||
Size get size => new Size(right - left, bottom - top);
|
||||
|
||||
// Rects are inclusive of the top and left edges but exclusive of the bottom
|
||||
// right edges.
|
||||
bool contains(Point point) => point.x >= left && point.x < right
|
||||
&& point.y >= top && point.y < bottom;
|
||||
|
||||
void setLTRB(double left, double top, double right, double bottom) {
|
||||
_value = new Float32List.fromList([left, top, right, bottom]);
|
||||
_value[0] = left
|
||||
..[1] = top
|
||||
..[2] = right
|
||||
..[3] = bottom;
|
||||
}
|
||||
}
|
||||
|
||||
12
engine/core/painting/Size.dart
Normal file
12
engine/core/painting/Size.dart
Normal file
@ -0,0 +1,12 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of dart.sky;
|
||||
|
||||
class Size {
|
||||
double width;
|
||||
double height;
|
||||
|
||||
Point(this.width, this.height);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user