Skip to content

Commit

Permalink
feat: Utilities for text height behavior (#495)
Browse files Browse the repository at this point in the history
  • Loading branch information
tilucasoli authored Oct 17, 2024
1 parent cc18c6f commit 49063ec
Show file tree
Hide file tree
Showing 15 changed files with 561 additions and 354 deletions.
1 change: 1 addition & 0 deletions packages/mix/lib/mix.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export 'src/attributes/shadow/shadow_util.dart';
export 'src/attributes/spacing/edge_insets_dto.dart';
export 'src/attributes/spacing/spacing_util.dart';
export 'src/attributes/strut_style/strut_style_dto.dart';
export 'src/attributes/text_height_behavior/text_height_behavior_dto.dart';
export 'src/attributes/text_style/text_style_dto.dart';
export 'src/attributes/text_style/text_style_util.dart';
/// CORE
Expand Down
8 changes: 8 additions & 0 deletions packages/mix/lib/src/attributes/enum/enum_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ final class TextDirectionUtility<T extends Attribute>
const TextDirectionUtility(super.builder);
}

/// {@macro text_direction_utility}
@MixableEnumUtility()
final class TextLeadingDistributionUtility<T extends Attribute>
extends MixUtility<T, TextLeadingDistribution>
with _$TextLeadingDistributionUtility {
const TextLeadingDistributionUtility(super.builder);
}

/// {@macro tile_mode_utility}
@MixableEnumUtility()
final class TileModeUtility<T extends Attribute> extends MixUtility<T, TileMode>
Expand Down
18 changes: 18 additions & 0 deletions packages/mix/lib/src/attributes/enum/enum_util.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions packages/mix/lib/src/attributes/scalars/scalar_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,6 @@ final class ImageProviderUtility<T extends Attribute>
T memory(Uint8List bytes) => builder(MemoryImage(bytes));
}

@MixableClassUtility()
final class TextHeightBehaviorUtility<T extends Attribute>
extends MixUtility<T, TextHeightBehavior> with _$TextHeightBehaviorUtility {
const TextHeightBehaviorUtility(super.builder);
}

@MixableClassUtility()
final class GradientTransformUtility<T extends Attribute>
extends MixUtility<T, GradientTransform> with _$GradientTransformUtility {
Expand Down
12 changes: 0 additions & 12 deletions packages/mix/lib/src/attributes/scalars/scalar_util.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// ignore_for_file: prefer_relative_imports,avoid-importing-entrypoint-exports

import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:mix/mix.dart';
import 'package:mix_annotations/mix_annotations.dart';

part 'text_height_behavior_dto.g.dart';

@MixableDto(generateUtility: false)
base class TextHeightBehaviorDto extends Dto<TextHeightBehavior>
with _$TextHeightBehaviorDto, Diagnosticable {
final bool? applyHeightToFirstAscent;
final bool? applyHeightToLastDescent;
final TextLeadingDistribution? leadingDistribution;

const TextHeightBehaviorDto({
this.applyHeightToFirstAscent,
this.applyHeightToLastDescent,
this.leadingDistribution,
});

@override
TextHeightBehavior get defaultValue => const TextHeightBehavior();
}

final class TextHeightBehaviorUtility<T extends Attribute>
extends DtoUtility<T, TextHeightBehaviorDto, TextHeightBehavior> {
late final heightToFirstAscent = BoolUtility(
(v) => only(applyHeightToFirstAscent: v),
);
late final heightToLastDescent = BoolUtility(
(v) => only(applyHeightToLastDescent: v),
);

late final leadingDistribution = TextLeadingDistributionUtility(
(v) => only(leadingDistribution: v),
);

TextHeightBehaviorUtility(super.builder)
: super(valueToDto: (v) => v.toDto());

@Deprecated("Use the utilities instead")
T call(TextHeightBehavior value) => builder(value.toDto());

@override
T only({
bool? applyHeightToFirstAscent,
bool? applyHeightToLastDescent,
TextLeadingDistribution? leadingDistribution,
}) =>
builder(
TextHeightBehaviorDto(
applyHeightToFirstAscent: applyHeightToFirstAscent,
applyHeightToLastDescent: applyHeightToLastDescent,
leadingDistribution: leadingDistribution,
),
);
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion packages/mix/lib/src/specs/text/text_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import '../../attributes/modifiers/widget_modifiers_data_dto.dart';
import '../../attributes/modifiers/widget_modifiers_util.dart';
import '../../attributes/scalars/scalar_util.dart';
import '../../attributes/strut_style/strut_style_dto.dart';
import '../../attributes/text_height_behavior/text_height_behavior_dto.dart';
import '../../attributes/text_style/text_style_dto.dart';
import '../../attributes/text_style/text_style_util.dart';
import '../../core/attribute.dart';
Expand All @@ -32,7 +33,6 @@ final class TextSpec extends Spec<TextSpec> with _$TextSpec, Diagnosticable {
final TextAlign? textAlign;
final int? maxLines;
final TextWidthBasis? textWidthBasis;
final TextHeightBehavior? textHeightBehavior;
final TextScaler? textScaler;
final TextStyle? style;
final TextDirection? textDirection;
Expand All @@ -41,6 +41,9 @@ final class TextSpec extends Spec<TextSpec> with _$TextSpec, Diagnosticable {
@Deprecated('Use textScaler instead')
final double? textScaleFactor;

@MixableProperty(dto: MixableFieldDto(type: TextHeightBehaviorDto))
final TextHeightBehavior? textHeightBehavior;

@MixableProperty(
utilities: [
MixableUtility(
Expand Down
9 changes: 5 additions & 4 deletions packages/mix/lib/src/specs/text/text_spec.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 49063ec

Please sign in to comment.