Skip to content

Commit

Permalink
fix: ProgressRing and ProgressBar now fit correctly the parent bo…
Browse files Browse the repository at this point in the history
…unds (Fixes #942)
  • Loading branch information
bdlukaa committed Oct 18, 2023
1 parent 686c88a commit 023d190
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [next]

* fix: `ProgressRing` and `ProgressBar` now fit correctly the parent bounds ([#942](https://github.com/bdlukaa/fluent_ui/issues/942))

## 4.7.6

* fix: items not aligned centered in `ListTile`. Added `ListTile.contentAlignment` and `ListTile.contentPadding` ([#939](https://github.com/bdlukaa/fluent_ui/issues/939))
Expand Down
5 changes: 4 additions & 1 deletion example/lib/screens/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ class _HomePageState extends State<HomePage> with PageMixin {
child: InfoLabel(
label: 'Progress',
child: const SizedBox(
height: 30, width: 30, child: ProgressRing()),
height: 30,
width: 30,
child: ProgressRing(),
),
),
),
),
Expand Down
17 changes: 14 additions & 3 deletions lib/src/controls/surfaces/progress_indicators.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,13 @@ class _ProgressBarPainter extends CustomPainter {

@override
void paint(Canvas canvas, Size size) {
size = Size(size.width - strokeWidth / 2, size.height - strokeWidth / 2);

void drawLine(Offset xy1, Offset xy2, Color color) {
xy1 += Offset(strokeWidth / 2, 0);
xy1 = xy1.clamp(Offset.zero, Offset(size.width, size.height));
xy2 = xy2.clamp(xy1, Offset(size.width, size.height));

canvas.drawLine(
xy1,
xy2,
Expand Down Expand Up @@ -442,9 +448,14 @@ class _RingPainter extends CustomPainter {

@override
void paint(Canvas canvas, Size size) {
// Since the indicator is drawn as a stroke, the offset and size need to be
// adapted so that the stroke will be drawn inside the paint area.
final offset = Offset(strokeWidth / 2, strokeWidth / 2);
size = Size(size.width - strokeWidth, size.height - strokeWidth);

// Background line
canvas.drawArc(
Offset.zero & size,
offset & size,
_startAngle,
100,
false,
Expand All @@ -460,15 +471,15 @@ class _RingPainter extends CustomPainter {
..style = PaintingStyle.stroke;
if (value == null) {
canvas.drawArc(
Offset.zero & size,
offset & size,
((backwards ? -startAngle : startAngle) - 90) * _deg2Rad,
sweepAngle * _deg2Rad,
false,
paint,
);
} else {
canvas.drawArc(
Offset.zero & size,
offset & size,
_startAngle,
(value! / 100).clamp(0, 1) * _sweep,
false,
Expand Down
12 changes: 11 additions & 1 deletion lib/src/utils.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:math' as math;

import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/foundation.dart';

/// Asserts that the given context has a [FluentTheme] ancestor.
///
Expand Down Expand Up @@ -76,7 +77,7 @@ bool debugCheckHasFluentLocalizations(BuildContext context) {
/// Check if the current screen is 10 foot long or bigger.
///
/// [width] is the width of the current screen. If not provided,
/// [SingletonFlutterWindow.physicalSize] is used
/// [FlutterView.physicalSize] is used
bool is10footScreen(BuildContext context) {
final width = View.of(context).physicalSize.width;
return width >= 11520;
Expand Down Expand Up @@ -154,3 +155,12 @@ extension StringExtension on String {
return first.toLowerCase() + substring(1);
}
}

extension OffsetExtension on Offset {
Offset clamp(Offset min, Offset max) {
return Offset(
clampDouble(dx, min.dx, max.dx),
clampDouble(dy, min.dy, max.dy),
);
}
}

0 comments on commit 023d190

Please sign in to comment.