Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
982f511c
Commit
982f511c
authored
Oct 20, 2017
by
Ian Hickson
Committed by
GitHub
Oct 20, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make Border more general (#12619)
parent
f2d3b99b
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
471 additions
and
12 deletions
+471
-12
painting.dart
packages/flutter/lib/painting.dart
+1
-0
box_border.dart
packages/flutter/lib/src/painting/box_border.dart
+25
-9
box_decoration.dart
packages/flutter/lib/src/painting/box_decoration.dart
+1
-1
circle_border.dart
packages/flutter/lib/src/painting/circle_border.dart
+1
-1
rounded_rectangle_border.dart
...es/flutter/lib/src/painting/rounded_rectangle_border.dart
+1
-1
shape_decoration.dart
packages/flutter/lib/src/painting/shape_decoration.dart
+391
-0
shape_decoration_test.dart
packages/flutter/test/painting/shape_decoration_test.dart
+51
-0
No files found.
packages/flutter/lib/painting.dart
View file @
982f511c
...
...
@@ -36,6 +36,7 @@ export 'src/painting/gradient.dart';
export
'src/painting/images.dart'
;
export
'src/painting/matrix_utils.dart'
;
export
'src/painting/rounded_rectangle_border.dart'
;
export
'src/painting/shape_decoration.dart'
;
export
'src/painting/text_painter.dart'
;
export
'src/painting/text_span.dart'
;
export
'src/painting/text_style.dart'
;
packages/flutter/lib/src/painting/box_border.dart
View file @
982f511c
...
...
@@ -57,8 +57,26 @@ abstract class BoxBorder extends ShapeBorder {
/// const constructors so that they can be used in const expressions.
const
BoxBorder
();
/// The top side of this border.
///
/// This getter is available on both [Border] and [BorderDirectional]. If
/// [isUniform] is true, then this is the same style as all the other sides.
BorderSide
get
top
;
/// The bottom side of this border.
BorderSide
get
bottom
;
/// Whether all four sides of the border are identical. Uniform borders are
/// typically more efficient to paint.
///
/// A uniform border by definition has no text direction dependency and
/// therefore could be expressed as a [Border], even if it is currently a
/// [BorderDirectional]. A uniform border can also be expressed as a
/// [RoundedRectangleBorder].
bool
get
isUniform
;
// We override this to tighten the return value, so that callers can assume
// that we'll return a
BoxBorder
.
// that we'll return a
[BoxBorder]
.
@override
BoxBorder
add
(
ShapeBorder
other
,
{
bool
reversed:
false
})
=>
null
;
...
...
@@ -315,13 +333,13 @@ class Border extends BoxBorder {
);
}
/// The top side of this border.
@override
final
BorderSide
top
;
/// The right side of this border.
final
BorderSide
right
;
/// The bottom side of this border.
@override
final
BorderSide
bottom
;
/// The left side of this border.
...
...
@@ -332,8 +350,7 @@ class Border extends BoxBorder {
return
new
EdgeInsets
.
fromLTRB
(
left
.
width
,
top
.
width
,
right
.
width
,
bottom
.
width
);
}
/// Whether all four sides of the border are identical. Uniform borders are
/// typically more efficient to paint.
@override
bool
get
isUniform
{
final
Color
topColor
=
top
.
color
;
if
(
right
.
color
!=
topColor
||
...
...
@@ -572,7 +589,7 @@ class BorderDirectional extends BoxBorder {
);
}
/// The top side of this border.
@override
final
BorderSide
top
;
/// The start side of this border.
...
...
@@ -595,7 +612,7 @@ class BorderDirectional extends BoxBorder {
/// * [TextDirection], which is used to describe the reading direction.
final
BorderSide
end
;
/// The bottom side of this border.
@override
final
BorderSide
bottom
;
@override
...
...
@@ -603,8 +620,7 @@ class BorderDirectional extends BoxBorder {
return
new
EdgeInsetsDirectional
.
fromSTEB
(
start
.
width
,
top
.
width
,
end
.
width
,
bottom
.
width
);
}
/// Whether all four sides of the border are identical. Uniform borders are
/// typically more efficient to paint.
@override
bool
get
isUniform
{
final
Color
topColor
=
top
.
color
;
if
(
start
.
color
!=
topColor
||
...
...
packages/flutter/lib/src/painting/box_decoration.dart
View file @
982f511c
...
...
@@ -206,7 +206,7 @@ class BoxDecoration extends Decoration {
/// * [Decoration.lerp], which can interpolate between any two types of
/// [Decoration]s, not just [BoxDecoration]s.
/// * [lerpFrom] and [lerpTo], which are used to implement [Decoration.lerp]
///
and which use [BoxDecoration.lerp] when interpolating two
/// and which use [BoxDecoration.lerp] when interpolating two
/// [BoxDecoration]s or a [BoxDecoration] to or from null.
static
BoxDecoration
lerp
(
BoxDecoration
a
,
BoxDecoration
b
,
double
t
)
{
if
(
a
==
null
&&
b
==
null
)
...
...
packages/flutter/lib/src/painting/circle_border.dart
View file @
982f511c
...
...
@@ -25,7 +25,7 @@ class CircleBorder extends ShapeBorder {
/// Create a circle border.
///
/// The [side] argument must not be null.
const
CircleBorder
(
this
.
side
)
:
assert
(
side
!=
null
);
const
CircleBorder
(
[
this
.
side
=
BorderSide
.
none
]
)
:
assert
(
side
!=
null
);
/// The style of this border.
final
BorderSide
side
;
...
...
packages/flutter/lib/src/painting/rounded_rectangle_border.dart
View file @
982f511c
...
...
@@ -28,7 +28,7 @@ class RoundedRectangleBorder extends ShapeBorder {
/// Creates a rounded rectangle border.
///
/// The arguments must not be null.
RoundedRectangleBorder
({
const
RoundedRectangleBorder
({
this
.
side
:
BorderSide
.
none
,
this
.
borderRadius
:
BorderRadius
.
zero
,
})
:
assert
(
side
!=
null
),
...
...
packages/flutter/lib/src/painting/shape_decoration.dart
0 → 100644
View file @
982f511c
This diff is collapsed.
Click to expand it.
packages/flutter/test/painting/shape_decoration_test.dart
0 → 100644
View file @
982f511c
// Copyright 2017 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.
import
'package:flutter/painting.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
void
main
(
)
{
test
(
'ShapeDecoration constructor'
,
()
{
final
Color
colorR
=
const
Color
(
0xffff0000
);
final
Color
colorG
=
const
Color
(
0xff00ff00
);
final
Gradient
gradient
=
new
LinearGradient
(
colors:
<
Color
>[
colorR
,
colorG
]);
expect
(
const
ShapeDecoration
(
shape:
const
Border
()),
const
ShapeDecoration
(
shape:
const
Border
()));
expect
(()
=>
new
ShapeDecoration
(
color:
colorR
,
gradient:
gradient
,
shape:
const
Border
()),
throwsAssertionError
);
expect
(()
=>
new
ShapeDecoration
(
color:
colorR
,
shape:
null
),
throwsAssertionError
);
expect
(
new
ShapeDecoration
.
fromBoxDecoration
(
const
BoxDecoration
(
shape:
BoxShape
.
circle
)),
const
ShapeDecoration
(
shape:
const
CircleBorder
(
BorderSide
.
none
)),
);
expect
(
new
ShapeDecoration
.
fromBoxDecoration
(
new
BoxDecoration
(
shape:
BoxShape
.
rectangle
,
borderRadius:
new
BorderRadiusDirectional
.
circular
(
100.0
))),
new
ShapeDecoration
(
shape:
new
RoundedRectangleBorder
(
borderRadius:
new
BorderRadiusDirectional
.
circular
(
100.0
))),
);
expect
(
new
ShapeDecoration
.
fromBoxDecoration
(
new
BoxDecoration
(
shape:
BoxShape
.
circle
,
border:
new
Border
.
all
(
color:
colorG
))),
new
ShapeDecoration
(
shape:
new
CircleBorder
(
new
BorderSide
(
color:
colorG
))),
);
expect
(
new
ShapeDecoration
.
fromBoxDecoration
(
new
BoxDecoration
(
shape:
BoxShape
.
rectangle
,
border:
new
Border
.
all
(
color:
colorR
))),
new
ShapeDecoration
(
shape:
new
Border
.
all
(
color:
colorR
)),
);
expect
(
new
ShapeDecoration
.
fromBoxDecoration
(
const
BoxDecoration
(
shape:
BoxShape
.
rectangle
,
border:
const
BorderDirectional
(
start:
const
BorderSide
()))),
const
ShapeDecoration
(
shape:
const
BorderDirectional
(
start:
const
BorderSide
())),
);
});
test
(
'ShapeDecoration.lerp and hit test'
,
()
{
final
Decoration
a
=
const
ShapeDecoration
(
shape:
const
CircleBorder
());
final
Decoration
b
=
const
ShapeDecoration
(
shape:
const
RoundedRectangleBorder
());
expect
(
Decoration
.
lerp
(
a
,
b
,
0.0
),
a
);
expect
(
Decoration
.
lerp
(
a
,
b
,
1.0
),
b
);
const
Size
size
=
const
Size
(
200.0
,
100.0
);
// at t=0.5, width will be 150 (x=25 to x=175).
expect
(
a
.
hitTest
(
size
,
const
Offset
(
20.0
,
50.0
)),
isFalse
);
expect
(
Decoration
.
lerp
(
a
,
b
,
0.1
).
hitTest
(
size
,
const
Offset
(
20.0
,
50.0
)),
isFalse
);
expect
(
Decoration
.
lerp
(
a
,
b
,
0.5
).
hitTest
(
size
,
const
Offset
(
20.0
,
50.0
)),
isFalse
);
expect
(
Decoration
.
lerp
(
a
,
b
,
0.9
).
hitTest
(
size
,
const
Offset
(
20.0
,
50.0
)),
isTrue
);
expect
(
b
.
hitTest
(
size
,
const
Offset
(
20.0
,
50.0
)),
isTrue
);
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment