UI fixes and league

This commit is contained in:
Jan Pleterski
2026-11-28 12:22:02 +01:00
parent 2fc741a9f6
commit 258303deb8
118 changed files with 1439 additions and 537 deletions
+19 -6
View File
@@ -39,6 +39,16 @@ class BarList extends StatelessWidget {
String tick(double v) => v == v.roundToDouble() ? '${v.round()}' : v.toStringAsFixed(1);
return LayoutBuilder(builder: (context, box) {
final barWidth = box.maxWidth - labelWidth - valueWidth;
// 26 high, thinner when many rows share little height (e.g. 10 … 0)
final ticksHeight = ticks.isEmpty ? 0.0 : 20 * scale;
final rowHeight = entries.isEmpty || !box.hasBoundedHeight
? double.infinity
: (box.maxHeight - ticksHeight) / entries.length;
final barHeight = (rowHeight * 0.75).clamp(4.0, 26 * scale);
// Text shrinks with thin rows too, so many bars (a session of 20
// targets) don't run their labels and values into each other
final labelSize = (rowHeight * 0.78).clamp(6.0, 12 * scale);
final valueSize = (rowHeight * 0.85).clamp(6.0, 15 * scale);
return Column(
children: [
Expanded(
@@ -51,8 +61,10 @@ class BarList extends StatelessWidget {
SizedBox(
width: labelWidth,
child: Text(e.label,
maxLines: 1,
style: TextStyle(
fontSize: 12 * scale,
fontSize: labelSize,
height: 1,
fontWeight: FontWeight.w600,
color: e.goldLabel ? c.gold : c.muted)),
),
@@ -62,16 +74,16 @@ class BarList extends StatelessWidget {
alignment: Alignment.centerLeft,
children: [
Container(
height: 26 * scale,
decoration: BoxDecoration(color: c.tile, borderRadius: BorderRadius.circular(7 * scale)),
height: barHeight,
decoration: BoxDecoration(color: c.tile, borderRadius: BorderRadius.circular(barHeight * 0.27)),
),
FractionallySizedBox(
widthFactor: max <= 0 ? 0 : (e.value / max).clamp(0.0, 1.0),
child: Container(
height: 26 * scale,
height: barHeight,
decoration: BoxDecoration(
color: e.highlight ? c.gold : c.accent,
borderRadius: BorderRadius.circular(7 * scale),
borderRadius: BorderRadius.circular(barHeight * 0.27),
),
),
),
@@ -85,7 +97,8 @@ class BarList extends StatelessWidget {
child: Text(e.valueText,
maxLines: 1,
style: TextStyle(
fontSize: 15 * scale,
fontSize: valueSize,
height: 1,
fontWeight: FontWeight.w700,
color: e.highlight ? c.gold : (e.value == 0 ? c.faint : c.ink),
fontFeatures: AppTheme.tnum)),
+4 -4
View File
@@ -200,7 +200,7 @@ class _ChartPainter extends CustomPainter {
// Gridlines + y labels in each axis series' colour
final grid = Paint()
..color = gridColor
..strokeWidth = 1;
..strokeWidth = 0.6;
for (final f in [0.0, 0.5, 1.0]) {
final y = plot.bottom - plot.height * f;
canvas.drawLine(Offset(axis, y), Offset(size.width - axis, y), grid);
@@ -232,7 +232,7 @@ class _ChartPainter extends CustomPainter {
path,
Paint()
..color = s.color
..strokeWidth = 2
..strokeWidth = 1.2
..style = PaintingStyle.stroke
..strokeJoin = StrokeJoin.round,
);
@@ -240,8 +240,8 @@ class _ChartPainter extends CustomPainter {
for (int i = 0; i < n; i++) {
final isSel = i == selected;
final p = Offset(xAt(i), yAt(s.values[i], r));
canvas.drawCircle(p, isSel ? 6 : 4.5, Paint()..color = surfaceColor);
canvas.drawCircle(p, isSel ? 4.5 : 3.5, Paint()..color = s.color);
canvas.drawCircle(p, isSel ? 5 : 2.8, Paint()..color = surfaceColor);
canvas.drawCircle(p, isSel ? 3.8 : 2, Paint()..color = s.color);
}
}
+9 -11
View File
@@ -163,19 +163,17 @@ class ResultShareCard extends StatelessWidget {
),
),
const SizedBox(height: 10),
Row(
TileRow(
gap: data.tiles.length > 6 ? 3 : 6,
children: [
for (int i = 0; i < data.tiles.length; i++) ...[
if (i > 0) const SizedBox(width: 6),
Expanded(
child: ScoreTile(
top: data.tiles[i].$1,
value: data.tiles[i].$2,
filled: data.tiles[i].$3,
height: 60,
),
for (final (top, value, filled) in data.tiles)
ScoreTile(
top: top,
value: value,
filled: filled,
height: 60,
radius: data.tiles.length > 6 ? 9 : 14,
),
],
],
),
],
+79 -47
View File
@@ -3,10 +3,13 @@ import '../models/target_style.dart';
import '../utils/target_scoring.dart';
/// A target design with hits on it, drawn in the shared 1200 × 1200 space and
/// scaled to the space it gets (always square).
/// scaled to the space it gets (always square). The designs are transparent
/// outside the target; a miss is drawn where it landed, on the screen
/// background. The small previews ([zoomToHits]) show the target only,
/// without the misses.
///
/// The default target is painted as vectors, so its rings and numbers stay
/// sharp at any size or zoom; the other designs are their v3 images.
/// sharp at any size or zoom; the other designs are their v5 images.
class TargetFace extends StatelessWidget {
final TargetStyle style;
final List<Offset> hits; // in target space (0–1200)
@@ -14,6 +17,7 @@ class TargetFace extends StatelessWidget {
final Set<int> highlighted; // indexes of [hits] drawn with a ring
final Set<int> dimmed; // indexes drawn faded (e.g. other values while one is pressed)
final bool showScoring; // debug: the radii the scoring uses, over the design
final bool zoomToHits; // small previews: the target only, zoomed in on the shots
const TargetFace({
super.key,
@@ -23,18 +27,38 @@ class TargetFace extends StatelessWidget {
this.highlighted = const {},
this.dimmed = const {},
this.showScoring = false,
this.zoomToHits = false,
});
/// How far [zoomToHits] zooms: just enough, round the centre, to keep every
/// shot (and a little air) in view; never past 3× and never so far that the
/// black and ring 6 are cut, so there is always something to read them by.
static double zoomFor(List<Offset> hits) {
if (hits.isEmpty) return 1;
var r = 0.0;
for (final h in hits) {
final d = (TargetScoring.shown(h) - TargetScoring.center).distance;
if (d > r) r = d;
}
final view = (r + TargetScoring.bulletDiameter / 2 + 30).clamp(260.0, TargetScoring.size / 2);
return (TargetScoring.size / 2 / view).clamp(1.0, 3.0);
}
@override
Widget build(BuildContext context) {
final asset = style.asset;
return AspectRatio(
// Small previews: the target only, so misses are left out
final hits = zoomToHits ? [for (final h in this.hits) if (TargetScoring.scoreAt(h) > 0) h] : this.hits;
final zoom = zoomToHits ? zoomFor(hits) : 1.0;
final face = AspectRatio(
aspectRatio: 1,
child: Stack(
fit: StackFit.expand,
children: [
if (asset == null)
const RepaintBoundary(child: CustomPaint(painter: DefaultTargetPainter(glow: true)))
const RepaintBoundary(child: CustomPaint(painter: DefaultTargetPainter()))
else
Image.asset(asset, fit: BoxFit.contain, filterQuality: FilterQuality.medium, gaplessPlayback: true),
if (showScoring) const CustomPaint(painter: ScoringRingsPainter()),
@@ -45,9 +69,28 @@ class TargetFace extends StatelessWidget {
],
),
);
if (zoom == 1) return face;
return AspectRatio(
aspectRatio: 1,
child: LayoutBuilder(
builder: (context, box) => ClipRRect(
borderRadius: BorderRadius.circular(box.biggest.shortestSide * 0.1),
child: Transform.scale(scale: zoom, child: face),
),
),
);
}
}
/// Maps the shared target space into a square of [size], centred; returns
/// the scale (screen px per target unit).
double toFaceSpace(Canvas canvas, Size size) {
final s = size.shortestSide / TargetScoring.size;
canvas.translate((size.width - size.shortestSide) / 2, (size.height - size.shortestSide) / 2);
canvas.scale(s);
return s;
}
/// Small preview of a design, for the pickers and the settings row.
class TargetThumb extends StatelessWidget {
final TargetStyle style;
@@ -61,7 +104,7 @@ class TargetThumb extends StatelessWidget {
return SizedBox.square(
dimension: size,
child: asset == null
? CustomPaint(painter: DefaultTargetPainter(glow: true, numbers: size >= 60))
? CustomPaint(painter: DefaultTargetPainter(numbers: size >= 60))
: Image.asset(
asset,
fit: BoxFit.contain,
@@ -72,52 +115,44 @@ class TargetThumb extends StatelessWidget {
}
}
/// The default target ("00 Privzeta · brez sijaja") in vectors: white paper
/// ending on ring 1, black 7–10, numbers 1–8 on the four axes. [glow] adds a
/// small glow (white rim, short light-blue halo).
/// The default target ("00 Privzeta", target-designs/v5) in vectors: white
/// paper ending on ring 1, black 7–10, numbers 1–8 on the four axes, no glow.
class DefaultTargetPainter extends CustomPainter {
final bool glow;
final bool numbers;
const DefaultTargetPainter({this.glow = false, this.numbers = true});
const DefaultTargetPainter({this.numbers = true});
static const double _paper = 510;
static const Color _glowOuter = Color(0xFF9FD8FF);
// Outer radius of score zone k (1–9); zone 10 is the centre dot
static double ring(int k) => k == 10 ? 15 : 15 + 55 * (10 - k).toDouble();
@override
void paint(Canvas canvas, Size size) {
final s = size.shortestSide / TargetScoring.size;
canvas.save();
canvas.translate((size.width - size.shortestSide) / 2, (size.height - size.shortestSide) / 2);
canvas.scale(s);
toFaceSpace(canvas, size);
const c = TargetScoring.center;
if (glow) {
// figcraft drop-shadow "radius" is the blur; Flutter wants sigma ≈ blur / 2
void blurDisc(double r, Color color, double blur) => canvas.drawCircle(
c, r, Paint()..color = color..maskFilter = MaskFilter.blur(BlurStyle.normal, blur / 2));
// A small glow: a short light-blue halo and a white rim
blurDisc(_paper + 2, _glowOuter.withValues(alpha: 0.55), 40);
blurDisc(_paper + 1, Colors.white.withValues(alpha: 0.7), 10);
}
// Paper, then the black (zones 7–10)
canvas.drawCircle(c, _paper, Paint()..color = Colors.white);
canvas.drawCircle(c, ring(7), Paint()..color = Colors.black);
final line = Paint()
..style = PaintingStyle.stroke
..isAntiAlias = true;
// Ring lines are filled discs painted from the outside in (line colour out
// to r + w/2, then the zone colour from r − w/2), not stroked circles:
// Impeller draws thin stroked circles unevenly, some rings thinner than
// the rest
final black = Paint()..color = Colors.black;
final white = Paint()..color = Colors.white;
const paperLine = 2.0;
const blackLine = 3.0;
// Paper with lines 1–6 (ring 1 is its edge)
for (int k = 1; k <= 6; k++) {
canvas.drawCircle(c, ring(k), line..color = Colors.black..strokeWidth = 3);
canvas.drawCircle(c, ring(k) + paperLine / 2, black);
canvas.drawCircle(c, ring(k) - paperLine / 2, white);
}
// The black (zones 7–10) with white lines 8 and 9
canvas.drawCircle(c, ring(7), black);
for (final k in [8, 9]) {
canvas.drawCircle(c, ring(k), line..color = Colors.white..strokeWidth = 5);
canvas.drawCircle(c, ring(k) + blackLine / 2, white);
canvas.drawCircle(c, ring(k) - blackLine / 2, black);
}
canvas.drawCircle(c, ring(10), Paint()..color = Colors.white);
canvas.drawCircle(c, ring(10), white);
if (numbers) {
for (int k = 1; k <= 8; k++) {
@@ -146,7 +181,7 @@ class DefaultTargetPainter extends CustomPainter {
}
@override
bool shouldRepaint(DefaultTargetPainter old) => old.glow != glow || old.numbers != numbers;
bool shouldRepaint(DefaultTargetPainter old) => old.numbers != numbers;
}
/// Hits in target space: a filled dot of [TargetScoring.bulletDiameter] with a
@@ -164,10 +199,8 @@ class HitsPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final s = size.shortestSide / TargetScoring.size;
canvas.save();
canvas.translate((size.width - size.shortestSide) / 2, (size.height - size.shortestSide) / 2);
canvas.scale(s);
toFaceSpace(canvas, size);
const r = TargetScoring.bulletDiameter / 2;
final rim = Color.lerp(color, Colors.black, 0.6)!;
@@ -179,21 +212,22 @@ class HitsPainter extends CustomPainter {
if (highlighted.contains(i)) i,
];
for (final i in order) {
final p = hits[i];
final p = TargetScoring.shown(hits[i]); // a shot far off is kept in the square
final selected = highlighted.contains(i);
final faded = dimmed.contains(i);
// Semi-transparent, so overlapping hits and the rings under them show through
canvas.drawCircle(p + const Offset(0, 2), r,
Paint()..color = Colors.black.withValues(alpha: faded ? 0.05 : 0.18)..maskFilter = const MaskFilter.blur(BlurStyle.normal, 3));
canvas.drawCircle(p, r, Paint()..color = color.withValues(alpha: faded ? 0.25 : (selected ? 0.9 : 0.78)));
Paint()..color = Colors.black.withValues(alpha: faded ? 0.03 : (selected ? 0.35 : 0.18))..maskFilter = const MaskFilter.blur(BlurStyle.normal, 3));
// Faded ones barely show; highlighted ones are solid
canvas.drawCircle(p, r, Paint()..color = color.withValues(alpha: faded ? 0.18 : (selected ? 1.0 : 0.78)));
canvas.drawCircle(
p,
r - 1.5,
r - 0.75,
Paint()
..style = PaintingStyle.stroke
..strokeWidth = 3
..color = rim.withValues(alpha: faded ? 0.2 : 0.8));
// Selected: a red border on the hit's own edge, nothing around it
..strokeWidth = 1.5
..color = rim.withValues(alpha: faded ? 0.12 : 0.8));
// Selected: a thick red border on the hit's own edge, nothing around it
if (selected) {
canvas.drawCircle(
p,
@@ -220,10 +254,8 @@ class ScoringRingsPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final s = size.shortestSide / TargetScoring.size;
canvas.save();
canvas.translate((size.width - size.shortestSide) / 2, (size.height - size.shortestSide) / 2);
canvas.scale(s);
final s = toFaceSpace(canvas, size);
const c = TargetScoring.center;
final line = Paint()
..style = PaintingStyle.stroke
+155 -51
View File
@@ -176,13 +176,19 @@ class SegmentItem {
const SegmentItem(this.label, [this.icon]);
}
/// Two or three equal segments in a card ("Statistika | Zgodovina").
/// Two or three equal segments in a card ("Statistika | Zgodovina"). The
/// selected pill hops over to a newly picked segment (a slide with a slight
/// overshoot). [trailing] sits at the end of the same bar, after a thin line
/// (e.g. a menu); [bare] leaves out the bar's own card, for several rows in
/// one card (see [SegmentedCard]).
class SegmentedTabs extends StatelessWidget {
final List<SegmentItem> items;
final int selected;
final ValueChanged<int> onSelect;
final double height;
final bool accentSelected; // selected segment filled with the accent
final Widget? trailing;
final bool bare;
const SegmentedTabs({
super.key,
@@ -191,62 +197,125 @@ class SegmentedTabs extends StatelessWidget {
required this.onSelect,
this.height = 44,
this.accentSelected = false,
this.trailing,
this.bare = false,
});
static const Duration _hop = Duration(milliseconds: 380);
// Slides past its target a little and settles back: a hop, not a fade
static const Curve _hopCurve = Cubic(0.3, 1.3, 0.5, 1);
static BoxDecoration track(Palette c) => BoxDecoration(
color: c.isDark ? c.card : c.tile,
borderRadius: BorderRadius.circular(14),
border: c.isDark ? Border.all(color: c.line) : null,
);
@override
Widget build(BuildContext context) {
final c = Palette.current;
final segments = LayoutBuilder(builder: (context, box) {
final w = box.maxWidth / items.length;
return Stack(
children: [
// The pill, under the labels
if (selected >= 0 && selected < items.length)
AnimatedPositioned(
duration: _hop,
curve: _hopCurve,
left: w * selected,
top: 0,
bottom: 0,
width: w,
child: AnimatedContainer(
duration: const Duration(milliseconds: 180),
decoration: BoxDecoration(
color: accentSelected ? c.accent : (c.isDark ? c.tile : c.card),
borderRadius: BorderRadius.circular(10),
boxShadow: !c.isDark ? c.shadow : null,
),
),
),
Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
for (int i = 0; i < items.length; i++)
Expanded(
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => onSelect(i),
child: TweenAnimationBuilder<Color?>(
tween: ColorTween(end: _fg(c, i)),
duration: const Duration(milliseconds: 220),
builder: (context, fg, _) => Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (items[i].icon != null) ...[
Icon(items[i].icon, size: 16, color: fg),
const SizedBox(width: 8),
],
Flexible(
child: Text(
items[i].label,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: fg),
),
),
],
),
),
),
),
],
),
],
);
});
final bar = trailing == null
? segments
: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(child: segments),
Container(width: 1, margin: const EdgeInsets.symmetric(horizontal: 4, vertical: 6), color: c.isDark ? c.line : c.line2),
trailing!,
],
);
return Container(
height: height,
padding: bare ? EdgeInsets.zero : const EdgeInsets.all(4),
decoration: bare ? null : track(c),
child: bar,
);
}
Color _fg(Palette c, int i) => i != selected ? c.muted : (accentSelected ? c.onAccent : c.ink);
}
/// Several [SegmentedTabs] rows (built [bare]) in one card, a thin line
/// between them: "Statistika | Zgodovina" over its filters.
class SegmentedCard extends StatelessWidget {
final List<Widget> rows;
const SegmentedCard({super.key, required this.rows});
@override
Widget build(BuildContext context) {
final c = Palette.current;
return Container(
height: height,
padding: const EdgeInsets.all(4),
decoration: BoxDecoration(
color: c.isDark ? c.card : c.tile,
borderRadius: BorderRadius.circular(14),
border: c.isDark ? Border.all(color: c.line) : null,
),
child: Row(
// The selected pill fills the bar's height
crossAxisAlignment: CrossAxisAlignment.stretch,
decoration: SegmentedTabs.track(c),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
for (int i = 0; i < items.length; i++)
Expanded(
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => onSelect(i),
child: AnimatedContainer(
duration: const Duration(milliseconds: 180),
curve: Curves.easeOut,
decoration: BoxDecoration(
color: i == selected ? (accentSelected ? c.accent : (c.isDark ? c.tile : c.card)) : Colors.transparent,
borderRadius: BorderRadius.circular(10),
boxShadow: i == selected && !c.isDark ? c.shadow : null,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (items[i].icon != null) ...[
Icon(items[i].icon, size: 16, color: _fg(c, i)),
const SizedBox(width: 8),
],
Flexible(
child: Text(
items[i].label,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: _fg(c, i)),
),
),
],
),
),
),
),
for (int i = 0; i < rows.length; i++) ...[
if (i > 0) Container(height: 1, margin: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), color: c.isDark ? c.line : c.line2),
rows[i],
],
],
),
);
}
Color _fg(Palette c, int i) => i != selected ? c.muted : (accentSelected ? c.onAccent : c.ink);
}
/// Stadium chip: accent when selected ("Treningi", "Vse").
@@ -304,6 +373,7 @@ class AppCard extends StatelessWidget {
final double radius;
final Color? color;
final Color? borderColor;
final double borderWidth;
final bool dashed;
const AppCard({
@@ -315,6 +385,7 @@ class AppCard extends StatelessWidget {
this.radius = AppTheme.radius,
this.color,
this.borderColor,
this.borderWidth = 1,
this.dashed = false,
});
@@ -323,7 +394,7 @@ class AppCard extends StatelessWidget {
final c = Palette.current;
final shape = RoundedRectangleBorder(
borderRadius: BorderRadius.circular(radius),
side: dashed ? BorderSide.none : BorderSide(color: borderColor ?? (c.isDark ? c.line2 : c.line2)),
side: dashed ? BorderSide.none : BorderSide(color: borderColor ?? (c.isDark ? c.line2 : c.line2), width: borderWidth),
);
Widget content = Padding(padding: padding, child: child);
if (onTap != null || onLongPress != null) {
@@ -447,7 +518,8 @@ class SoftButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
final c = Palette.current;
final fg = destructive ? c.red : c.ink;
// Without an action it is visibly off, so it never looks like it does nothing
final fg = (destructive ? c.red : c.ink).withValues(alpha: onTap == null ? 0.35 : 1);
return Material(
color: destructive ? c.redSoft : c.tile,
borderRadius: BorderRadius.circular(12),
@@ -486,6 +558,7 @@ class ScoreTile extends StatelessWidget {
final GestureTapDownCallback? onTapDown;
final VoidCallback? onTapEnd;
final bool outlined;
final double radius;
const ScoreTile({
super.key,
@@ -498,6 +571,7 @@ class ScoreTile extends StatelessWidget {
this.onTapDown,
this.onTapEnd,
this.outlined = false,
this.radius = 14,
});
@override
@@ -515,16 +589,19 @@ class ScoreTile extends StatelessWidget {
height: height,
decoration: BoxDecoration(
color: fill,
borderRadius: BorderRadius.circular(14),
borderRadius: BorderRadius.circular(radius),
border: outlined ? Border.all(color: c.ink, width: 2) : null,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (top != null)
Text(top!,
style: TextStyle(
fontSize: 10, fontWeight: FontWeight.w600, color: fg.withValues(alpha: 0.7), fontFeatures: AppTheme.tnum)),
FittedBox(
fit: BoxFit.scaleDown,
child: Text(top!,
style: TextStyle(
fontSize: 10, fontWeight: FontWeight.w600, color: fg.withValues(alpha: 0.7), fontFeatures: AppTheme.tnum)),
),
FittedBox(
fit: BoxFit.scaleDown,
child: Text(value,
@@ -538,6 +615,33 @@ class ScoreTile extends StatelessWidget {
}
}
/// A centred row of equal tiles. Each is as wide as if there were at least
/// [minSlots], so one or two tiles don't stretch across the whole width.
class TileRow extends StatelessWidget {
final List<Widget> children;
final double gap;
final int minSlots;
const TileRow({super.key, required this.children, this.gap = 10, this.minSlots = 6});
@override
Widget build(BuildContext context) {
return LayoutBuilder(builder: (context, box) {
final slots = children.length < minSlots ? minSlots : children.length;
final w = (box.maxWidth - gap * (slots - 1)) / slots;
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
for (int i = 0; i < children.length; i++) ...[
if (i > 0) SizedBox(width: gap),
SizedBox(width: w, child: children[i]),
],
],
);
});
}
}
/// Small coloured label: "TRENING", "TEKMOVANJE", "V ŽIVO".
class StatusChip extends StatelessWidget {
final String label;