mod: seg bar, dyn decorate

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-02-03 21:26:43 +08:00
parent e368436bc6
commit b4abb58a41
2 changed files with 95 additions and 80 deletions

View File

@@ -22,7 +22,7 @@ class Segment {
class SegmentProgressBar extends CustomPainter { class SegmentProgressBar extends CustomPainter {
final List<Segment> segmentColors; final List<Segment> segmentColors;
late double _defHeight; double? _defHeight;
SegmentProgressBar({ SegmentProgressBar({
required this.segmentColors, required this.segmentColors,
@@ -42,6 +42,17 @@ class SegmentProgressBar extends CustomPainter {
if (segmentColors[i].title != null) { if (segmentColors[i].title != null) {
double fontSize = 10; double fontSize = 10;
_defHeight ??= (TextPainter(
text: TextSpan(
text: segmentColors[i].title,
style: TextStyle(
fontSize: fontSize,
),
),
textDirection: TextDirection.ltr,
)..layout())
.height;
TextPainter getTextPainter() => TextPainter( TextPainter getTextPainter() => TextPainter(
text: TextSpan( text: TextSpan(
text: segmentColors[i].title, text: segmentColors[i].title,
@@ -51,14 +62,12 @@ class SegmentProgressBar extends CustomPainter {
height: 1, height: 1,
), ),
), ),
strutStyle: StrutStyle(height: 1, leading: 0), strutStyle:
StrutStyle(leading: 0, height: 1, fontSize: fontSize),
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
)..layout(); )..layout();
TextPainter textPainter = getTextPainter(); TextPainter textPainter = getTextPainter();
if (i == 0) {
_defHeight = textPainter.height;
}
late double prevStart; late double prevStart;
if (i != 0) { if (i != 0) {
@@ -75,7 +84,7 @@ class SegmentProgressBar extends CustomPainter {
canvas.drawRect( canvas.drawRect(
Rect.fromLTRB( Rect.fromLTRB(
0, 0,
-_defHeight - 2, -_defHeight!,
size.width, size.width,
0, 0,
), ),
@@ -86,9 +95,9 @@ class SegmentProgressBar extends CustomPainter {
canvas.drawRect( canvas.drawRect(
Rect.fromLTWH( Rect.fromLTWH(
segmentStart, segmentStart,
-_defHeight - 2, -_defHeight!,
segmentEnd == segmentStart ? 2 : segmentEnd - segmentStart, segmentEnd == segmentStart ? 2 : segmentEnd - segmentStart,
size.height + _defHeight + 2, size.height + _defHeight!,
), ),
paint, paint,
); );
@@ -98,7 +107,7 @@ class SegmentProgressBar extends CustomPainter {
: (segmentStart - prevStart - textPainter.width) / 2 + : (segmentStart - prevStart - textPainter.width) / 2 +
prevStart + prevStart +
1; 1;
double textY = (-_defHeight - textPainter.height) / 2 - 1; double textY = (-_defHeight! - textPainter.height) / 2;
textPainter.paint(canvas, Offset(textX, textY)); textPainter.paint(canvas, Offset(textX, textY));
} else { } else {
canvas.drawRect( canvas.drawRect(

View File

@@ -110,39 +110,44 @@ class AuthorPanel extends StatelessWidget {
) )
], ],
), ),
// const Spacer(),
// if (source != 'detail' && item.modules?.moduleTag?.text != null)
// Container(
// padding:
// const EdgeInsets.symmetric(horizontal: 4, vertical: 2),
// decoration: BoxDecoration(
// color: Theme.of(context).colorScheme.surface,
// borderRadius: const BorderRadius.all(Radius.circular(4)),
// border: Border.all(
// width: 1.25,
// color: Theme.of(context).colorScheme.primary,
// ),
// ),
// child: Text(
// item.modules.moduleTag.text,
// style: TextStyle(
// height: 1,
// fontSize: 12,
// color: Theme.of(context).colorScheme.primary,
// ),
// strutStyle: const StrutStyle(
// leading: 0,
// height: 1,
// fontSize: 12,
// ),
// ),
// ),
], ],
), ),
), ),
Align( Align(
alignment: Alignment.centerRight, alignment: Alignment.centerRight,
child: item.modules.moduleAuthor.decorate != null child: source != 'detail' && item.modules?.moduleTag?.text != null
? Row(
mainAxisSize: MainAxisSize.min,
children: [
Container(
padding: const EdgeInsets.symmetric(
horizontal: 4, vertical: 2),
decoration: BoxDecoration(
borderRadius:
const BorderRadius.all(Radius.circular(4)),
border: Border.all(
width: 1.25,
color: Theme.of(context).colorScheme.primary,
),
),
child: Text(
item.modules.moduleTag.text,
style: TextStyle(
height: 1,
fontSize: 12,
color: Theme.of(context).colorScheme.primary,
),
strutStyle: const StrutStyle(
leading: 0,
height: 1,
fontSize: 12,
),
),
),
_moreWidget(context),
],
)
: item.modules.moduleAuthor.decorate != null
? Row( ? Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
@@ -166,8 +171,8 @@ class AuthorPanel extends StatelessWidget {
children: [ children: [
CachedNetworkImage( CachedNetworkImage(
height: 32, height: 32,
imageUrl: imageUrl: item
item.modules.moduleAuthor.decorate['card_url'], .modules.moduleAuthor.decorate['card_url'],
), ),
if ((item.modules.moduleAuthor.decorate?['fan'] if ((item.modules.moduleAuthor.decorate?['fan']
?['num_str'] as String?) ?['num_str'] as String?)
@@ -178,10 +183,11 @@ class AuthorPanel extends StatelessWidget {
child: Text( child: Text(
'${item.modules.moduleAuthor.decorate['fan']['num_str']}', '${item.modules.moduleAuthor.decorate['fan']['num_str']}',
style: TextStyle( style: TextStyle(
height: 1,
fontSize: 11, fontSize: 11,
fontFamily: 'digital_id_num', fontFamily: 'digital_id_num',
color: color: (item.modules.moduleAuthor
(item.modules.moduleAuthor.decorate?['fan'] .decorate?['fan']
?['color'] as String?) ?['color'] as String?)
?.startsWith('#') == ?.startsWith('#') ==
true true