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
365d2277
Commit
365d2277
authored
Aug 29, 2015
by
Adam Barth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename ParagraphPainter to TextPainter
Also, add asserts that the text has layout before being painted.
parent
5feb77f6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
27 deletions
+60
-27
text_painter.dart
packages/flutter/lib/painting/text_painter.dart
+40
-6
paragraph.dart
packages/flutter/lib/rendering/paragraph.dart
+19
-20
basic.dart
packages/flutter/lib/widgets/basic.dart
+1
-1
No files found.
packages/flutter/lib/painting/
paragraph
_painter.dart
→
packages/flutter/lib/painting/
text
_painter.dart
View file @
365d2277
...
...
@@ -90,8 +90,8 @@ class StyledTextSpan extends TextSpan {
}
}
class
Paragraph
Painter
{
Paragraph
Painter
(
TextSpan
text
)
{
class
Text
Painter
{
Text
Painter
(
TextSpan
text
)
{
_layoutRoot
.
rootElement
=
_document
.
createElement
(
'p'
);
assert
(
text
!=
null
);
this
.
text
=
text
;
...
...
@@ -99,40 +99,68 @@ class ParagraphPainter {
final
sky
.
Document
_document
=
new
sky
.
Document
();
final
sky
.
LayoutRoot
_layoutRoot
=
new
sky
.
LayoutRoot
();
bool
_needsLayout
=
true
;
TextSpan
_text
;
TextSpan
get
text
=>
_text
;
void
set
text
(
TextSpan
value
)
{
if
(
_text
==
value
)
return
;
_text
=
value
;
_layoutRoot
.
rootElement
.
setChild
(
_text
.
_toDOM
(
_document
));
_layoutRoot
.
rootElement
.
removeAttribute
(
'style'
);
_text
.
_applyStyleToContainer
(
_layoutRoot
.
rootElement
);
_needsLayout
=
true
;
}
double
get
minWidth
=>
_layoutRoot
.
minWidth
;
void
set
minWidth
(
value
)
{
if
(
_layoutRoot
.
minWidth
==
value
)
return
;
_layoutRoot
.
minWidth
=
value
;
_needsLayout
=
true
;
}
double
get
maxWidth
=>
_layoutRoot
.
maxWidth
;
void
set
maxWidth
(
value
)
{
if
(
_layoutRoot
.
maxWidth
==
value
)
return
;
_layoutRoot
.
maxWidth
=
value
;
_needsLayout
=
true
;
}
double
get
minHeight
=>
_layoutRoot
.
minHeight
;
void
set
minHeight
(
value
)
{
if
(
_layoutRoot
.
minHeight
==
value
)
return
;
_layoutRoot
.
minHeight
=
value
;
_needsLayout
=
true
;
}
double
get
maxHeight
=>
_layoutRoot
.
maxHeight
;
void
set
maxHeight
(
value
)
{
if
(
_layoutRoot
.
maxHeight
==
value
)
return
;
_layoutRoot
.
maxHeight
=
value
;
}
double
get
minContentWidth
=>
_layoutRoot
.
rootElement
.
minContentWidth
;
double
get
maxContentWidth
=>
_layoutRoot
.
rootElement
.
maxContentWidth
;
double
get
height
=>
_layoutRoot
.
rootElement
.
height
;
double
get
minContentWidth
{
assert
(!
_needsLayout
);
return
_layoutRoot
.
rootElement
.
minContentWidth
;
}
double
get
maxContentWidth
{
assert
(!
_needsLayout
);
return
_layoutRoot
.
rootElement
.
maxContentWidth
;
}
double
get
height
{
assert
(!
_needsLayout
);
return
_layoutRoot
.
rootElement
.
height
;
}
double
computeDistanceToActualBaseline
(
TextBaseline
baseline
)
{
assert
(!
_needsLayout
);
sky
.
Element
root
=
_layoutRoot
.
rootElement
;
switch
(
baseline
)
{
case
TextBaseline
.
alphabetic
:
return
root
.
alphabeticBaseline
;
...
...
@@ -140,9 +168,15 @@ class ParagraphPainter {
}
}
void
layout
()
=>
_layoutRoot
.
layout
();
void
layout
()
{
if
(!
_needsLayout
)
return
;
_layoutRoot
.
layout
();
_needsLayout
=
false
;
}
void
paint
(
sky
.
Canvas
canvas
,
sky
.
Offset
offset
)
{
assert
(!
_needsLayout
&&
"Please call layout() before paint() to position the text before painting it."
is
String
);
// TODO(ianh): Make LayoutRoot support a paint offset so we don't
// need to translate for each span of text.
canvas
.
translate
(
offset
.
dx
,
offset
.
dy
);
...
...
packages/flutter/lib/rendering/paragraph.dart
View file @
365d2277
...
...
@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:sky/painting/
paragraph
_painter.dart'
;
import
'package:sky/painting/
text
_painter.dart'
;
import
'package:sky/rendering/box.dart'
;
import
'package:sky/rendering/object.dart'
;
export
'package:sky/painting/
paragraph
_painter.dart'
;
export
'package:sky/painting/
text
_painter.dart'
;
// Unfortunately, using full precision floating point here causes bad layouts
// because floating point math isn't associative. If we add and subtract
...
...
@@ -21,20 +21,19 @@ double _applyFloatingPointHack(double layoutValue) {
class
RenderParagraph
extends
RenderBox
{
RenderParagraph
(
TextSpan
text
)
:
_paragraphPainter
=
new
ParagraphPainter
(
text
)
{
RenderParagraph
(
TextSpan
text
)
:
_textPainter
=
new
TextPainter
(
text
)
{
assert
(
text
!=
null
);
}
ParagraphPainter
_paragraph
Painter
;
TextPainter
_text
Painter
;
BoxConstraints
_constraintsForCurrentLayout
;
// when null, we don't have a current layout
TextSpan
get
text
=>
_
paragraph
Painter
.
text
;
TextSpan
get
text
=>
_
text
Painter
.
text
;
void
set
text
(
TextSpan
value
)
{
if
(
_
paragraph
Painter
.
text
==
value
)
if
(
_
text
Painter
.
text
==
value
)
return
;
_
paragraph
Painter
.
text
=
value
;
_
text
Painter
.
text
=
value
;
_constraintsForCurrentLayout
=
null
;
markNeedsLayout
();
}
...
...
@@ -43,30 +42,30 @@ class RenderParagraph extends RenderBox {
assert
(
constraints
!=
null
);
if
(
_constraintsForCurrentLayout
==
constraints
)
return
;
// already cached this layout
_
paragraph
Painter
.
maxWidth
=
constraints
.
maxWidth
;
_
paragraph
Painter
.
minWidth
=
constraints
.
minWidth
;
_
paragraph
Painter
.
minHeight
=
constraints
.
minHeight
;
_
paragraph
Painter
.
maxHeight
=
constraints
.
maxHeight
;
_
paragraph
Painter
.
layout
();
_
text
Painter
.
maxWidth
=
constraints
.
maxWidth
;
_
text
Painter
.
minWidth
=
constraints
.
minWidth
;
_
text
Painter
.
minHeight
=
constraints
.
minHeight
;
_
text
Painter
.
maxHeight
=
constraints
.
maxHeight
;
_
text
Painter
.
layout
();
_constraintsForCurrentLayout
=
constraints
;
}
double
getMinIntrinsicWidth
(
BoxConstraints
constraints
)
{
_layout
(
constraints
);
return
constraints
.
constrainWidth
(
_applyFloatingPointHack
(
_
paragraph
Painter
.
minContentWidth
));
_applyFloatingPointHack
(
_
text
Painter
.
minContentWidth
));
}
double
getMaxIntrinsicWidth
(
BoxConstraints
constraints
)
{
_layout
(
constraints
);
return
constraints
.
constrainWidth
(
_applyFloatingPointHack
(
_
paragraph
Painter
.
maxContentWidth
));
_applyFloatingPointHack
(
_
text
Painter
.
maxContentWidth
));
}
double
_getIntrinsicHeight
(
BoxConstraints
constraints
)
{
_layout
(
constraints
);
return
constraints
.
constrainHeight
(
_applyFloatingPointHack
(
_
paragraph
Painter
.
height
));
_applyFloatingPointHack
(
_
text
Painter
.
height
));
}
double
getMinIntrinsicHeight
(
BoxConstraints
constraints
)
{
...
...
@@ -80,14 +79,14 @@ class RenderParagraph extends RenderBox {
double
computeDistanceToActualBaseline
(
TextBaseline
baseline
)
{
assert
(!
needsLayout
);
_layout
(
constraints
);
return
_
paragraph
Painter
.
computeDistanceToActualBaseline
(
baseline
);
return
_
text
Painter
.
computeDistanceToActualBaseline
(
baseline
);
}
void
performLayout
()
{
_layout
(
constraints
);
// _paragraphPainter.width always expands to fill, use maxContentWidth instead.
size
=
constraints
.
constrain
(
new
Size
(
_applyFloatingPointHack
(
_
paragraph
Painter
.
maxContentWidth
),
_applyFloatingPointHack
(
_
paragraph
Painter
.
height
)));
size
=
constraints
.
constrain
(
new
Size
(
_applyFloatingPointHack
(
_
text
Painter
.
maxContentWidth
),
_applyFloatingPointHack
(
_
text
Painter
.
height
)));
}
void
paint
(
PaintingContext
context
,
Offset
offset
)
{
...
...
@@ -99,7 +98,7 @@ class RenderParagraph extends RenderBox {
// TODO(abarth): Make computing the min/max intrinsic width/height
// a non-destructive operation.
_layout
(
constraints
);
_
paragraph
Painter
.
paint
(
context
.
canvas
,
offset
);
_
text
Painter
.
paint
(
context
.
canvas
,
offset
);
}
// we should probably expose a way to do precise (inter-glpyh) hit testing
...
...
packages/flutter/lib/widgets/basic.dart
View file @
365d2277
...
...
@@ -9,8 +9,8 @@ import 'package:vector_math/vector_math.dart';
import
'package:sky/base/image_resource.dart'
;
import
'package:sky/mojo/asset_bundle.dart'
;
import
'package:sky/mojo/net/image_cache.dart'
as
image_cache
;
import
'package:sky/painting/text_painter.dart'
;
import
'package:sky/painting/text_style.dart'
;
import
'package:sky/painting/paragraph_painter.dart'
;
import
'package:sky/rendering/block.dart'
;
import
'package:sky/rendering/box.dart'
;
import
'package:sky/rendering/flex.dart'
;
...
...
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