Merge upstream/dev (22 commits) [upstream-sync]
Conflicts resolved by hand, our fork changes carried over: - MainActivity.kt: keep the unread widget hooks next to upstream's scroll capture (attach and detach both). - app_settings_screen.dart: upstream wrapped the list in MeshSettingsTileTheme; image-message and translation sections stay gated on kOnDeviceMl (ML-free build). - channel_chat_screen.dart: upstream split build() into methods; took theirs and re-applied the terminal-theme list padding. - chat_composer.dart: both imports (terminal_theme, radio_guard). - mesh_nav_tile.dart: upstream's meshTileTitleStyle, with the smaller terminal-theme title kept. flutter analyze clean, flutter test 1522 passed (CI image, local). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
185d2aca53
210 files changed
+52066
-5541
No files matched your search
+310
-1
@@ -1,6 +1,7 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../l10n/l10n.dart';
|
||||
@@ -13,7 +14,8 @@ import '../theme/theme_icons.dart';
|
||||
/// Building blocks used across all screens so the app reads as one product:
|
||||
/// [SectionHeader], [MeshCard], [StatusChip], [StatTile], [AvatarCircle],
|
||||
/// [SignalBars], [RouteChip], [PulseDot], [BottomSheetHeader] +
|
||||
/// [showMeshSheet], [ErrorRetryCard], and [ListEntrance].
|
||||
/// [showMeshSheet], [ErrorRetryCard], [ListEntrance], [MeshSegmentLabel]
|
||||
/// and [MeshMenuItemRow].
|
||||
|
||||
/// Small-caps mono section label, optionally with a trailing widget.
|
||||
class SectionHeader extends StatelessWidget {
|
||||
@@ -788,3 +790,310 @@ class _ListEntranceState extends State<ListEntrance>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Contents of a [PopupMenuItem]: a 20px icon, a 12px gap and a label that
|
||||
/// wraps to at most [maxLines] lines and then ends in an ellipsis, so long
|
||||
/// translations are never clipped at the menu edge.
|
||||
///
|
||||
/// Pass an [icon], or a [leading] widget for custom icons (sized 20). With
|
||||
/// neither, a 20px gap keeps the label aligned with rows that have one.
|
||||
/// [color] tints icon and label (e.g. red for a destructive action);
|
||||
/// [iconColor] tints only the icon. [selected] bolds the label, for menus
|
||||
/// that mark the current choice.
|
||||
class MeshMenuItemRow extends StatelessWidget {
|
||||
final IconData? icon;
|
||||
final Widget? leading;
|
||||
final String label;
|
||||
final Color? color;
|
||||
final Color? iconColor;
|
||||
final bool selected;
|
||||
final int maxLines;
|
||||
|
||||
const MeshMenuItemRow({
|
||||
super.key,
|
||||
this.icon,
|
||||
this.leading,
|
||||
required this.label,
|
||||
this.color,
|
||||
this.iconColor,
|
||||
this.selected = false,
|
||||
this.maxLines = 2,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final effectiveIconColor = iconColor ?? color;
|
||||
return Row(
|
||||
children: [
|
||||
IconTheme.merge(
|
||||
data: IconThemeData(size: 20, color: effectiveIconColor),
|
||||
child: SizedBox(
|
||||
width: 20,
|
||||
child:
|
||||
leading ??
|
||||
(icon == null
|
||||
? null
|
||||
: Icon(icon, size: 20, color: effectiveIconColor)),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Flexible(
|
||||
child: Text(
|
||||
label,
|
||||
maxLines: maxLines,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: color,
|
||||
fontWeight: selected ? FontWeight.bold : null,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Label for a [ButtonSegment] that never breaks a word in the middle.
|
||||
///
|
||||
/// Uses the button's text style. If the label does not fit on one line it is
|
||||
/// scaled down, but not below [minFontSize] (before the user's text scale).
|
||||
/// Below that, a multi-word label wraps at word boundaries onto up to
|
||||
/// [maxLines] centred lines, shrunk just enough for its longest word to fit.
|
||||
/// A single word that still does not fit keeps shrinking on one line, as
|
||||
/// splitting or clipping it would be harder to read than smaller text.
|
||||
class MeshSegmentLabel extends LeafRenderObjectWidget {
|
||||
final String text;
|
||||
final double minFontSize;
|
||||
final int maxLines;
|
||||
|
||||
const MeshSegmentLabel(
|
||||
this.text, {
|
||||
super.key,
|
||||
this.minFontSize = 12,
|
||||
this.maxLines = 2,
|
||||
});
|
||||
|
||||
TextStyle _style(BuildContext context) {
|
||||
final style = DefaultTextStyle.of(context).style;
|
||||
return MediaQuery.boldTextOf(context)
|
||||
? style.merge(const TextStyle(fontWeight: FontWeight.bold))
|
||||
: style;
|
||||
}
|
||||
|
||||
@override
|
||||
RenderObject createRenderObject(BuildContext context) {
|
||||
return _RenderSegmentLabel(
|
||||
text: text,
|
||||
style: _style(context),
|
||||
textScaler: MediaQuery.textScalerOf(context),
|
||||
textDirection: Directionality.of(context),
|
||||
minFontSize: minFontSize,
|
||||
maxLines: maxLines,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void updateRenderObject(BuildContext context, RenderObject renderObject) {
|
||||
(renderObject as _RenderSegmentLabel)
|
||||
..text = text
|
||||
..style = _style(context)
|
||||
..textScaler = MediaQuery.textScalerOf(context)
|
||||
..textDirection = Directionality.of(context)
|
||||
..minFontSize = minFontSize
|
||||
..maxLines = maxLines;
|
||||
}
|
||||
}
|
||||
|
||||
class _RenderSegmentLabel extends RenderBox {
|
||||
_RenderSegmentLabel({
|
||||
required String text,
|
||||
required TextStyle style,
|
||||
required TextScaler textScaler,
|
||||
required TextDirection textDirection,
|
||||
required double minFontSize,
|
||||
required int maxLines,
|
||||
}) : _text = text,
|
||||
_style = style,
|
||||
_textScaler = textScaler,
|
||||
_textDirection = textDirection,
|
||||
_minFontSize = minFontSize,
|
||||
_maxLines = maxLines;
|
||||
|
||||
final TextPainter _painter = TextPainter(textAlign: TextAlign.center);
|
||||
|
||||
String _text;
|
||||
set text(String value) {
|
||||
if (value == _text) return;
|
||||
_text = value;
|
||||
markNeedsLayout();
|
||||
markNeedsSemanticsUpdate();
|
||||
}
|
||||
|
||||
TextStyle _style;
|
||||
set style(TextStyle value) {
|
||||
if (value == _style) return;
|
||||
_style = value;
|
||||
// Layout even for a colour-only change: the painter takes the new style
|
||||
// (the selected or disabled colour) in _fit, not in paint.
|
||||
markNeedsLayout();
|
||||
}
|
||||
|
||||
@visibleForTesting
|
||||
Color? get debugPaintedColor => _painter.text?.style?.color;
|
||||
|
||||
TextScaler _textScaler;
|
||||
set textScaler(TextScaler value) {
|
||||
if (value == _textScaler) return;
|
||||
_textScaler = value;
|
||||
markNeedsLayout();
|
||||
}
|
||||
|
||||
TextDirection _textDirection;
|
||||
set textDirection(TextDirection value) {
|
||||
if (value == _textDirection) return;
|
||||
_textDirection = value;
|
||||
markNeedsLayout();
|
||||
markNeedsSemanticsUpdate();
|
||||
}
|
||||
|
||||
double _minFontSize;
|
||||
set minFontSize(double value) {
|
||||
if (value == _minFontSize) return;
|
||||
_minFontSize = value;
|
||||
markNeedsLayout();
|
||||
}
|
||||
|
||||
int _maxLines;
|
||||
set maxLines(int value) {
|
||||
if (value == _maxLines) return;
|
||||
_maxLines = value;
|
||||
markNeedsLayout();
|
||||
}
|
||||
|
||||
double get _fontSize => _style.fontSize ?? 14;
|
||||
|
||||
/// [_textScaler] further multiplied by [factor].
|
||||
TextScaler _scaled(double factor) {
|
||||
if (factor >= 1) return _textScaler;
|
||||
return TextScaler.linear(_textScaler.scale(_fontSize) * factor / _fontSize);
|
||||
}
|
||||
|
||||
double _lineWidth(TextPainter painter, String text, TextScaler scaler) {
|
||||
painter
|
||||
..text = TextSpan(text: text, style: _style)
|
||||
..textDirection = _textDirection
|
||||
..textScaler = scaler
|
||||
..maxLines = 1
|
||||
..ellipsis = null
|
||||
..layout();
|
||||
return painter.width;
|
||||
}
|
||||
|
||||
/// Configures [painter] for [maxWidth] and lays it out.
|
||||
void _fit(TextPainter painter, double maxWidth) {
|
||||
final full = _lineWidth(painter, _text, _textScaler);
|
||||
var factor = 1.0;
|
||||
var lines = 1;
|
||||
if (full > maxWidth) {
|
||||
// A little slack: glyph metrics do not scale exactly linearly.
|
||||
final fitFactor = maxWidth / full * 0.98;
|
||||
final floor = math.min(1.0, _minFontSize / _fontSize);
|
||||
final words = _text.trim().split(RegExp(r'\s+'));
|
||||
if (fitFactor >= floor || words.length < 2) {
|
||||
factor = fitFactor;
|
||||
} else {
|
||||
final longest = words
|
||||
.map((w) => _lineWidth(painter, w, _textScaler))
|
||||
.reduce(math.max);
|
||||
factor = math.min(1.0, maxWidth / longest * 0.98);
|
||||
lines = _maxLines;
|
||||
}
|
||||
}
|
||||
painter
|
||||
..text = TextSpan(text: _text, style: _style)
|
||||
..textDirection = _textDirection
|
||||
..textScaler = _scaled(factor)
|
||||
..maxLines = lines
|
||||
..ellipsis = '\u2026'
|
||||
..layout(maxWidth: maxWidth);
|
||||
}
|
||||
|
||||
double _intrinsicHeight(double width) {
|
||||
final painter = TextPainter(textAlign: TextAlign.center);
|
||||
_fit(painter, width);
|
||||
final height = painter.height;
|
||||
painter.dispose();
|
||||
return height;
|
||||
}
|
||||
|
||||
@override
|
||||
double computeMinIntrinsicWidth(double height) {
|
||||
final painter = TextPainter();
|
||||
final floor = math.min(1.0, _minFontSize / _fontSize);
|
||||
final longest = _text
|
||||
.trim()
|
||||
.split(RegExp(r'\s+'))
|
||||
.map((w) => _lineWidth(painter, w, _scaled(floor)))
|
||||
.reduce(math.max);
|
||||
painter.dispose();
|
||||
return longest.ceilToDouble();
|
||||
}
|
||||
|
||||
@override
|
||||
double computeMaxIntrinsicWidth(double height) {
|
||||
final painter = TextPainter();
|
||||
final width = _lineWidth(painter, _text, _textScaler);
|
||||
painter.dispose();
|
||||
return width.ceilToDouble();
|
||||
}
|
||||
|
||||
@override
|
||||
double computeMinIntrinsicHeight(double width) => _intrinsicHeight(width);
|
||||
|
||||
@override
|
||||
double computeMaxIntrinsicHeight(double width) => _intrinsicHeight(width);
|
||||
|
||||
@override
|
||||
Size computeDryLayout(covariant BoxConstraints constraints) {
|
||||
final painter = TextPainter(textAlign: TextAlign.center);
|
||||
_fit(painter, constraints.maxWidth);
|
||||
final size = constraints.constrain(painter.size);
|
||||
painter.dispose();
|
||||
return size;
|
||||
}
|
||||
|
||||
Offset get _paintOffset => Offset(
|
||||
(size.width - _painter.width) / 2,
|
||||
(size.height - _painter.height) / 2,
|
||||
);
|
||||
|
||||
@override
|
||||
void performLayout() {
|
||||
_fit(_painter, constraints.maxWidth);
|
||||
size = constraints.constrain(_painter.size);
|
||||
}
|
||||
|
||||
@override
|
||||
double? computeDistanceToActualBaseline(TextBaseline baseline) {
|
||||
return _paintOffset.dy + _painter.computeDistanceToActualBaseline(baseline);
|
||||
}
|
||||
|
||||
@override
|
||||
void paint(PaintingContext context, Offset offset) {
|
||||
_painter.paint(context.canvas, offset + _paintOffset);
|
||||
}
|
||||
|
||||
@override
|
||||
void describeSemanticsConfiguration(SemanticsConfiguration config) {
|
||||
super.describeSemanticsConfiguration(config);
|
||||
config
|
||||
..label = _text
|
||||
..textDirection = _textDirection;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_painter.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user