Skip to content

Commit

Permalink
fix: correct pixel ratio and layer interaction calculations on smalle…
Browse files Browse the repository at this point in the history
…r screens

Ensure accurate pixel ratio and layer interaction handling in ProImageEditor when rendered in reduced screen areas, addressing [GitHub issue #37](#37).
  • Loading branch information
hm21 committed May 8, 2024
1 parent 5d9e2aa commit ac1f74c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 27 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Changelog

## Version 2.7.5
- **fix**: Corrected pixelRatio and layer interaction calculations in ProImageEditor for smaller screen areas, ensuring accuracy across various device sizes. See [GitHub issue #37](https://github.com/hm21/pro_image_editor/issues/37).

## Version 2.7.4
- **fix**: Migrated all emoji editor theme configurations from `EmojiEditorConfigs` to `EmojiEditorTheme` inside `ImageEditorTheme`, resolving issue #38.
- **fix**: Migrated all emoji editor theme configurations from `EmojiEditorConfigs` to `EmojiEditorTheme` inside `ImageEditorTheme`, resolving [GitHub issue #38](https://github.com/hm21/pro_image_editor/issues/38).

## Version 2.7.3
- **fix**: Correct platform conditional to include web check. Details in [GitHub issue #35](https://github.com/hm21/pro_image_editor/issues/35)
Expand Down
5 changes: 1 addition & 4 deletions example/lib/pages/reorder_layer_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ class _ReorderLayerExampleState extends State<ReorderLayerExample>
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
LayoutBuilder(builder: (context, constraints) {
return _buildEditor();
}),
builder: (context) => _buildEditor(),
),
);
},
Expand Down
5 changes: 1 addition & 4 deletions example/lib/pages/selectable_layer_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ class _SelectableLayerExampleState extends State<SelectableLayerExample>
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
LayoutBuilder(builder: (context, constraints) {
return _buildEditor();
}),
builder: (context) => _buildEditor(),
),
);
},
Expand Down
23 changes: 11 additions & 12 deletions lib/modules/main_editor/main_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ class ProImageEditorState extends State<ProImageEditor>
var w = decodedImage.width;
var h = decodedImage.height;

var widthRatio = w.toDouble() / _screenSize.screen.width;
var widthRatio = w.toDouble() / _screenSize.lastScreenSize.width;
var heightRatio = h.toDouble() / _screenSize.screenInnerHeight;
_pixelRatio = max(heightRatio, widthRatio);

Expand Down Expand Up @@ -967,7 +967,7 @@ class ProImageEditorState extends State<ProImageEditor>
var w = decodedImage.width;
var h = decodedImage.height;

var widthRatio = w.toDouble() / _screenSize.screen.width;
var widthRatio = w.toDouble() / _screenSize.lastScreenSize.width;
var heightRatio = h.toDouble() / _screenSize.screenInnerHeight;
var newPixelRatio = max(heightRatio, widthRatio);

Expand All @@ -981,11 +981,12 @@ class ProImageEditorState extends State<ProImageEditor>

double fitFactor = 1;

bool oldFitWidth =
_screenSize.imageWidth >= _screenSize.screen.width - 0.1 &&
_screenSize.imageWidth <= _screenSize.screen.width + 0.1;
bool newFitWidth = newImgW >= _screenSize.screen.width - 0.1 &&
newImgW <= _screenSize.screen.width + 0.1;
bool oldFitWidth = _screenSize.imageWidth >=
_screenSize.lastScreenSize.width - 0.1 &&
_screenSize.imageWidth <= _screenSize.lastScreenSize.width + 0.1;
bool newFitWidth =
newImgW >= _screenSize.lastScreenSize.width - 0.1 &&
newImgW <= _screenSize.lastScreenSize.width + 0.1;
var scaleX = newFitWidth ? oldFullW / w : oldFullH / h;

if (oldFitWidth != newFitWidth) {
Expand Down Expand Up @@ -1541,10 +1542,7 @@ class ProImageEditorState extends State<ProImageEditor>
_screenSize.screenSizeDebouncer(() {
_decodeImage();
});
_screenSize.lastScreenSize = Size(
constraints.maxWidth,
constraints.maxHeight,
);
_screenSize.lastScreenSize = constraints.biggest;
}
return AnnotatedRegion<SystemUiOverlayStyle>(
value: imageEditorTheme.uiOverlayStyle,
Expand Down Expand Up @@ -1842,7 +1840,8 @@ class ProImageEditorState extends State<ProImageEditor>
scrollDirection: Axis.horizontal,
child: ConstrainedBox(
constraints: BoxConstraints(
minWidth: min(_screenSize.screen.width, 600),
minWidth:
min(_screenSize.lastScreenSize.width, 600),
maxWidth: 600,
),
child: Padding(
Expand Down
11 changes: 6 additions & 5 deletions lib/modules/main_editor/utils/screen_size_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,19 @@ class ScreenSizeHelper {

/// Getter for the screen inner height, excluding top and bottom padding.
double get screenInnerHeight =>
screen.height -
lastScreenSize.height -
screenPadding.top -
screenPadding.bottom -
allToolbarHeight;

/// Getter for the X-coordinate of the middle of the screen.
double get screenMiddleX =>
screen.width / 2 - (screenPadding.left + screenPadding.right) / 2;
lastScreenSize.width / 2 - (screenPadding.left + screenPadding.right) / 2;

/// Getter for the Y-coordinate of the middle of the screen.
double get screenMiddleY =>
screen.height / 2 - (screenPadding.top + screenPadding.bottom) / 2;
lastScreenSize.height / 2 -
(screenPadding.top + screenPadding.bottom) / 2;

/// Returns the total height of all toolbars.
double get allToolbarHeight => appBarHeight + bottomBarHeight;
Expand All @@ -63,12 +64,12 @@ class ScreenSizeHelper {

/// Get the screen padding values.
EdgeInsets get screenPaddingHelper => EdgeInsets.only(
top: (screen.height -
top: (lastScreenSize.height -
screenPadding.top -
screenPadding.bottom -
imageHeight) /
2,
left: (screen.width -
left: (lastScreenSize.width -
screenPadding.left -
screenPadding.right -
imageWidth) /
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: pro_image_editor
description: "A Flutter image editor: Seamlessly enhance your images with user-friendly editing features."
version: 2.7.4
version: 2.7.5
homepage: https://github.com/hm21/pro_image_editor/
repository: https://github.com/hm21/pro_image_editor/
issue_tracker: https://github.com/hm21/pro_image_editor/issues/
Expand Down

0 comments on commit ac1f74c

Please sign in to comment.