@@ -553,12 +553,19 @@ class InlineContent extends StatelessWidget {
553
553
required this .style,
554
554
required this .nodes,
555
555
}) {
556
+ assert (style.fontSize != null );
556
557
_builder = _InlineContentBuilder (this );
557
558
}
558
559
559
560
final GestureRecognizer ? recognizer;
560
561
final Map <LinkNode , GestureRecognizer >? linkRecognizers;
562
+
563
+ /// A [TextStyle] applied to this content and provided to descendants.
564
+ ///
565
+ /// Must set [TextStyle.fontSize] . Some descendant spans will consume it,
566
+ /// e.g., to make their content slightly smaller than surrounding text.
561
567
final TextStyle style;
568
+
562
569
final List <InlineContentNode > nodes;
563
570
564
571
late final _InlineContentBuilder _builder;
@@ -630,18 +637,21 @@ class _InlineContentBuilder {
630
637
return _buildInlineCode (node);
631
638
} else if (node is UserMentionNode ) {
632
639
return WidgetSpan (alignment: PlaceholderAlignment .middle,
633
- child: UserMention (node: node));
640
+ child: UserMention (surroundingTextStyle : widget.style, node: node));
634
641
} else if (node is UnicodeEmojiNode ) {
635
642
return TextSpan (text: node.emojiUnicode, recognizer: _recognizer);
636
643
} else if (node is ImageEmojiNode ) {
637
644
return WidgetSpan (alignment: PlaceholderAlignment .middle,
638
645
child: MessageImageEmoji (node: node));
639
646
} else if (node is MathInlineNode ) {
640
- return TextSpan (style: _kInlineMathStyle,
647
+ return TextSpan (
648
+ style: widget.style
649
+ .merge (_kInlineMathStyle)
650
+ .apply (fontSizeFactor: _kInlineCodeFontSizeFactor),
641
651
children: [TextSpan (text: node.texSource)]);
642
652
} else if (node is GlobalTimeNode ) {
643
653
return WidgetSpan (alignment: PlaceholderAlignment .middle,
644
- child: GlobalTime (node: node));
654
+ child: GlobalTime (node: node, surroundingTextStyle : widget.style ));
645
655
} else if (node is UnimplementedInlineContentNode ) {
646
656
return _errorUnimplemented (node);
647
657
} else {
@@ -690,8 +700,13 @@ class _InlineContentBuilder {
690
700
691
701
// TODO `code`: find equivalent of web's `unicode-bidi: embed; direction: ltr`
692
702
693
- // Use a light gray background, instead of a border.
694
- return _buildNodes (style: _kInlineCodeStyle, node.nodes);
703
+ return _buildNodes (
704
+ // Use a light gray background, instead of a border.
705
+ style: widget.style
706
+ .merge (_kInlineCodeStyle)
707
+ .apply (fontSizeFactor: _kInlineCodeFontSizeFactor),
708
+ node.nodes,
709
+ );
695
710
696
711
// Another fun solution -- we can in fact have a border! Like so:
697
712
// TextStyle(
@@ -711,17 +726,27 @@ class _InlineContentBuilder {
711
726
}
712
727
}
713
728
729
+ /// The [TextStyle] for inline math, excluding font-size adjustment.
730
+ ///
731
+ /// Inline math should use this and also apply [_kInlineCodeFontSizeFactor]
732
+ /// to the font size of the surrounding text
733
+ /// (which might be a Paragraph, a Heading, etc.).
714
734
final _kInlineMathStyle = _kInlineCodeStyle.merge (TextStyle (
715
735
backgroundColor: const HSLColor .fromAHSL (1 , 240 , 0.4 , 0.93 ).toColor ()));
716
736
737
+ const _kInlineCodeFontSizeFactor = 0.825 ;
738
+
739
+ /// The [TextStyle] for inline code, excluding font-size adjustment.
740
+ ///
741
+ /// Inline code should use this and also apply [_kInlineCodeFontSizeFactor]
742
+ /// to the font size of the surrounding text
743
+ /// (which might be a Paragraph, a Heading, etc.).
717
744
// Even though [kMonospaceTextStyle] is a variable-weight font,
718
745
// it's acceptable to skip [weightVariableTextStyle] here,
719
746
// assuming the text gets the effect of [weightVariableTextStyle]
720
747
// through inheritance, e.g., from a [DefaultTextStyle].
721
748
final _kInlineCodeStyle = kMonospaceTextStyle
722
- .merge (const TextStyle (
723
- backgroundColor: Color (0xffeeeeee ),
724
- fontSize: 0.825 * kBaseFontSize));
749
+ .merge (const TextStyle (backgroundColor: Color (0xffeeeeee )));
725
750
726
751
final _kCodeBlockStyle = kMonospaceTextStyle
727
752
.merge (const TextStyle (
@@ -752,22 +777,27 @@ final _kCodeBlockStyle = kMonospaceTextStyle
752
777
// const _kInlineCodeRightBracket = '⟩';
753
778
754
779
class UserMention extends StatelessWidget {
755
- const UserMention ({super .key, required this .node});
780
+ const UserMention ({
781
+ super .key,
782
+ required this .surroundingTextStyle,
783
+ required this .node,
784
+ });
756
785
786
+ final TextStyle surroundingTextStyle;
757
787
final UserMentionNode node;
758
788
759
789
@override
760
790
Widget build (BuildContext context) {
761
791
return Container (
762
792
decoration: _kDecoration,
763
- padding: const EdgeInsets .symmetric (horizontal: 0.2 * kBaseFontSize ),
793
+ padding: EdgeInsets .symmetric (horizontal: 0.2 * surroundingTextStyle.fontSize ! ),
764
794
child: InlineContent (
765
795
// If an @-mention is inside a link, let the @-mention override it.
766
796
recognizer: null , // TODO make @-mentions tappable, for info on user
767
797
// One hopes an @-mention can't contain an embedded link.
768
798
// (The parser on creating a UserMentionNode has a TODO to check that.)
769
799
linkRecognizers: null ,
770
- style: Paragraph .textStyle ,
800
+ style: surroundingTextStyle ,
771
801
nodes: node.nodes));
772
802
}
773
803
@@ -834,16 +864,23 @@ class MessageImageEmoji extends StatelessWidget {
834
864
}
835
865
836
866
class GlobalTime extends StatelessWidget {
837
- const GlobalTime ({super .key, required this .node});
867
+ const GlobalTime ({
868
+ super .key,
869
+ required this .node,
870
+ required this .surroundingTextStyle,
871
+ });
838
872
839
873
final GlobalTimeNode node;
874
+ final TextStyle surroundingTextStyle;
840
875
841
876
static final _backgroundColor = const HSLColor .fromAHSL (1 , 0 , 0 , 0.93 ).toColor ();
842
877
static final _borderColor = const HSLColor .fromAHSL (1 , 0 , 0 , 0.8 ).toColor ();
843
878
static final _dateFormat = DateFormat ('EEE, MMM d, y, h:mm a' ); // TODO(intl): localize date
844
879
845
880
@override
846
881
Widget build (BuildContext context) {
882
+ final surroundingFontSize = surroundingTextStyle.fontSize! ;
883
+
847
884
// Design taken from css for `.rendered_markdown & time` in web,
848
885
// see zulip:web/styles/rendered_markdown.css .
849
886
final text = _dateFormat.format (node.datetime.toLocal ());
@@ -855,15 +892,15 @@ class GlobalTime extends StatelessWidget {
855
892
border: Border .all (width: 1 , color: _borderColor),
856
893
borderRadius: BorderRadius .circular (3 )),
857
894
child: Padding (
858
- padding: const EdgeInsets .symmetric (horizontal: 0.2 * kBaseFontSize ),
895
+ padding: EdgeInsets .symmetric (horizontal: 0.2 * surroundingFontSize ),
859
896
child: Row (
860
897
mainAxisSize: MainAxisSize .min,
861
898
children: [
862
- const Icon (ZulipIcons .clock, size: kBaseFontSize ),
899
+ Icon (ZulipIcons .clock, size: surroundingFontSize ),
863
900
// Ad-hoc spacing adjustment per feedback:
864
901
// https://chat.zulip.org/#narrow/stream/101-design/topic/clock.20icons/near/1729345
865
902
const SizedBox (width: 1 ),
866
- Text (text, style: Paragraph .textStyle ),
903
+ Text (text, style: surroundingTextStyle ),
867
904
]))));
868
905
}
869
906
}
0 commit comments