Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## [0.1.1]
* Capacity Indicator now works as expected ([#49](https://github.com/GroovinChip/macos_ui/issues/49))
* Clear button is now aligned to text ([#82](https://github.com/GroovinChip/macos_ui/issues/82))

## [0.1.0]
Expand Down
5 changes: 4 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ class _DemoState extends State<Demo> {
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: TextField(
prefix: Padding(
padding: const EdgeInsets.symmetric(horizontal: 4.0, vertical: 2.0),
padding: const EdgeInsets.symmetric(
horizontal: 4.0,
vertical: 2.0,
),
child: Icon(CupertinoIcons.search),
),
placeholder: 'Type some text here',
Expand Down
5 changes: 4 additions & 1 deletion lib/src/fields/text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,10 @@ class _TextFieldState extends State<TextField>
}
: null,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 6.0, vertical: 4.0),
padding: const EdgeInsets.symmetric(
horizontal: 6.0,
vertical: 4.0,
),
child: Icon(
CupertinoIcons.clear_thick_circled,
size: 18.0,
Expand Down
91 changes: 51 additions & 40 deletions lib/src/indicators/capacity_indicators.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,9 @@ class CapacityIndicator extends StatelessWidget {
properties.add(StringProperty('semanticLabel', semanticLabel));
}

void _handleUpdate(Offset lp) {
double value = discrete ? lp.dx / splits : lp.dx;
if (value.isNegative)
value = 0;
else if (value > 100) value = 100;
onChanged?.call(value);
void _handleUpdate(Offset lp, double width) {
double value = (lp.dx / width) * splits;
onChanged?.call(value.clamp(0.0, 100.0));
}

@override
Expand All @@ -106,45 +103,59 @@ class CapacityIndicator extends StatelessWidget {
value: value.toStringAsFixed(2),
child: Container(
constraints: BoxConstraints(minWidth: _kCapacityIndicatorMinWidth),
child: GestureDetector(
onPanStart: (event) => _handleUpdate(event.localPosition),
onPanUpdate: (event) => _handleUpdate(event.localPosition),
onPanDown: (event) => _handleUpdate(event.localPosition),
child: discrete
? LayoutBuilder(builder: (context, consts) {
double width = consts.biggest.width;
if (width.isInfinite) width = 100;
final splitWidth = width / splits;
final fillToIndex = (100 - -(value - 100)) * (splits / 10);
return SizedBox(
width: width,
child: Row(
children: List.generate(splits, (index) {
return Container(
padding: EdgeInsets.only(
right: index == splits - 1 ? 0 : 2.0,
),
width: splitWidth,
child: CapacityIndicatorCell(
value: value > 0 && fillToIndex / 10 >= index
? 100
: 0,
backgroundColor: backgroundColor,
borderColor: borderColor,
color: color,
),
);
}),
),
);
})
: CapacityIndicatorCell(
child: LayoutBuilder(builder: (context, consts) {
double width = consts.maxWidth;
if (width.isInfinite) width = 100;
final splitWidth = width / splits;
if (discrete) {
final fillToIndex = value / splits - 1;
return SizedBox(
width: width,
child: GestureDetector(
onPanStart: (event) =>
_handleUpdate(event.localPosition, splitWidth),
onPanUpdate: (event) =>
_handleUpdate(event.localPosition, splitWidth),
onPanDown: (event) =>
_handleUpdate(event.localPosition, splitWidth),
child: Row(
children: List.generate(splits, (index) {
return Container(
padding: EdgeInsets.only(
right: index == splits - 1 ? 0 : 2.0,
),
width: splitWidth,
child: CapacityIndicatorCell(
value: value > 0 && fillToIndex >= index ? 100 : 0,
backgroundColor: backgroundColor,
borderColor: borderColor,
color: color,
),
);
}),
),
),
);
} else {
return SizedBox(
width: width,
child: GestureDetector(
onPanStart: (event) =>
_handleUpdate(event.localPosition, splitWidth),
onPanUpdate: (event) =>
_handleUpdate(event.localPosition, splitWidth),
onPanDown: (event) =>
_handleUpdate(event.localPosition, splitWidth),
child: CapacityIndicatorCell(
value: value,
backgroundColor: backgroundColor,
borderColor: borderColor,
color: color,
),
),
),
);
}
}),
),
);
}
Expand Down