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
eaab8fa1
Commit
eaab8fa1
authored
Dec 04, 2015
by
Adam Barth
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #735 from abarth/custom_clip
Add custom clipping to ClipRect and ClipOval
parents
97599711
f6672660
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
94 additions
and
16 deletions
+94
-16
proxy_box.dart
packages/flutter/lib/src/rendering/proxy_box.dart
+67
-12
basic.dart
packages/flutter/lib/src/widgets/basic.dart
+27
-4
No files found.
packages/flutter/lib/src/rendering/proxy_box.dart
View file @
eaab8fa1
...
...
@@ -561,15 +561,61 @@ class RenderShaderMask extends RenderProxyBox {
}
}
abstract
class
CustomClipper
<
T
>
{
T
getClip
(
Size
size
);
bool
shouldRepaint
(
CustomClipper
oldClipper
);
}
abstract
class
_RenderCustomClip
<
T
>
extends
RenderProxyBox
{
_RenderCustomClip
({
RenderBox
child
,
CustomClipper
<
T
>
clipper
})
:
_clipper
=
clipper
,
super
(
child
);
CustomClipper
<
T
>
get
clipper
=>
_clipper
;
CustomClipper
<
T
>
_clipper
;
void
set
clipper
(
CustomClipper
<
T
>
newClipper
)
{
if
(
_clipper
==
newClipper
)
return
;
CustomClipper
<
T
>
oldClipper
=
_clipper
;
_clipper
=
newClipper
;
if
(
newClipper
==
null
)
{
assert
(
oldClipper
!=
null
);
markNeedsPaint
();
}
else
if
(
oldClipper
==
null
||
oldClipper
.
runtimeType
!=
oldClipper
.
runtimeType
||
newClipper
.
shouldRepaint
(
oldClipper
))
{
markNeedsPaint
();
}
}
T
get
_defaultClip
;
T
get
_clip
=>
_clipper
?.
getClip
(
size
)
??
_defaultClip
;
}
/// Clips its child using a rectangle
///
/// Prevents its child from painting outside its bounds.
class
RenderClipRect
extends
RenderProxyBox
{
RenderClipRect
({
RenderBox
child
})
:
super
(
child
);
class
RenderClipRect
extends
_RenderCustomClip
<
Rect
>
{
RenderClipRect
({
RenderBox
child
,
CustomClipper
<
Rect
>
clipper
})
:
super
(
child:
child
,
clipper:
clipper
);
Rect
get
_defaultClip
=>
Point
.
origin
&
size
;
bool
hitTest
(
HitTestResult
result
,
{
Point
position
})
{
if
(
_clipper
!=
null
)
{
Rect
clipRect
=
_clip
;
if
(!
clipRect
.
contains
(
position
))
return
false
;
}
return
super
.
hitTest
(
result
,
position:
position
);
}
void
paint
(
PaintingContext
context
,
Offset
offset
)
{
if
(
child
!=
null
)
context
.
pushClipRect
(
needsCompositing
,
offset
,
Point
.
origin
&
size
,
super
.
paint
);
context
.
pushClipRect
(
needsCompositing
,
offset
,
_clip
,
super
.
paint
);
}
}
...
...
@@ -579,8 +625,11 @@ class RenderClipRect extends RenderProxyBox {
/// y radius values and prevents its child from painting outside that rounded
/// rectangle.
class
RenderClipRRect
extends
RenderProxyBox
{
RenderClipRRect
({
RenderBox
child
,
double
xRadius
,
double
yRadius
})
:
_xRadius
=
xRadius
,
_yRadius
=
yRadius
,
super
(
child
)
{
RenderClipRRect
({
RenderBox
child
,
double
xRadius
,
double
yRadius
})
:
_xRadius
=
xRadius
,
_yRadius
=
yRadius
,
super
(
child
)
{
assert
(
_xRadius
!=
null
);
assert
(
_yRadius
!=
null
);
}
...
...
@@ -626,8 +675,11 @@ class RenderClipRRect extends RenderProxyBox {
///
/// Inscribes an oval into its layout dimensions and prevents its child from
/// painting outside that oval.
class
RenderClipOval
extends
RenderProxyBox
{
RenderClipOval
({
RenderBox
child
})
:
super
(
child
);
class
RenderClipOval
extends
_RenderCustomClip
<
Rect
>
{
RenderClipOval
({
RenderBox
child
,
CustomClipper
<
Rect
>
clipper
})
:
super
(
child:
child
,
clipper:
clipper
);
Rect
_cachedRect
;
Path
_cachedPath
;
...
...
@@ -640,10 +692,13 @@ class RenderClipOval extends RenderProxyBox {
return
_cachedPath
;
}
Rect
get
_defaultClip
=>
Point
.
origin
&
size
;
bool
hitTest
(
HitTestResult
result
,
{
Point
position
})
{
Point
center
=
size
.
center
(
Point
.
origin
);
Offset
offset
=
new
Offset
((
position
.
x
-
center
.
x
)
/
size
.
width
,
(
position
.
y
-
center
.
y
)
/
size
.
height
);
Rect
clipBounds
=
_clip
;
Point
center
=
clipBounds
.
center
;
Offset
offset
=
new
Offset
((
position
.
x
-
center
.
x
)
/
clipBounds
.
width
,
(
position
.
y
-
center
.
y
)
/
clipBounds
.
height
);
if
(
offset
.
distance
>
0.5
)
return
false
;
return
super
.
hitTest
(
result
,
position:
position
);
...
...
@@ -651,8 +706,8 @@ class RenderClipOval extends RenderProxyBox {
void
paint
(
PaintingContext
context
,
Offset
offset
)
{
if
(
child
!=
null
)
{
Rect
bounds
=
Point
.
origin
&
size
;
context
.
pushClipPath
(
needsCompositing
,
offset
,
bounds
,
_getClipPath
(
b
ounds
),
super
.
paint
);
Rect
clipBounds
=
_clip
;
context
.
pushClipPath
(
needsCompositing
,
offset
,
clipBounds
,
_getClipPath
(
clipB
ounds
),
super
.
paint
);
}
}
}
...
...
packages/flutter/lib/src/widgets/basic.dart
View file @
eaab8fa1
...
...
@@ -21,6 +21,7 @@ export 'package:flutter/rendering.dart' show
Canvas
,
Color
,
ColorFilter
,
CustomClipper
,
CustomPainter
,
EdgeDims
,
FlexAlignItems
,
...
...
@@ -160,8 +161,19 @@ class CustomPaint extends OneChildRenderObjectWidget {
}
class
ClipRect
extends
OneChildRenderObjectWidget
{
ClipRect
({
Key
key
,
Widget
child
})
:
super
(
key:
key
,
child:
child
);
RenderClipRect
createRenderObject
()
=>
new
RenderClipRect
();
ClipRect
({
Key
key
,
this
.
clipper
,
Widget
child
})
:
super
(
key:
key
,
child:
child
);
final
CustomClipper
<
Rect
>
clipper
;
RenderClipRect
createRenderObject
()
=>
new
RenderClipRect
(
clipper:
clipper
);
void
updateRenderObject
(
RenderClipRect
renderObject
,
ClipRect
oldWidget
)
{
renderObject
.
clipper
=
clipper
;
}
void
didUnmountRenderObject
(
RenderClipRect
renderObject
)
{
renderObject
.
clipper
=
null
;
}
}
class
ClipRRect
extends
OneChildRenderObjectWidget
{
...
...
@@ -180,8 +192,19 @@ class ClipRRect extends OneChildRenderObjectWidget {
}
class
ClipOval
extends
OneChildRenderObjectWidget
{
ClipOval
({
Key
key
,
Widget
child
})
:
super
(
key:
key
,
child:
child
);
RenderClipOval
createRenderObject
()
=>
new
RenderClipOval
();
ClipOval
({
Key
key
,
this
.
clipper
,
Widget
child
})
:
super
(
key:
key
,
child:
child
);
final
CustomClipper
<
Rect
>
clipper
;
RenderClipOval
createRenderObject
()
=>
new
RenderClipOval
(
clipper:
clipper
);
void
updateRenderObject
(
RenderClipOval
renderObject
,
ClipOval
oldWidget
)
{
renderObject
.
clipper
=
clipper
;
}
void
didUnmountRenderObject
(
RenderClipOval
renderObject
)
{
renderObject
.
clipper
=
null
;
}
}
...
...
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