Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more options to ZefyrThemeData. #107

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/zefyr/lib/src/widgets/code.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ZefyrCode extends StatelessWidget {
child: new Container(
// TODO: make decorations configurable
decoration: BoxDecoration(
color: Colors.blueGrey.shade50,
color: theme.blockTheme.code.backgroundColor,
borderRadius: BorderRadius.circular(3.0),
),
padding: const EdgeInsets.all(16.0),
Expand Down
10 changes: 7 additions & 3 deletions packages/zefyr/lib/src/widgets/horizontal_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:flutter/widgets.dart';
import 'package:notus/notus.dart';

import 'editable_box.dart';
import 'theme.dart';

class ZefyrHorizontalRule extends LeafRenderObjectWidget {
ZefyrHorizontalRule({@required this.node}) : assert(node != null);
Expand All @@ -17,7 +18,7 @@ class ZefyrHorizontalRule extends LeafRenderObjectWidget {

@override
RenderHorizontalRule createRenderObject(BuildContext context) {
return new RenderHorizontalRule(node: node);
return new RenderHorizontalRule(node: node, context: context);
}

@override
Expand All @@ -34,7 +35,8 @@ class RenderHorizontalRule extends RenderEditableBox {

RenderHorizontalRule({
@required EmbedNode node,
}) : _node = node;
@required BuildContext context,
}) : _node = node, _context = context;

@override
EmbedNode get node => _node;
Expand All @@ -45,6 +47,8 @@ class RenderHorizontalRule extends RenderEditableBox {
markNeedsPaint();
}

BuildContext _context;

@override
double get preferredLineHeight => size.height;

Expand Down Expand Up @@ -77,7 +81,7 @@ class RenderHorizontalRule extends RenderEditableBox {
@override
void paint(PaintingContext context, Offset offset) {
final rect = new Rect.fromLTWH(0.0, 0.0, size.width, _kThickness);
final paint = new ui.Paint()..color = Colors.grey.shade200;
final paint = new ui.Paint()..color = ZefyrTheme.of(_context).horizontalRuleColor;
context.canvas.drawRect(rect.shift(offset), paint);
}

Expand Down
8 changes: 4 additions & 4 deletions packages/zefyr/lib/src/widgets/quote.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ZefyrQuote extends StatelessWidget {
final style = theme.blockTheme.quote.textStyle;
List<Widget> items = [];
for (var line in node.children) {
items.add(_buildLine(line, style, theme.indentSize));
items.add(_buildLine(line, style, theme));
}

return Padding(
Expand All @@ -31,7 +31,7 @@ class ZefyrQuote extends StatelessWidget {
);
}

Widget _buildLine(Node node, TextStyle blockStyle, double indentSize) {
Widget _buildLine(Node node, TextStyle blockStyle, ZefyrThemeData theme) {
LineNode line = node;

Widget content;
Expand All @@ -45,10 +45,10 @@ class ZefyrQuote extends StatelessWidget {
return Container(
decoration: BoxDecoration(
border: Border(
left: BorderSide(width: 4.0, color: Colors.grey.shade300),
left: BorderSide(width: 4.0, color: theme.blockTheme.quote.backgroundColor),
),
),
padding: EdgeInsets.only(left: indentSize),
padding: EdgeInsets.only(left: theme.indentSize),
child: row,
);
}
Expand Down
12 changes: 12 additions & 0 deletions packages/zefyr/lib/src/widgets/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ZefyrThemeData {
final StyleTheme paragraphTheme;
final HeadingTheme headingTheme;
final BlockTheme blockTheme;
final Color horizontalRuleColor;
final Color selectionColor;
final Color cursorColor;

Expand Down Expand Up @@ -88,6 +89,7 @@ class ZefyrThemeData {
new StyleTheme(textStyle: paragraphStyle, padding: padding),
headingTheme: new HeadingTheme.fallback(),
blockTheme: new BlockTheme.fallback(),
horizontalRuleColor: Colors.grey.shade200,
selectionColor: Colors.lightBlueAccent.shade100,
cursorColor: Colors.black,
indentSize: 16.0,
Expand All @@ -102,6 +104,7 @@ class ZefyrThemeData {
this.paragraphTheme,
this.headingTheme,
this.blockTheme,
this.horizontalRuleColor,
this.selectionColor,
this.cursorColor,
this.indentSize,
Expand All @@ -116,6 +119,7 @@ class ZefyrThemeData {
StyleTheme paragraphTheme,
HeadingTheme headingTheme,
BlockTheme blockTheme,
Color horizontalRuleColor,
Color selectionColor,
Color cursorColor,
double indentSize,
Expand All @@ -128,6 +132,7 @@ class ZefyrThemeData {
paragraphTheme: paragraphTheme ?? this.paragraphTheme,
headingTheme: headingTheme ?? this.headingTheme,
blockTheme: blockTheme ?? this.blockTheme,
horizontalRuleColor: horizontalRuleColor?? this.horizontalRuleColor,
selectionColor: selectionColor ?? this.selectionColor,
cursorColor: cursorColor ?? this.cursorColor,
indentSize: indentSize ?? this.indentSize,
Expand All @@ -143,6 +148,7 @@ class ZefyrThemeData {
paragraphTheme: other.paragraphTheme,
headingTheme: other.headingTheme,
blockTheme: other.blockTheme,
horizontalRuleColor: other.horizontalRuleColor,
selectionColor: other.selectionColor,
cursorColor: other.cursorColor,
indentSize: other.indentSize,
Expand Down Expand Up @@ -232,6 +238,7 @@ class BlockTheme {
quote: new StyleTheme(
textStyle: new TextStyle(color: Colors.grey.shade700),
padding: padding,
backgroundColor: Colors.grey.shade300,
),
code: new StyleTheme(
textStyle: new TextStyle(
Expand All @@ -241,6 +248,7 @@ class BlockTheme {
height: 1.25,
),
padding: padding,
backgroundColor: Colors.blueGrey.shade50,
),
);
}
Expand All @@ -257,10 +265,14 @@ class StyleTheme {
/// Padding to apply around lines of text.
final EdgeInsets padding;

/// Background color of this theme
final Color backgroundColor;

/// Creates a new [StyleTheme].
StyleTheme({
this.textStyle,
this.padding,
this.backgroundColor,
});
}

Expand Down