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
e1f0d8c9
Commit
e1f0d8c9
authored
Mar 16, 2016
by
Adam Barth
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2727 from abarth/within_rect
Use FractionalOffset for gradients
parents
42c1f629
502a4ae0
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
18 additions
and
21 deletions
+18
-21
card_collection.dart
dev/manual_tests/card_collection.dart
+2
-2
weather_demo.dart
examples/material_gallery/lib/demo/weather_demo.dart
+2
-2
box_painter.dart
packages/flutter/lib/src/painting/box_painter.dart
+11
-14
box_test.dart
packages/flutter/test/rendering/box_test.dart
+1
-1
shader_mask_test.dart
packages/flutter/test/widget/shader_mask_test.dart
+2
-2
No files found.
dev/manual_tests/card_collection.dart
View file @
e1f0d8c9
...
...
@@ -397,8 +397,8 @@ class CardCollectionState extends State<CardCollection> {
Shader
_createShader
(
Rect
bounds
)
{
return
new
LinearGradient
(
begin:
const
Offset
(
0.0
,
0.0
),
end:
const
Offset
(
0.0
,
1.0
),
begin:
const
Fractional
Offset
(
0.0
,
0.0
),
end:
const
Fractional
Offset
(
0.0
,
1.0
),
colors:
<
Color
>[
const
Color
(
0x00FFFFFF
),
const
Color
(
0xFFFFFFFF
)],
stops:
<
double
>[
0.1
,
0.35
]
)
...
...
examples/material_gallery/lib/demo/weather_demo.dart
View file @
e1f0d8c9
...
...
@@ -285,8 +285,8 @@ class GradientNode extends NodeWithSize {
Rect
rect
=
Point
.
origin
&
size
;
Paint
gradientPaint
=
new
Paint
()..
shader
=
new
LinearGradient
(
begin:
const
Offset
(
0.0
,
0.0
),
end:
const
Offset
(
0.0
,
1.0
),
begin:
const
Fractional
Offset
(
0.0
,
0.0
),
end:
const
Fractional
Offset
(
0.0
,
1.0
),
colors:
<
Color
>[
colorTop
,
colorBottom
],
stops:
<
double
>[
0.0
,
1.0
]
).
createShader
(
rect
);
...
...
packages/flutter/lib/src/painting/box_painter.dart
View file @
e1f0d8c9
...
...
@@ -244,12 +244,6 @@ class BoxShadow {
String
toString
()
=>
'BoxShadow(
$color
,
$offset
,
$blurRadius
,
$spreadRadius
)'
;
}
// TODO(ianh): We should probably expose something that does this on Rect.
// https://github.com/flutter/flutter/issues/2318
Point
_offsetToPoint
(
Offset
offset
,
Rect
rect
)
{
return
new
Point
(
rect
.
left
+
offset
.
dx
*
rect
.
width
,
rect
.
top
+
offset
.
dy
*
rect
.
height
);
}
/// A 2D gradient.
abstract
class
Gradient
{
const
Gradient
();
...
...
@@ -259,8 +253,8 @@ abstract class Gradient {
/// A 2D linear gradient.
class
LinearGradient
extends
Gradient
{
const
LinearGradient
({
this
.
begin
:
const
Offset
(
0.0
,
0.5
),
this
.
end
:
const
Offset
(
1.0
,
0.5
),
this
.
begin
:
const
Fractional
Offset
(
0.0
,
0.5
),
this
.
end
:
const
Fractional
Offset
(
1.0
,
0.5
),
this
.
colors
,
this
.
stops
,
this
.
tileMode
:
TileMode
.
clamp
...
...
@@ -272,7 +266,7 @@ class LinearGradient extends Gradient {
///
/// For example, a begin offset of (0.0,0.5) is half way down the
/// left side of the box.
final
Offset
begin
;
final
Fractional
Offset
begin
;
/// The offset from coordinate (0.0,0.0) at which stop 1.0 of the
/// gradient is placed, in a coordinate space that maps the top left
...
...
@@ -280,7 +274,7 @@ class LinearGradient extends Gradient {
///
/// For example, an end offset of (1.0,0.5) is half way down the
/// right side of the box.
final
Offset
end
;
final
Fractional
Offset
end
;
/// The colors the gradient should obtain at each of the stops.
///
...
...
@@ -299,7 +293,7 @@ class LinearGradient extends Gradient {
@override
Shader
createShader
(
Rect
rect
)
{
return
new
ui
.
Gradient
.
linear
(
<
Point
>[
_offsetToPoint
(
begin
,
rect
),
_offsetToPoint
(
end
,
rect
)],
<
Point
>[
begin
.
withinRect
(
rect
),
end
.
withinRect
(
rect
)],
colors
,
stops
,
tileMode
);
}
...
...
@@ -348,7 +342,7 @@ class LinearGradient extends Gradient {
/// A 2D radial gradient.
class
RadialGradient
extends
Gradient
{
const
RadialGradient
({
this
.
center
:
const
Offset
(
0.5
,
0.5
),
this
.
center
:
const
Fractional
Offset
(
0.5
,
0.5
),
this
.
radius
:
0.5
,
this
.
colors
,
this
.
stops
,
...
...
@@ -360,7 +354,7 @@ class RadialGradient extends Gradient {
///
/// For example, an offset of (0.5,0.5) will place the radial
/// gradient in the center of the box.
final
Offset
center
;
final
Fractional
Offset
center
;
/// The radius of the gradient, as a fraction of the shortest side
/// of the paint box.
...
...
@@ -389,7 +383,7 @@ class RadialGradient extends Gradient {
@override
Shader
createShader
(
Rect
rect
)
{
return
new
ui
.
Gradient
.
radial
(
_offsetToPoint
(
center
,
rect
),
center
.
withinRect
(
rect
),
radius
*
rect
.
shortestSide
,
colors
,
stops
,
tileMode
);
...
...
@@ -645,6 +639,9 @@ class FractionalOffset {
Offset
alongSize
(
Size
other
)
{
return
new
Offset
(
dx
*
other
.
width
,
dy
*
other
.
height
);
}
Point
withinRect
(
Rect
rect
)
{
return
new
Point
(
rect
.
left
+
dx
*
rect
.
width
,
rect
.
top
+
dy
*
rect
.
height
);
}
@override
bool
operator
==(
dynamic
other
)
{
...
...
packages/flutter/test/rendering/box_test.dart
View file @
e1f0d8c9
...
...
@@ -14,7 +14,7 @@ void main() {
decoration:
new
BoxDecoration
(
backgroundColor:
const
Color
(
0xFF00FF00
),
gradient:
new
RadialGradient
(
center:
Offset
.
zero
,
radius:
1.8
,
center:
Fractional
Offset
.
zero
,
radius:
1.8
,
colors:
<
Color
>[
Colors
.
yellow
[
500
],
Colors
.
blue
[
500
]]),
boxShadow:
elevationToShadow
[
3
])
);
...
...
packages/flutter/test/widget/shader_mask_test.dart
View file @
e1f0d8c9
...
...
@@ -10,8 +10,8 @@ import 'package:test/test.dart';
Shader
createShader
(
Rect
bounds
)
{
return
new
LinearGradient
(
begin:
const
Offset
(
0.0
,
0.0
),
end:
const
Offset
(
0.0
,
1.0
),
begin:
const
Fractional
Offset
(
0.0
,
0.0
),
end:
const
Fractional
Offset
(
0.0
,
1.0
),
colors:
<
Color
>[
const
Color
(
0x00FFFFFF
),
const
Color
(
0xFFFFFFFF
)],
stops:
<
double
>[
0.1
,
0.35
]
)
...
...
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