From be0db552796ee1a1ff0d9f27502a79f6c3c716d3 Mon Sep 17 00:00:00 2001 From: Joe Date: Thu, 9 May 2024 15:01:33 +0800 Subject: [PATCH] Fix PR issues --- forui/lib/forui.dart | 2 +- forui/lib/src/box/box_style.dart | 2 +- forui/lib/src/theme/font/font_data.dart | 45 +++++++++++-------- ...le_builder.dart => scaled_text_style.dart} | 12 ++--- 4 files changed, 35 insertions(+), 26 deletions(-) rename forui/lib/src/theme/font/{text_style_builder.dart => scaled_text_style.dart} (64%) diff --git a/forui/lib/forui.dart b/forui/lib/forui.dart index a15d4f680..a4947df2c 100644 --- a/forui/lib/forui.dart +++ b/forui/lib/forui.dart @@ -8,7 +8,7 @@ export 'src/theme/theme_data.dart'; export 'src/theme/widget_data.dart'; export 'src/theme/font/font_data.dart'; -export 'src/theme/font/text_style_builder.dart'; +export 'src/theme/font/scaled_text_style.dart'; export 'src/theme/style/zinc_style.dart'; diff --git a/forui/lib/src/box/box_style.dart b/forui/lib/src/box/box_style.dart index e4fa3e143..bf4bf75c7 100644 --- a/forui/lib/src/box/box_style.dart +++ b/forui/lib/src/box/box_style.dart @@ -15,5 +15,5 @@ class FBoxStyle { /// Creates a [FBoxStyle] that inherits its properties from [data] and [style]. FBoxStyle.inherit({required FFontData data, required FStyleData style}): - color = style.background, text = TextStyleBuilder.inherit(data, const TextStyle(fontSize: 20)); + color = style.background, text = ScaledTextStyle(const TextStyle(fontSize: 20), data); } diff --git a/forui/lib/src/theme/font/font_data.dart b/forui/lib/src/theme/font/font_data.dart index 064107ed7..bbaae086d 100644 --- a/forui/lib/src/theme/font/font_data.dart +++ b/forui/lib/src/theme/font/font_data.dart @@ -3,33 +3,42 @@ import 'package:flutter/material.dart'; import 'package:forui/forui.dart'; import 'package:forui/src/theme/theme.dart'; -/// The default font data that is inherited from a [FTheme] by child Forui widgets. +/// The font data that is inherited from a [FTheme] deigned to be utilized by [ScaledTextStyle] and child Forui widgets. +/// +/// This class contains scalar values that are multiplied with the corresponding properties on [TextStyle] to ensure +/// that various fonts are scaled consistently across the application. class FFontData { - /// The size that corresponds to the `fontSize` property on [TextStyle]. - final double fontSize; + /// The font size scalar that multiplies with the `fontSize` property on [TextStyle]. + final double fontSizeScalar; - /// The letter spacing that corresponds to the `letterSpacing` property on [TextStyle]. - final double letterSpacing; + /// The letter spacing scalar that multiplies with the `letterSpacing` property on [TextStyle]. + final double letterSpacingScalar; - /// The word spacing that corresponds to the `wordSpacing` property on [TextStyle]. - final double wordSpacing; + /// The word spacing scalar that multiplies with the `wordSpacing` property on [TextStyle]. + final double wordSpacingScalar; - /// The height that corresponds to the `height` property on [TextStyle]. - final double height; + /// The height scalar that multiplies with the `height` property on [TextStyle]. + final double heightScalar; /// Creates a [FFontData]. const FFontData({ - this.fontSize = 1, - this.letterSpacing = 1, - this.wordSpacing = 1, - this.height = 1, + this.fontSizeScalar = 1, + this.letterSpacingScalar = 1, + this.wordSpacingScalar = 1, + this.heightScalar = 1, }); /// Creates a copy of this [FFontData] with the given properties replaced. - FFontData copyWith({double? fontSize, double? letterSpacing, double? wordSpacing, double? height}) => FFontData( - fontSize: fontSize ?? this.fontSize, - letterSpacing: letterSpacing ?? this.letterSpacing, - wordSpacing: wordSpacing ?? this.wordSpacing, - height: height ?? this.height, + FFontData copyWith({ + double? fontSizeScalar, + double? letterSpacingScalar, + double? wordSpacingScalar, + double? heightScalar, + }) => + FFontData( + fontSizeScalar: fontSizeScalar ?? this.fontSizeScalar, + letterSpacingScalar: letterSpacingScalar ?? this.letterSpacingScalar, + wordSpacingScalar: wordSpacingScalar ?? this.wordSpacingScalar, + heightScalar: heightScalar ?? this.heightScalar, ); } diff --git a/forui/lib/src/theme/font/text_style_builder.dart b/forui/lib/src/theme/font/scaled_text_style.dart similarity index 64% rename from forui/lib/src/theme/font/text_style_builder.dart rename to forui/lib/src/theme/font/scaled_text_style.dart index dd8c2dfee..a5e0e6b31 100644 --- a/forui/lib/src/theme/font/text_style_builder.dart +++ b/forui/lib/src/theme/font/scaled_text_style.dart @@ -9,13 +9,13 @@ import 'package:forui/forui.dart'; /// * Height /// * Letter spacing /// * Word spacing -extension type TextStyleBuilder._(TextStyle style) implements TextStyle { +extension type ScaledTextStyle._(TextStyle style) implements TextStyle { /// Creates a [TextStyle] that inherits the properties from the given [FFontData]. - TextStyleBuilder(TextStyle base, FFontData data): style = TextStyle( - fontSize: _calculateFactor(base.fontSize, data.fontSize), - letterSpacing: _calculateFactor(base.letterSpacing, data.letterSpacing), - wordSpacing: _calculateFactor(base.wordSpacing, data.wordSpacing), - height: _calculateFactor(base.height, data.height), + ScaledTextStyle(TextStyle base, FFontData data): style = TextStyle( + fontSize: _calculateFactor(base.fontSize, data.fontSizeScalar), + letterSpacing: _calculateFactor(base.letterSpacing, data.letterSpacingScalar), + wordSpacing: _calculateFactor(base.wordSpacing, data.wordSpacingScalar), + height: _calculateFactor(base.height, data.heightScalar), ); static double? _calculateFactor(double? value, double factor) => value == null ? null : value * factor;