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
b1435e29
Commit
b1435e29
authored
Nov 11, 2015
by
Adam Barth
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #305 from abarth/input_layout
Give loose contraints to text inside input widget
parents
6d57a2a2
64a64535
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
28 deletions
+34
-28
input.dart
packages/flutter/lib/src/material/input.dart
+2
-2
text_painter.dart
packages/flutter/lib/src/painting/text_painter.dart
+10
-2
editable_paragraph.dart
packages/flutter/lib/src/rendering/editable_paragraph.dart
+21
-20
paragraph.dart
packages/flutter/lib/src/rendering/paragraph.dart
+1
-4
No files found.
packages/flutter/lib/src/material/input.dart
View file @
b1435e29
...
...
@@ -167,7 +167,7 @@ class InputState extends ScrollableState<Input> {
scrollTo
(
scrollBehavior
.
updateExtents
(
contentExtent:
_contentWidth
,
containerExtent:
_containerWidth
,
scrollOffset:
_contentWidth
)
);
scrollOffset:
_contentWidth
)
)
;
}
}
packages/flutter/lib/src/painting/text_painter.dart
View file @
b1435e29
...
...
@@ -177,10 +177,18 @@ class TextPainter {
return
_applyFloatingPointHack
(
_paragraph
.
maxIntrinsicWidth
);
}
double
get
width
{
assert
(!
_needsLayout
);
return
_applyFloatingPointHack
(
_paragraph
.
width
);
}
double
get
height
{
assert
(!
_needsLayout
);
return
_applyFloatingPointHack
(
_paragraph
.
height
);
}
Size
get
size
{
assert
(!
_needsLayout
);
double
height
=
_applyFloatingPointHack
(
_paragraph
.
height
);
double
width
=
_applyFloatingPointHack
(
_paragraph
.
width
);
return
new
Size
(
width
,
height
);
}
...
...
packages/flutter/lib/src/rendering/editable_paragraph.dart
View file @
b1435e29
...
...
@@ -60,15 +60,21 @@ class RenderEditableParagraph extends RenderParagraph {
markNeedsPaint
();
}
// Editable text does not support line wrap.
bool
get
allowLineWrap
=>
false
;
BoxConstraints
_getTextContraints
(
BoxConstraints
constraints
)
{
return
new
BoxConstraints
(
minWidth:
0.0
,
maxWidth:
double
.
INFINITY
,
minHeight:
constraints
.
minHeight
,
maxHeight:
constraints
.
maxHeight
);
}
double
_getIntrinsicWidth
(
BoxConstraints
constraints
)
{
// There should be no difference between the minimum and maximum width
// because we only support single-line text.
layoutText
(
constraints
);
layoutText
(
_getTextContraints
(
constraints
)
);
return
constraints
.
constrainWidth
(
textPainter
.
size
.
width
+
_kCursorGap
+
_kCursorWidth
textPainter
.
width
+
_kCursorGap
+
_kCursorWidth
);
}
...
...
@@ -81,23 +87,21 @@ class RenderEditableParagraph extends RenderParagraph {
}
void
performLayout
()
{
layoutText
(
constraints
);
layoutText
(
_getTextContraints
(
constraints
));
Size
contentSize
=
new
Size
(
textPainter
.
width
+
_kCursorGap
+
_kCursorWidth
,
textPainter
.
height
);
size
=
constraints
.
constrain
(
contentSize
);
Offset
cursorPadding
=
const
Offset
(
_kCursorGap
+
_kCursorWidth
,
0.0
);
Size
newContentSize
=
textPainter
.
size
+
cursorPadding
;
size
=
constraints
.
constrain
(
newContentSize
);
if
(
_contentSize
==
null
||
_contentSize
!=
newContentSize
)
{
_contentSize
=
newContentSize
;
if
(
_contentSize
==
null
||
_contentSize
!=
contentSize
)
{
_contentSize
=
contentSize
;
if
(
onContentSizeChanged
!=
null
)
onContentSizeChanged
(
newC
ontentSize
);
onContentSizeChanged
(
_c
ontentSize
);
}
}
void
paint
(
PaintingContext
context
,
Offset
offset
)
{
layoutText
(
constraints
);
layoutText
(
_getTextContraints
(
constraints
)
);
bool
needsClipping
=
(
_contentSize
.
width
>
size
.
width
);
final
bool
needsClipping
=
(
_contentSize
.
width
>
size
.
width
);
if
(
needsClipping
)
{
context
.
canvas
.
save
();
context
.
canvas
.
clipRect
(
offset
&
size
);
...
...
@@ -107,15 +111,12 @@ class RenderEditableParagraph extends RenderParagraph {
if
(
_showCursor
)
{
Rect
cursorRect
=
new
Rect
.
fromLTWH
(
textPainter
.
size
.
width
+
_kCursorGap
,
_kCursorHeightOffset
,
offset
.
dx
+
_contentSize
.
width
-
_kCursorWidth
-
_scrollOffset
.
dx
,
offset
.
dy
+
_kCursorHeightOffset
-
_scrollOffset
.
dy
,
_kCursorWidth
,
size
.
height
-
2.0
*
_kCursorHeightOffset
);
context
.
canvas
.
drawRect
(
cursorRect
.
shift
(
offset
-
_scrollOffset
),
new
Paint
()..
color
=
_cursorColor
);
context
.
canvas
.
drawRect
(
cursorRect
,
new
Paint
()..
color
=
_cursorColor
);
}
if
(
needsClipping
)
...
...
packages/flutter/lib/src/rendering/paragraph.dart
View file @
b1435e29
...
...
@@ -47,14 +47,11 @@ class RenderParagraph extends RenderBox {
markNeedsLayout
();
}
// Whether the text should be allowed to wrap to multiple lines.
bool
get
allowLineWrap
=>
true
;
void
layoutText
(
BoxConstraints
constraints
)
{
assert
(
constraints
!=
null
);
if
(
_constraintsForCurrentLayout
==
constraints
)
return
;
// already cached this layout
textPainter
.
maxWidth
=
allowLineWrap
?
constraints
.
maxWidth
:
double
.
INFINITY
;
textPainter
.
maxWidth
=
constraints
.
maxWidth
;
textPainter
.
minWidth
=
constraints
.
minWidth
;
textPainter
.
minHeight
=
constraints
.
minHeight
;
textPainter
.
maxHeight
=
constraints
.
maxHeight
;
...
...
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