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
b38ff603
Commit
b38ff603
authored
Sep 19, 2016
by
Adam Barth
Committed by
GitHub
Sep 19, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make it possible to create new text themes (#5918)
Fixes #5916
parent
eafe1c7a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
163 additions
and
19 deletions
+163
-19
typography.dart
packages/flutter/lib/src/material/typography.dart
+156
-14
text_style.dart
packages/flutter/lib/src/painting/text_style.dart
+7
-5
No files found.
packages/flutter/lib/src/material/typography.dart
View file @
b38ff603
...
@@ -27,8 +27,29 @@ import 'colors.dart';
...
@@ -27,8 +27,29 @@ import 'colors.dart';
/// * [ThemeData]
/// * [ThemeData]
/// * <http://www.google.com/design/spec/style/typography.html>
/// * <http://www.google.com/design/spec/style/typography.html>
class
TextTheme
{
class
TextTheme
{
/// Create a text theme that uses the given values.
const
TextTheme
.
_
(
this
.
display4
,
this
.
display3
,
this
.
display2
,
this
.
display1
,
this
.
headline
,
this
.
title
,
this
.
subhead
,
this
.
body2
,
this
.
body1
,
this
.
caption
,
this
.
button
);
///
/// Rather than creating a new text theme, consider using [Typography.black]
/// or [Typography.white], which implement the typography styles in the
/// material design specification:
///
/// <https://material.google.com/style/typography.html#typography-styles>
///
/// If you do decide to create your own text theme, consider using one of
/// those predefined themes as a starting point for [copyWith] or [apply].
const
TextTheme
({
this
.
display4
,
this
.
display3
,
this
.
display2
,
this
.
display1
,
this
.
headline
,
this
.
title
,
this
.
subhead
,
this
.
body2
,
this
.
body1
,
this
.
caption
,
this
.
button
});
const
TextTheme
.
_black
()
const
TextTheme
.
_black
()
:
display4
=
const
TextStyle
(
fontFamily:
'Roboto'
,
inherit:
false
,
fontSize:
112.0
,
fontWeight:
FontWeight
.
w100
,
color:
Colors
.
black54
,
textBaseline:
TextBaseline
.
alphabetic
),
:
display4
=
const
TextStyle
(
fontFamily:
'Roboto'
,
inherit:
false
,
fontSize:
112.0
,
fontWeight:
FontWeight
.
w100
,
color:
Colors
.
black54
,
textBaseline:
TextBaseline
.
alphabetic
),
...
@@ -93,20 +114,141 @@ class TextTheme {
...
@@ -93,20 +114,141 @@ class TextTheme {
/// Used for text on [RaisedButton] and [FlatButton].
/// Used for text on [RaisedButton] and [FlatButton].
final
TextStyle
button
;
final
TextStyle
button
;
/// Creates a copy of this text theme but with the given fields replaced with
/// the new values.
///
/// Consider using [Typography.black] or [Typography.white], which implement
/// the typography styles in the material design specification, as a starting
/// point.
TextTheme
copyWith
({
TextStyle
display4
,
TextStyle
display3
,
TextStyle
display2
,
TextStyle
display1
,
TextStyle
headline
,
TextStyle
title
,
TextStyle
subhead
,
TextStyle
body2
,
TextStyle
body1
,
TextStyle
caption
,
TextStyle
button
})
{
return
new
TextTheme
(
display4:
display4
??
this
.
display4
,
display3:
display3
??
this
.
display3
,
display2:
display2
??
this
.
display2
,
display1:
display1
??
this
.
display1
,
headline:
headline
??
this
.
headline
,
title:
title
??
this
.
title
,
subhead:
subhead
??
this
.
subhead
,
body2:
body2
??
this
.
body2
,
body1:
body1
??
this
.
body1
,
caption:
caption
??
this
.
caption
,
button:
button
??
this
.
button
);
}
/// Creates a copy of this text theme but with the given field replaced in
/// each of the individual text styles.
///
/// The `displayColor` is applied to [display4], [display3], [display2],
/// [display1], and [caption]. The `bodyColor` is applied to the remaining
/// text styles.
///
/// Consider using [Typography.black] or [Typography.white], which implement
/// the typography styles in the material design specification, as a starting
/// point.
TextTheme
apply
({
String
fontFamily
,
double
fontSizeFactor:
1.0
,
double
fontSizeDelta:
0.0
,
Color
displayColor
,
Color
bodyColor
})
{
return
new
TextTheme
(
display4:
display4
.
apply
(
color:
displayColor
,
fontFamily:
fontFamily
,
fontSizeFactor:
fontSizeFactor
,
fontSizeDelta:
fontSizeDelta
),
display3:
display3
.
apply
(
color:
displayColor
,
fontFamily:
fontFamily
,
fontSizeFactor:
fontSizeFactor
,
fontSizeDelta:
fontSizeDelta
),
display2:
display2
.
apply
(
color:
displayColor
,
fontFamily:
fontFamily
,
fontSizeFactor:
fontSizeFactor
,
fontSizeDelta:
fontSizeDelta
),
display1:
display1
.
apply
(
color:
displayColor
,
fontFamily:
fontFamily
,
fontSizeFactor:
fontSizeFactor
,
fontSizeDelta:
fontSizeDelta
),
headline:
headline
.
apply
(
color:
bodyColor
,
fontFamily:
fontFamily
,
fontSizeFactor:
fontSizeFactor
,
fontSizeDelta:
fontSizeDelta
),
title:
title
.
apply
(
color:
bodyColor
,
fontFamily:
fontFamily
,
fontSizeFactor:
fontSizeFactor
,
fontSizeDelta:
fontSizeDelta
),
subhead:
subhead
.
apply
(
color:
bodyColor
,
fontFamily:
fontFamily
,
fontSizeFactor:
fontSizeFactor
,
fontSizeDelta:
fontSizeDelta
),
body2:
body2
.
apply
(
color:
bodyColor
,
fontFamily:
fontFamily
,
fontSizeFactor:
fontSizeFactor
,
fontSizeDelta:
fontSizeDelta
),
body1:
body1
.
apply
(
color:
bodyColor
,
fontFamily:
fontFamily
,
fontSizeFactor:
fontSizeFactor
,
fontSizeDelta:
fontSizeDelta
),
caption:
caption
.
apply
(
color:
displayColor
,
fontFamily:
fontFamily
,
fontSizeFactor:
fontSizeFactor
,
fontSizeDelta:
fontSizeDelta
),
button:
button
.
apply
(
color:
bodyColor
,
fontFamily:
fontFamily
,
fontSizeFactor:
fontSizeFactor
,
fontSizeDelta:
fontSizeDelta
),
);
}
/// Linearly interpolate between two text themes.
/// Linearly interpolate between two text themes.
static
TextTheme
lerp
(
TextTheme
begin
,
TextTheme
end
,
double
t
)
{
static
TextTheme
lerp
(
TextTheme
begin
,
TextTheme
end
,
double
t
)
{
return
new
TextTheme
.
_
(
return
new
TextTheme
(
TextStyle
.
lerp
(
begin
.
display4
,
end
.
display4
,
t
),
display4:
TextStyle
.
lerp
(
begin
.
display4
,
end
.
display4
,
t
),
TextStyle
.
lerp
(
begin
.
display3
,
end
.
display3
,
t
),
display3:
TextStyle
.
lerp
(
begin
.
display3
,
end
.
display3
,
t
),
TextStyle
.
lerp
(
begin
.
display2
,
end
.
display2
,
t
),
display2:
TextStyle
.
lerp
(
begin
.
display2
,
end
.
display2
,
t
),
TextStyle
.
lerp
(
begin
.
display1
,
end
.
display1
,
t
),
display1:
TextStyle
.
lerp
(
begin
.
display1
,
end
.
display1
,
t
),
TextStyle
.
lerp
(
begin
.
headline
,
end
.
headline
,
t
),
headline:
TextStyle
.
lerp
(
begin
.
headline
,
end
.
headline
,
t
),
TextStyle
.
lerp
(
begin
.
title
,
end
.
title
,
t
),
title:
TextStyle
.
lerp
(
begin
.
title
,
end
.
title
,
t
),
TextStyle
.
lerp
(
begin
.
subhead
,
end
.
subhead
,
t
),
subhead:
TextStyle
.
lerp
(
begin
.
subhead
,
end
.
subhead
,
t
),
TextStyle
.
lerp
(
begin
.
body2
,
end
.
body2
,
t
),
body2:
TextStyle
.
lerp
(
begin
.
body2
,
end
.
body2
,
t
),
TextStyle
.
lerp
(
begin
.
body1
,
end
.
body1
,
t
),
body1:
TextStyle
.
lerp
(
begin
.
body1
,
end
.
body1
,
t
),
TextStyle
.
lerp
(
begin
.
caption
,
end
.
caption
,
t
),
caption:
TextStyle
.
lerp
(
begin
.
caption
,
end
.
caption
,
t
),
TextStyle
.
lerp
(
begin
.
button
,
end
.
button
,
t
)
button:
TextStyle
.
lerp
(
begin
.
button
,
end
.
button
,
t
)
);
);
}
}
}
}
...
...
packages/flutter/lib/src/painting/text_style.dart
View file @
b38ff603
...
@@ -103,8 +103,8 @@ class TextStyle {
...
@@ -103,8 +103,8 @@ class TextStyle {
/// Creates a copy of this text style but with the numeric fields multiplied
/// Creates a copy of this text style but with the numeric fields multiplied
/// by the given factors and then incremented by the given deltas.
/// by the given factors and then incremented by the given deltas.
///
///
/// For example, `style.apply(fontSizeFactor: 2.0, fontSizeDelta: 1.0)` would
return
/// For example, `style.apply(fontSizeFactor: 2.0, fontSizeDelta: 1.0)` would
/// a [TextStyle] whose [fontSize] is `style.fontSize * 2.0 + 1.0`.
///
return
a [TextStyle] whose [fontSize] is `style.fontSize * 2.0 + 1.0`.
///
///
/// For the [fontWeight], the delta is applied to the [FontWeight] enum index
/// For the [fontWeight], the delta is applied to the [FontWeight] enum index
/// values, so that for instance `style.apply(fontWeightDelta: -2)` when
/// values, so that for instance `style.apply(fontWeightDelta: -2)` when
...
@@ -116,8 +116,10 @@ class TextStyle {
...
@@ -116,8 +116,10 @@ class TextStyle {
/// If the underlying values are null, then the corresponding factors and/or
/// If the underlying values are null, then the corresponding factors and/or
/// deltas must not be specified.
/// deltas must not be specified.
///
///
/// The non-numeric fields
are copied verbatim
.
/// The non-numeric fields
can be controlled using the cooresponding arguments
.
TextStyle
apply
({
TextStyle
apply
({
Color
color
,
String
fontFamily
,
double
fontSizeFactor:
1.0
,
double
fontSizeFactor:
1.0
,
double
fontSizeDelta:
0.0
,
double
fontSizeDelta:
0.0
,
int
fontWeightDelta:
0
,
int
fontWeightDelta:
0
,
...
@@ -144,8 +146,8 @@ class TextStyle {
...
@@ -144,8 +146,8 @@ class TextStyle {
assert
(
heightFactor
!=
null
||
(
heightFactor
==
1.0
&&
heightDelta
==
0.0
));
assert
(
heightFactor
!=
null
||
(
heightFactor
==
1.0
&&
heightDelta
==
0.0
));
return
new
TextStyle
(
return
new
TextStyle
(
inherit:
inherit
,
inherit:
inherit
,
color:
color
,
color:
color
??
this
.
color
,
fontFamily:
fontFamily
,
fontFamily:
fontFamily
??
this
.
fontFamily
,
fontSize:
fontSize
==
null
?
null
:
fontSize
*
fontSizeFactor
+
fontSizeDelta
,
fontSize:
fontSize
==
null
?
null
:
fontSize
*
fontSizeFactor
+
fontSizeDelta
,
fontWeight:
fontWeight
==
null
?
null
:
FontWeight
.
values
[(
fontWeight
.
index
+
fontWeightDelta
).
clamp
(
0
,
FontWeight
.
values
.
length
-
1
)],
fontWeight:
fontWeight
==
null
?
null
:
FontWeight
.
values
[(
fontWeight
.
index
+
fontWeightDelta
).
clamp
(
0
,
FontWeight
.
values
.
length
-
1
)],
fontStyle:
fontStyle
,
fontStyle:
fontStyle
,
...
...
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