Skip to content
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
18 changes: 18 additions & 0 deletions lib/core/models/styles/text_editor_style.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Flutter imports:
import 'dart:ui' as ui;

import 'package:flutter/material.dart';

import '../../constants/editor_style_constants.dart';
Expand Down Expand Up @@ -53,6 +55,7 @@ class TextEditorStyle {
/// style properties.
const TextEditorStyle({
this.textHeight = 0.0,
this.leadingDistribution = ui.TextLeadingDistribution.proportional,
this.fontSizeBottomSheetTitle,
this.textFieldMargin = const EdgeInsets.only(
bottom: kBottomNavigationBarHeight,
Expand Down Expand Up @@ -126,6 +129,19 @@ class TextEditorStyle {
/// on various platforms. Set to null to use the default line height.
final double? textHeight;

/// Controls how extra leading from the [TextStyle.height] multiplier is
/// distributed above and below the text glyph.
///
/// [TextLeadingDistribution.proportional] distributes leading proportional
/// to the font's ascent / descent ratio (~75% above, ~25% below for most
/// Latin fonts). This is the default and matches Flutter's standard
/// rendering.
///
/// [TextLeadingDistribution.even] splits the extra leading 50 / 50, which
/// visually centres glyphs inside their rounded background rects when
/// [TextStyle.height] is greater than 1.0.
final ui.TextLeadingDistribution leadingDistribution;

/// Creates a copy of this `TextEditorStyle` object with the given fields
/// replaced with new values.
///
Expand All @@ -134,6 +150,7 @@ class TextEditorStyle {
/// others unchanged.
TextEditorStyle copyWith({
double? textHeight,
ui.TextLeadingDistribution? leadingDistribution,
Color? appBarBackground,
Color? appBarColor,
Color? bottomBarBackground,
Expand All @@ -152,6 +169,7 @@ class TextEditorStyle {
}) {
return TextEditorStyle(
textHeight: textHeight ?? this.textHeight,
leadingDistribution: leadingDistribution ?? this.leadingDistribution,
fontScaleBottomSheetBackground:
fontScaleBottomSheetBackground ?? this.fontScaleBottomSheetBackground,
appBarBackground: appBarBackground ?? this.appBarBackground,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class RoundedBackgroundText extends StatelessWidget {
required this.maxTextWidth,
this.cursorWidth = 0,
this.enableHitBoxCorrection = false,
this.leadingDistribution = TextLeadingDistribution.proportional,
}) : text = TextSpan(text: text, style: style);

/// Creates a [RoundedBackgroundText] widget with rich text using
Expand All @@ -42,6 +43,7 @@ class RoundedBackgroundText extends StatelessWidget {
required this.maxTextWidth,
this.cursorWidth = 0,
this.enableHitBoxCorrection = false,
this.leadingDistribution = TextLeadingDistribution.proportional,
});

/// A flag to enable or disable hitBox correction for the text.
Expand All @@ -64,6 +66,13 @@ class RoundedBackgroundText extends StatelessWidget {
/// The width of the text cursor when displayed.
final double cursorWidth;

/// Controls how extra leading is distributed above and below the text.
///
/// Defaults to [TextLeadingDistribution.proportional].
/// Set to [TextLeadingDistribution.even] to visually centre glyphs inside
/// their rounded background rects when [TextStyle.height] > 1.0.
final TextLeadingDistribution leadingDistribution;

/// Callback function triggered with the result of a hit test.
final Function(bool hasHit)? onHitTestResult;

Expand All @@ -76,9 +85,7 @@ class RoundedBackgroundText extends StatelessWidget {
final painter = TextPainter(
text: TextSpan(
children: [text],
style: const TextStyle(
leadingDistribution: TextLeadingDistribution.proportional,
).merge(style),
style: TextStyle(leadingDistribution: leadingDistribution).merge(style),
),
textDirection: Directionality.maybeOf(context) ?? TextDirection.ltr,
maxLines: defaultTextStyle.maxLines,
Expand Down Expand Up @@ -140,6 +147,13 @@ class RoundedBackgroundText extends StatelessWidget {
value: onHitTestResult != null,
ifTrue: 'callback set',
),
)
..add(
EnumProperty<TextLeadingDistribution>(
'leadingDistribution',
leadingDistribution,
defaultValue: TextLeadingDistribution.proportional,
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class _RoundedBackgroundTextFieldState
Widget _buildBackgroundText() {
final style = widget.style.copyWith(
color: Colors.transparent,
leadingDistribution: TextLeadingDistribution.proportional,
leadingDistribution: widget.configs.style.leadingDistribution,
);

return Positioned(
Expand Down Expand Up @@ -183,7 +183,7 @@ class _RoundedBackgroundTextFieldState
scrollPadding: EdgeInsets.zero,
style: widget.style.copyWith(
fontSize: fontSize,
leadingDistribution: TextLeadingDistribution.proportional,
leadingDistribution: widget.configs.style.leadingDistribution,
height: widget.configs.style.textHeight,
),
decoration: InputDecoration.collapsed(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class LayerWidgetTextItem extends StatelessWidget {
backgroundColor: layer.background,
textAlign: layer.align,
style: finalStyle,
leadingDistribution: textEditorConfigs.style.leadingDistribution,
);
}

Expand Down
Loading