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
8678edfa
Commit
8678edfa
authored
Mar 24, 2016
by
Ian Hickson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2871 from Hixie/borders
Tweaks to Border to make it easier to subclass.
parents
1949f124
685ccfce
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
24 deletions
+31
-24
box_painter.dart
packages/flutter/lib/src/painting/box_painter.dart
+31
-24
No files found.
packages/flutter/lib/src/painting/box_painter.dart
View file @
8678edfa
...
...
@@ -29,6 +29,7 @@ class BorderSide {
/// A black border side of zero width.
static
const
BorderSide
none
=
const
BorderSide
(
width:
0.0
);
/// Creates a copy of this border but with the given fields replaced with the new values.
BorderSide
copyWith
({
Color
color
,
double
width
...
...
@@ -39,6 +40,7 @@ class BorderSide {
);
}
/// Linearly interpolate between two border sides.
static
BorderSide
lerp
(
BorderSide
a
,
BorderSide
b
,
double
t
)
{
assert
(
a
!=
null
);
assert
(
b
!=
null
);
...
...
@@ -80,7 +82,7 @@ class Border {
Color
color:
const
Color
(
0xFF000000
),
double
width:
1.0
})
{
BorderSide
side
=
new
BorderSide
(
color:
color
,
width:
width
);
final
BorderSide
side
=
new
BorderSide
(
color:
color
,
width:
width
);
return
new
Border
(
top:
side
,
right:
side
,
bottom:
side
,
left:
side
);
}
...
...
@@ -101,6 +103,29 @@ class Border {
return
new
EdgeInsets
.
TRBL
(
top
.
width
,
right
.
width
,
bottom
.
width
,
left
.
width
);
}
/// Whether all four sides of the border are identical.
bool
get
isUniform
{
assert
(
top
!=
null
);
assert
(
right
!=
null
);
assert
(
bottom
!=
null
);
assert
(
left
!=
null
);
final
Color
topColor
=
top
.
color
;
if
(
right
.
color
!=
topColor
||
bottom
.
color
!=
topColor
||
left
.
color
!=
topColor
)
return
false
;
final
double
topWidth
=
top
.
width
;
if
(
right
.
width
!=
topWidth
||
bottom
.
width
!=
topWidth
||
left
.
width
!=
topWidth
)
return
false
;
return
true
;
}
/// Creates a new border with the widths of this border multiplied by [t].
Border
scale
(
double
t
)
{
return
new
Border
(
top:
top
.
copyWith
(
width:
t
*
top
.
width
),
...
...
@@ -110,6 +135,7 @@ class Border {
);
}
/// Linearly interpolate between two borders.
static
Border
lerp
(
Border
a
,
Border
b
,
double
t
)
{
if
(
a
==
null
&&
b
==
null
)
return
null
;
...
...
@@ -129,7 +155,7 @@ class Border {
bool
operator
==(
dynamic
other
)
{
if
(
identical
(
this
,
other
))
return
true
;
if
(
other
is
!
Border
)
if
(
other
.
runtimeType
!=
runtimeType
)
return
false
;
final
Border
typedOther
=
other
;
return
top
==
typedOther
.
top
&&
...
...
@@ -1021,25 +1047,6 @@ class _BoxDecorationPainter extends BoxPainter {
return
_cachedBackgroundPaint
;
}
bool
get
_hasUniformBorder
{
Color
color
=
_decoration
.
border
.
top
.
color
;
bool
hasUniformColor
=
_decoration
.
border
.
right
.
color
==
color
&&
_decoration
.
border
.
bottom
.
color
==
color
&&
_decoration
.
border
.
left
.
color
==
color
;
if
(!
hasUniformColor
)
return
false
;
double
width
=
_decoration
.
border
.
top
.
width
;
bool
hasUniformWidth
=
_decoration
.
border
.
right
.
width
==
width
&&
_decoration
.
border
.
bottom
.
width
==
width
&&
_decoration
.
border
.
left
.
width
==
width
;
return
hasUniformWidth
;
}
void
_paintBox
(
Canvas
canvas
,
Rect
rect
,
Paint
paint
)
{
switch
(
_decoration
.
shape
)
{
case
BoxShape
.
circle
:
...
...
@@ -1098,7 +1105,7 @@ class _BoxDecorationPainter extends BoxPainter {
if
(
_decoration
.
border
==
null
)
return
;
if
(
_
hasUniformBorder
)
{
if
(
_
decoration
.
border
.
isUniform
)
{
if
(
_decoration
.
borderRadius
!=
null
)
{
_paintBorderWithRadius
(
canvas
,
rect
);
return
;
...
...
@@ -1158,7 +1165,7 @@ class _BoxDecorationPainter extends BoxPainter {
}
void
_paintBorderWithRadius
(
Canvas
canvas
,
Rect
rect
)
{
assert
(
_
hasUniformBorder
);
assert
(
_
decoration
.
border
.
isUniform
);
assert
(
_decoration
.
shape
==
BoxShape
.
rectangle
);
Color
color
=
_decoration
.
border
.
top
.
color
;
double
width
=
_decoration
.
border
.
top
.
width
;
...
...
@@ -1170,7 +1177,7 @@ class _BoxDecorationPainter extends BoxPainter {
}
void
_paintBorderWithCircle
(
Canvas
canvas
,
Rect
rect
)
{
assert
(
_
hasUniformBorder
);
assert
(
_
decoration
.
border
.
isUniform
);
assert
(
_decoration
.
shape
==
BoxShape
.
circle
);
assert
(
_decoration
.
borderRadius
==
null
);
double
width
=
_decoration
.
border
.
top
.
width
;
...
...
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