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
4a086acd
Commit
4a086acd
authored
Mar 08, 2016
by
Adam Barth
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2491 from abarth/align_cover
ImageFit.cover doesn't respect alignment
parents
bd67b563
cdc2aefc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
11 deletions
+61
-11
box_painter.dart
packages/flutter/lib/src/painting/box_painter.dart
+11
-9
image.dart
packages/flutter/lib/src/rendering/image.dart
+1
-2
paint_image_test.dart
packages/flutter/test/painting/paint_image_test.dart
+49
-0
No files found.
packages/flutter/lib/src/painting/box_painter.dart
View file @
4a086acd
...
...
@@ -492,8 +492,7 @@ void paintImage({
ImageFit
fit
,
ImageRepeat
repeat:
ImageRepeat
.
noRepeat
,
Rect
centerSlice
,
double
alignX
,
double
alignY
FractionalOffset
alignment
})
{
assert
(
canvas
!=
null
);
assert
(
image
!=
null
);
...
...
@@ -508,6 +507,7 @@ void paintImage({
outputSize
-=
sliceBorder
;
inputSize
-=
sliceBorder
;
}
Point
sourcePosition
=
Point
.
origin
;
Size
sourceSize
;
Size
destinationSize
;
fit
??=
centerSlice
==
null
?
ImageFit
.
scaleDown
:
ImageFit
.
fill
;
...
...
@@ -525,10 +525,13 @@ void paintImage({
destinationSize
=
new
Size
(
outputSize
.
width
,
sourceSize
.
height
*
outputSize
.
width
/
sourceSize
.
width
);
break
;
case
ImageFit
.
cover
:
if
(
outputSize
.
width
/
outputSize
.
height
>
inputSize
.
width
/
inputSize
.
height
)
if
(
outputSize
.
width
/
outputSize
.
height
>
inputSize
.
width
/
inputSize
.
height
)
{
sourceSize
=
new
Size
(
inputSize
.
width
,
inputSize
.
width
*
outputSize
.
height
/
outputSize
.
width
);
else
sourcePosition
=
new
Point
(
0.0
,
(
inputSize
.
height
-
sourceSize
.
height
)
*
(
alignment
?.
dy
??
0.5
));
}
else
{
sourceSize
=
new
Size
(
inputSize
.
height
*
outputSize
.
width
/
outputSize
.
height
,
inputSize
.
height
);
sourcePosition
=
new
Point
((
inputSize
.
width
-
sourceSize
.
width
)
*
(
alignment
?.
dx
??
0.5
),
0.0
);
}
destinationSize
=
outputSize
;
break
;
case
ImageFit
.
none
:
...
...
@@ -566,8 +569,8 @@ void paintImage({
// to nearest-neighbor.
paint
.
filterQuality
=
FilterQuality
.
low
;
}
double
dx
=
(
outputSize
.
width
-
destinationSize
.
width
)
*
(
align
X
??
0.5
);
double
dy
=
(
outputSize
.
height
-
destinationSize
.
height
)
*
(
align
Y
??
0.5
);
double
dx
=
(
outputSize
.
width
-
destinationSize
.
width
)
*
(
align
ment
?.
dx
??
0.5
);
double
dy
=
(
outputSize
.
height
-
destinationSize
.
height
)
*
(
align
ment
?.
dy
??
0.5
);
Point
destinationPosition
=
rect
.
topLeft
+
new
Offset
(
dx
,
dy
);
Rect
destinationRect
=
destinationPosition
&
destinationSize
;
if
(
repeat
!=
ImageRepeat
.
noRepeat
)
{
...
...
@@ -575,7 +578,7 @@ void paintImage({
canvas
.
clipRect
(
rect
);
}
if
(
centerSlice
==
null
)
{
Rect
sourceRect
=
Point
.
origi
n
&
sourceSize
;
Rect
sourceRect
=
sourcePositio
n
&
sourceSize
;
for
(
Rect
tileRect
in
_generateImageTileRects
(
rect
,
destinationRect
,
repeat
))
canvas
.
drawImageRect
(
image
,
sourceRect
,
tileRect
,
paint
);
}
else
{
...
...
@@ -1035,8 +1038,7 @@ class _BoxDecorationPainter extends BoxPainter {
rect:
rect
,
image:
image
,
colorFilter:
backgroundImage
.
colorFilter
,
alignX:
backgroundImage
.
alignment
?.
dx
,
alignY:
backgroundImage
.
alignment
?.
dy
,
alignment:
backgroundImage
.
alignment
,
fit:
backgroundImage
.
fit
,
repeat:
backgroundImage
.
repeat
);
...
...
packages/flutter/lib/src/rendering/image.dart
View file @
4a086acd
...
...
@@ -242,8 +242,7 @@ class RenderImage extends RenderBox {
image:
_image
,
colorFilter:
_colorFilter
,
fit:
_fit
,
alignX:
_alignment
?.
dx
,
alignY:
_alignment
?.
dy
,
alignment:
_alignment
,
centerSlice:
_centerSlice
,
repeat:
_repeat
);
...
...
packages/flutter/test/painting/paint_image_test.dart
0 → 100644
View file @
4a086acd
// 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.
import
'dart:ui'
as
ui
;
import
'package:flutter/painting.dart'
;
import
'package:test/test.dart'
;
class
TestImage
implements
ui
.
Image
{
TestImage
({
this
.
width
,
this
.
height
});
final
int
width
;
final
int
height
;
void
dispose
()
{
}
}
class
TestCanvas
implements
Canvas
{
final
List
<
Invocation
>
invocations
=
<
Invocation
>[];
void
noSuchMethod
(
Invocation
invocation
)
{
invocations
.
add
(
invocation
);
}
}
void
main
(
)
{
test
(
"Cover and align"
,
()
{
TestImage
image
=
new
TestImage
(
width:
300
,
height:
300
);
TestCanvas
canvas
=
new
TestCanvas
();
paintImage
(
canvas:
canvas
,
rect:
new
Rect
.
fromLTWH
(
50.0
,
75.0
,
200.0
,
100.0
),
image:
image
,
fit:
ImageFit
.
cover
,
alignment:
new
FractionalOffset
(
0.0
,
0.5
)
);
Invocation
command
=
canvas
.
invocations
.
firstWhere
((
Invocation
invocation
)
{
return
invocation
.
memberName
==
#drawImageRect
;
});
expect
(
command
,
isNotNull
);
expect
(
command
.
positionalArguments
[
0
],
equals
(
image
));
expect
(
command
.
positionalArguments
[
1
],
equals
(
new
Rect
.
fromLTWH
(
0.0
,
75.0
,
300.0
,
150.0
)));
expect
(
command
.
positionalArguments
[
2
],
equals
(
new
Rect
.
fromLTWH
(
50.0
,
75.0
,
200.0
,
100.0
)));
});
}
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