Skip to content

Commit

Permalink
Feat: spreadFactor to LightConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
AmosHuKe committed Nov 9, 2023
1 parent cd3ab2c commit a56172f
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 71 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

See the [Migration Guide](guides/migration_guide.md) for the details of breaking changes between versions.

## 2.1.0

### New features

- Add spreadFactor to LightConfig

## 2.0.10

### Fixes
Expand Down
1 change: 1 addition & 0 deletions README-ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ Tilt(
| color | `Color` | `Color(0xFFFFFFFF)` | 光照颜色。 |
| minIntensity | `double` | `0.0` | 颜色最小不透明度,也是初始不透明度。 |
| maxIntensity | `double` | `0.5` | 颜色最大不透明度,跟随倾斜最大进度。 |
| spreadFactor | `double` | `4.0` | 光源扩散系数,相对于当前 widget 尺寸。 |
| direction | `LightDirection` | `LightDirection.around` | 光照方向。 <br/> 影响:<br/> `[ShadowConfig.direction]`(配置后不受影响)。 |
| enableReverse | `bool` | `false` | 方向光照方向。 <br/> 影响:<br/> `[ShadowConfig.direction]`(配置后不受影响)。 <br/> `[ShadowConfig.enableReverse]`(配置后不受影响)。 |

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ Tilt(
| color | `Color` | `Color(0xFFFFFFFF)` | Light color. |
| minIntensity | `double` | `0.0` | Color minimum opacity, also initial opacity. |
| maxIntensity | `double` | `0.5` | Color maximum opacity for tilt progresses. |
| spreadFactor | `double` | `4.0` | Light spread factor, relative to current widget size. |
| direction | `LightDirection` | `LightDirection.around` | Light direction. <br/> Affects: <br/> `[ShadowConfig.direction]` (not affected after configuration). |
| enableReverse | `bool` | `false` | Reverse light direction. <br/> Affects: <br/> `[ShadowConfig.direction]` (not affected after configuration). <br/> `[ShadowConfig.enableReverse]` (not affected after configuration). |

Expand Down
15 changes: 13 additions & 2 deletions lib/src/config/tilt_light_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ class LightConfig {
this.color = const Color(0xFFFFFFFF),
this.minIntensity = 0.0,
this.maxIntensity = 0.5,
this.spreadFactor = 4.0,
this.direction = LightDirection.around,
this.enableReverse,
}) : assert(
}) : assert(
minIntensity <= maxIntensity &&
minIntensity >= 0.0 &&
maxIntensity <= 1.0,
);
),
assert(spreadFactor >= 1.0);

/// 禁用
final bool disable;
Expand All @@ -43,6 +45,11 @@ class LightConfig {
/// 为 0 时将没有光源
final double maxIntensity;

/// 光源扩散系数
///
/// 相对当前的尺寸固定扩散
final double spreadFactor;

/// 光源方向
///
/// {@template tilt.LightConfig.direction}
Expand All @@ -69,6 +76,7 @@ class LightConfig {
Color? color,
double? minIntensity,
double? maxIntensity,
double? spreadFactor,
LightDirection? direction,
bool? enableReverse,
}) {
Expand All @@ -77,6 +85,7 @@ class LightConfig {
color: color ?? this.color,
minIntensity: minIntensity ?? this.minIntensity,
maxIntensity: maxIntensity ?? this.maxIntensity,
spreadFactor: spreadFactor ?? this.spreadFactor,
direction: direction ?? this.direction,
enableReverse: enableReverse ?? this.enableReverse,
);
Expand All @@ -95,6 +104,7 @@ class LightConfig {
other.color == color &&
other.minIntensity == minIntensity &&
other.maxIntensity == maxIntensity &&
other.spreadFactor == spreadFactor &&
other.direction == direction &&
other.enableReverse == enableReverse;
}
Expand All @@ -106,6 +116,7 @@ class LightConfig {
color,
minIntensity,
maxIntensity,
spreadFactor,
direction,
enableReverse,
);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/tilt_light.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TiltLight extends StatelessWidget {
Offset get position => progressPosition(width, height, areaProgress);

/// 尺寸扩散的倍数
double get spread => 4.0;
double get spread => lightConfig.spreadFactor;

/// 扩散的尺寸 width
double get spreadW => width * spread;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description: Easily apply tilt parallax hover effects for Flutter, which support
# https://semver.org/spec/v2.0.0-rc.1.html
# https://dart.dev/tools/pub/versioning#semantic-versions
# https://dart.dev/tools/pub/dependencies#version-constraints
version: 2.0.10
version: 2.1.0
homepage: https://amoshuke.github.io/flutter_tilt_book
repository: https://github.com/fluttercandies/flutter_tilt
issue_tracker: https://github.com/fluttercandies/flutter_tilt/issues
Expand Down
29 changes: 29 additions & 0 deletions test/config/tilt_light_config_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,41 @@ import 'package:flutter_tilt/src/config/tilt_light_config.dart';

void main() {
group('LightConfig', () {
test('assert', () {
expect(
() => LightConfig(
minIntensity: 1.0,
maxIntensity: 0.0,
),
throwsAssertionError,
);
expect(
() => LightConfig(
minIntensity: -0.1,
maxIntensity: 1.0,
),
throwsAssertionError,
);
expect(
() => LightConfig(
minIntensity: 0.1,
maxIntensity: 1.1,
),
throwsAssertionError,
);
expect(
() => LightConfig(spreadFactor: 0.1),
throwsAssertionError,
);
});
test('copyWith', () {
const LightConfig lightConfig = LightConfig();
const LightConfig lightConfigExpect = LightConfig(
disable: true,
color: Color(0xFFFFFFF0),
minIntensity: 0.0,
maxIntensity: 0.5,
spreadFactor: 1.0,
direction: LightDirection.around,
enableReverse: true,
);
Expand All @@ -20,6 +48,7 @@ void main() {
color: const Color(0xFFFFFFF0),
minIntensity: 0.0,
maxIntensity: 0.5,
spreadFactor: 1.0,
direction: LightDirection.around,
enableReverse: true,
);
Expand Down
30 changes: 30 additions & 0 deletions test/config/tilt_shadow_config_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,36 @@ import 'package:flutter_tilt/src/config/tilt_shadow_config.dart';

void main() {
group('ShadowConfig', () {
test('assert', () {
expect(
() => ShadowConfig(minIntensity: 1.0, maxIntensity: 0.0),
throwsAssertionError,
);
expect(
() => ShadowConfig(minIntensity: -0.1, maxIntensity: 1.0),
throwsAssertionError,
);
expect(
() => ShadowConfig(minIntensity: 0.1, maxIntensity: 1.1),
throwsAssertionError,
);
expect(
() => ShadowConfig(offsetFactor: -0.1),
throwsAssertionError,
);
expect(
() => ShadowConfig(spreadFactor: -0.1),
throwsAssertionError,
);
expect(
() => ShadowConfig(minBlurRadius: 0.2, maxBlurRadius: 0.1),
throwsAssertionError,
);
expect(
() => ShadowConfig(minBlurRadius: -0.1, maxBlurRadius: 1.0),
throwsAssertionError,
);
});
test('copyWith', () {
const ShadowConfig shadowConfig = ShadowConfig();
const ShadowConfig shadowConfigExpect = ShadowConfig(
Expand Down
30 changes: 0 additions & 30 deletions test/tilt_widget/tilt_config_light_test.dart

This file was deleted.

37 changes: 0 additions & 37 deletions test/tilt_widget/tilt_config_shadow_test.dart

This file was deleted.

0 comments on commit a56172f

Please sign in to comment.