-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Utilities for text height behavior (#495)
- Loading branch information
1 parent
cc18c6f
commit 49063ec
Showing
15 changed files
with
561 additions
and
354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
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.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
packages/mix/lib/src/attributes/text_height_behavior/text_height_behavior_dto.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
), | ||
); | ||
} |
80 changes: 80 additions & 0 deletions
80
packages/mix/lib/src/attributes/text_height_behavior/text_height_behavior_dto.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.