This commit is contained in:
chen08209
2026-03-20 19:00:53 +08:00
parent 490e1bae87
commit c8a93029aa
2 changed files with 14 additions and 6 deletions

View File

@@ -11,20 +11,25 @@ class Measure {
: _measureMap = {},
_textScaler = TextScaler.linear(textScaleFactor);
TextPainter computeText(Text text, {double? maxWidth}) {
TextPainter computeText(Text text, {TextStyle? style, double? maxWidth}) {
return TextPainter(
text: TextSpan(text: text.data, style: text.style),
text: TextSpan(text: text.data, style: text.style ?? style),
maxLines: text.maxLines,
textScaler: _textScaler,
textDirection: text.textDirection ?? TextDirection.ltr,
)..layout(maxWidth: maxWidth ?? double.infinity);
}
Size computeTextSize(Text text, {double? maxWidth}) {
final textPainter = computeText(text, maxWidth: maxWidth);
Size computeTextSize(Text text, {TextStyle? style, double? maxWidth}) {
final textPainter = computeText(text, style: style, maxWidth: maxWidth);
return textPainter.size;
}
bool computeTextIsOverflow(Text text, {TextStyle? style, double? maxWidth}) {
final textPainter = computeText(text, style: style, maxWidth: maxWidth);
return textPainter.didExceedMaxLines;
}
double get bodyMediumHeight {
return _measureMap.updateCacheValue(
'bodyMediumHeight',

View File

@@ -14,8 +14,11 @@ class TooltipText extends StatelessWidget {
return LayoutBuilder(
builder: (context, constraints) {
final maxWidth = constraints.maxWidth;
final tp = globalState.measure.computeText(text, maxWidth: maxWidth);
if (tp.didExceedMaxLines) {
final isOverflow = globalState.measure.computeTextIsOverflow(
text,
maxWidth: maxWidth,
);
if (isOverflow) {
return Tooltip(
triggerMode: TooltipTriggerMode.longPress,
preferBelow: false,