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
f6672660
Commit
f6672660
authored
Dec 04, 2015
by
Adam Barth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add custom clipping to ClipRect and ClipOval
parent
a2b8f8b9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
17 deletions
+95
-17
proxy_box.dart
packages/flutter/lib/src/rendering/proxy_box.dart
+67
-12
basic.dart
packages/flutter/lib/src/widgets/basic.dart
+28
-5
No files found.
packages/flutter/lib/src/rendering/proxy_box.dart
View file @
f6672660
...
...
@@ -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 @
f6672660
...
...
@@ -21,6 +21,7 @@ export 'package:flutter/rendering.dart' show
Canvas
,
Color
,
ColorFilter
,
CustomClipper
,
CustomPainter
,
EdgeDims
,
FlexAlignItems
,
...
...
@@ -156,8 +157,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
{
...
...
@@ -176,8 +188,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
;
}
}
...
...
@@ -1382,4 +1405,4 @@ class StatefulBuilder extends StatefulComponent {
}
class
_StatefulBuilderState
extends
State
<
StatefulBuilder
>
{
Widget
build
(
BuildContext
context
)
=>
config
.
builder
(
context
,
setState
);
}
\ No newline at end of file
}
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