Skip to content

Commit

Permalink
Fix PR issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kawaijoe committed May 9, 2024
1 parent 6754c0a commit be0db55
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 26 deletions.
2 changes: 1 addition & 1 deletion forui/lib/forui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion forui/lib/src/box/box_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
45 changes: 27 additions & 18 deletions forui/lib/src/theme/font/font_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit be0db55

Please sign in to comment.