Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text style feature #16

Merged
merged 3 commits into from
Mar 1, 2023
Merged
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
6 changes: 4 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -24,8 +24,10 @@ class _MyGaugeExampleState extends State<MyGaugeExample> {
child: LinearGauge(
value: 75.0,
labelStyle: LabelStyle(
fontSize: 10,
color: Colors.red,
textStyle: TextStyle(
color: Colors.red,
fontSize: 10,
),
rulerPosition: RulerPosition.top,
labelOffset: 20),
primaryRulerColor: Colors.red,
36 changes: 2 additions & 34 deletions lib/linear_gauge/linear_gauge.dart
Original file line number Diff line number Diff line change
@@ -26,12 +26,6 @@ class LinearGauge extends LeafRenderObjectWidget {
this.steps = 0,
this.showLinearGaugeContainer = true,
this.gaugeOrientation = GaugeOrientation.horizontal,
this.textStyle = const TextStyle(
fontSize: 12.0,
color: Color.fromARGB(255, 86, 86, 86),
fontStyle: FontStyle.normal,
fontWeight: FontWeight.normal,
),
this.primaryRulersWidth = 1.0,
this.primaryRulersHeight = 15.0,
this.secondaryRulersHeight = 1.0,
@@ -116,28 +110,6 @@ class LinearGauge extends LeafRenderObjectWidget {
///
final GaugeOrientation? gaugeOrientation;

///
/// `textStyle` sets the Label text style of [LinearGauge]
///
/// default is to
/// ```dart
/// const TextStyle(
/// fontSize: 12.0,
/// color: Colors.grey,
/// fontStyle: FontStyle.normal,
/// fontWeight: FontWeight.normal,
/// ),
/// ```
///
/// Example
///
/// ```dart
/// child: const LinearGauge(
/// textStyle: TextStyle(color: Colors.red, fontSize: 16.0),
/// ),
/// ```
final TextStyle? textStyle;

///
///
/// `primaryRulersWidth` set the width of the Rulers which are attached to the labels
@@ -344,7 +316,6 @@ class LinearGauge extends LeafRenderObjectWidget {
steps: steps!,
showLinearGaugeContainer: showLinearGaugeContainer!,
gaugeOrientation: gaugeOrientation!,
textStyle: textStyle!,
primaryRulersWidth: primaryRulersWidth!,
primaryRulersHeight: primaryRulersHeight!,
secondaryRulersHeight: secondaryRulersHeight!,
@@ -357,8 +328,7 @@ class LinearGauge extends LeafRenderObjectWidget {
linearGaugeContainerBgColor: linearGaugeBoxDecoration!.backgroundColor,
linearGaugeContainerValueColor:
linearGaugeBoxDecoration!.linearGaugeValueColor!,
labelSize: labelStyle!.fontSize!,
labelColor: labelStyle!.color!,
textStyle: labelStyle!.textStyle!,
showLabel: labelStyle!.showLabel!,
rulerPosition: labelStyle!.rulerPosition!,
labelOffset: labelStyle!.labelOffset!,
@@ -384,14 +354,12 @@ class LinearGauge extends LeafRenderObjectWidget {
..setShowLinearGaugeContainer = showLinearGaugeContainer!
..setStart = start!
..setSteps = steps!
..setTextStyle = textStyle!
..setTextStyle = labelStyle!.textStyle!
..setSecondaryRulerPerInterval = secondaryRulerPerInterval!
..setLinearGaugeContainerBgColor =
linearGaugeBoxDecoration!.backgroundColor
..setLinearGaugeContainerValueColor =
linearGaugeBoxDecoration!.linearGaugeValueColor!
..setLabelSize = labelStyle!.fontSize!
..setLabelColor = labelStyle!.color!
..setShowLabel = labelStyle!.showLabel!
..setRulerPosition = labelStyle!.rulerPosition!
..setLabelOffset = labelStyle!.labelOffset!
44 changes: 22 additions & 22 deletions lib/linear_gauge/linear_gauge_painter.dart
Original file line number Diff line number Diff line change
@@ -26,8 +26,6 @@ class RenderLinearGauge extends RenderBox {
required double secondaryRulerPerInterval,
required Color linearGaugeContainerBgColor,
required Color linearGaugeContainerValueColor,
required double labelSize,
required Color labelColor,
required bool showLabel,
required RulerPosition rulerPosition,
required double labelOffset,
@@ -52,8 +50,6 @@ class RenderLinearGauge extends RenderBox {
_secondaryRulerPerInterval = secondaryRulerPerInterval,
_linearGaugeContainerBgColor = linearGaugeBoxDecoration.backgroundColor,
_linearGaugeContainerValueColor = linearGaugeContainerValueColor,
_labelSize = labelSize,
_labelColor = labelColor,
_showLabel = showLabel,
_rulerPosition = rulerPosition,
_labelOffset = labelOffset,
@@ -302,22 +298,6 @@ class RenderLinearGauge extends RenderBox {
markNeedsPaint();
}

double get getLabelSize => _labelSize;
double _labelSize;
set setLabelSize(double val) {
if (_labelSize == val) return;
_labelSize = val;
markNeedsPaint();
}

Color get getLabelColor => _labelColor;
Color _labelColor;
set setLabelColor(Color val) {
if (_labelColor == val) return;
_labelColor = val;
markNeedsPaint();
}

bool get showLabel => _showLabel;
bool _showLabel;
set setShowLabel(bool val) {
@@ -417,9 +397,29 @@ class RenderLinearGauge extends RenderBox {
final String labelText = text;
final double? value = double.tryParse(text);
final ui.TextStyle labelTextStyle = ui.TextStyle(
color: _labelColor,
fontSize: _labelSize,
color: getTextStyle.color,
fontSize: getTextStyle.fontSize,
background: getTextStyle.background,
decoration: getTextStyle.decoration,
decorationColor: getTextStyle.decorationColor,
decorationStyle: getTextStyle.decorationStyle,
decorationThickness: getTextStyle.decorationThickness,
fontFamily: getTextStyle.fontFamily,
fontFamilyFallback: getTextStyle.fontFamilyFallback,
fontFeatures: getTextStyle.fontFeatures,
fontStyle: getTextStyle.fontStyle,
fontVariations: getTextStyle.fontVariations,
fontWeight: getTextStyle.fontWeight,
foreground: getTextStyle.foreground,
height: getTextStyle.height,
leadingDistribution: getTextStyle.leadingDistribution,
letterSpacing: getTextStyle.letterSpacing,
locale: getTextStyle.locale,
shadows: getTextStyle.shadows,
textBaseline: getTextStyle.textBaseline,
wordSpacing: getTextStyle.wordSpacing,
);

final ui.ParagraphBuilder paragraphBuilder =
ui.ParagraphBuilder(paragraphStyle)
..pushStyle(labelTextStyle)
43 changes: 32 additions & 11 deletions lib/linear_gauge/styles/linear_gauge_label_style.dart
Original file line number Diff line number Diff line change
@@ -3,22 +3,41 @@ import 'package:geekyants_flutter_gauges/gauges.dart';

class LabelStyle {
const LabelStyle({
this.fontSize = 12.0,
this.color = Colors.black,
this.textStyle = const TextStyle(
fontSize: 12.0,
color: Color.fromARGB(255, 86, 86, 86),
fontStyle: FontStyle.normal,
fontWeight: FontWeight.normal,
),
this.showLabel = true,
this.rulerPosition = RulerPosition.bottom,
this.labelOffset = 0,
});

///
/// Sets the font size of the label
/// default is to 11.0
final double? fontSize;

/// `textStyle` sets the ruler text style of [LinearGauge]
///
/// default is to
/// ```dart
/// const TextStyle(
/// fontSize: 12.0,
/// color: Color.fromARGB(255, 86, 86, 86),
/// fontStyle: FontStyle.normal,
/// fontWeight: FontWeight.normal,
/// ),
/// ```
///
/// Example
///
/// ```dart
/// child: const LinearGauge(
/// labelStyle: LabelStyle(
/// textStyle: TextStyle(color: Colors.red, fontSize: 16.0),
/// )
/// ),
/// ```
///
/// Sets the font color of the label
/// default is to [Colors.black]
final Color? color;
final TextStyle? textStyle;

///
/// Sets the visibility of the label
@@ -34,7 +53,8 @@ class LabelStyle {
/// Example
///
/// ```dart
/// child: const LabelStyle(
/// child: const LinearGauge(
/// labelStyle : LabelStyle(
/// rulerPosition: RulerPosition.bottom,
/// ),
/// ```
@@ -50,7 +70,8 @@ class LabelStyle {
/// Example
///
/// ```dart
/// child: const LabelStyle(
/// child: const LinearGauge(
/// labelStyle : LabelStyle(
/// labelOffset: 10.0,
/// ),
/// ```
16 changes: 8 additions & 8 deletions test/gauges_test.dart
Original file line number Diff line number Diff line change
@@ -11,13 +11,13 @@ void main() {
steps: 0,
showLinearGaugeContainer: true,
gaugeOrientation: GaugeOrientation.horizontal,
textStyle: TextStyle(
fontSize: 12.0,
color: Color.fromARGB(255, 86, 86, 86),
fontStyle: FontStyle.normal,
fontWeight: FontWeight.normal,
),
labelStyle: LabelStyle(
textStyle: TextStyle(
fontSize: 12.0,
color: Color.fromARGB(255, 86, 86, 86),
fontStyle: FontStyle.normal,
fontWeight: FontWeight.normal,
),
rulerPosition: RulerPosition.bottom,
),
primaryRulersWidth: 1.0,
@@ -34,7 +34,7 @@ void main() {
});
group(' Testing', () {
test('RenderLinearGauge test getter and setter', () {
TextStyle textStyel = const TextStyle(
TextStyle textStyle = const TextStyle(
fontSize: 12.0,
color: Color.fromARGB(255, 86, 86, 86),
fontStyle: FontStyle.normal,
@@ -46,7 +46,7 @@ void main() {
expect(linearGauge.steps, 0);
expect(linearGauge.showLinearGaugeContainer, true);
expect(linearGauge.gaugeOrientation, GaugeOrientation.horizontal);
expect(linearGauge.textStyle, textStyel);
expect(linearGauge.labelStyle!.textStyle, textStyle);
expect(linearGauge.primaryRulersWidth, 1.0);
expect(linearGauge.primaryRulersHeight, 15.0);
expect(linearGauge.secondaryRulerColor, Colors.grey);