Skip to content

Conversation

@samruddhi-Rahegaonkar
Copy link
Member

@samruddhi-Rahegaonkar samruddhi-Rahegaonkar commented Oct 30, 2025

Fixes #1520

Checklist:

  • No hard coding: I have used resources from constants.dart without hard coding any value.
  • No end of file edits: No modifications done at end of resource files.
  • Code reformatting: I have reformatted code and fixed indentation in every file included in this pull request.
  • Code analyzation: My code passes analyzations run in flutter analyze and tests run in flutter test.

Summary by Sourcery

Map finger movements correctly onto the badge grid by centralizing dimension and offset calculations in BadgeUtils, replacing inline grid conversion logic in pan handlers, and updating the badge aspect ratio; also remove an extraneous line in the CI workflow.

Bug Fixes:

  • Correct finger-to-grid coordinate mapping so drawing follows finger movements accurately
  • Ensure the initial touch point is rendered immediately for freehand drawing

Enhancements:

  • Introduce BadgeUtils to compute badge size, offsets, and cell start coordinates
  • Refactor pan start and update handlers to use the new grid conversion method
  • Define gridWidth and gridHeight constants for badge dimensions
  • Adjust badge aspect ratio from 3.2 to 4.0 to match updated rendering

CI:

  • Remove extraneous blank line from GitHub Actions push workflow

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 30, 2025

Reviewer's Guide

This PR refactors the badge drawing widget to compute grid coordinates dynamically via BadgeUtils (replacing the old static cell-size logic), ensures the first freehand touch point is rendered immediately, updates rendering aspect ratio to 4.0 for the badge, and removes an extraneous line in the CI push workflow.

Sequence diagram for freehand drawing with immediate touch rendering

sequenceDiagram
  participant User as actor User
  participant BMBadge
  participant DrawBadgeProvider

  User->>BMBadge: Touches badge (pan start)
  BMBadge->>DrawBadgeProvider: pushToUndoStack()
  alt Freehand shape selected
    BMBadge->>BMBadge: _localToGrid(dragStart)
    BMBadge->>DrawBadgeProvider: setCell(x, y, isDrawing, preview: false)
  end
  User->>BMBadge: Moves finger (pan update)
  BMBadge->>BMBadge: _localToGrid(localPosition)
  BMBadge->>DrawBadgeProvider: clearPreviewGrid()
  BMBadge->>DrawBadgeProvider: setCell(x, y, isDrawing, preview: false)
Loading

Class diagram for updated BMBadge and BadgeUtils usage

classDiagram
  class BMBadge {
    +void Function(DrawBadgeProvider provider)? providerInit
  }
  class _BMBadgeState {
    -DrawBadgeProvider drawProvider
    -BadgeUtils badgeUtils
    -Offset? dragStart
    +_getBadgeRenderSize(): Size
    +_getLocalPosition(globalPosition: Offset): Offset
    +_localToGrid(localPosition: Offset): (int x, int y)
    +_handlePanStart(details: DragStartDetails)
    +_handlePanUpdate(details: DragUpdateDetails)
    +gridWidth: int
    +gridHeight: int
  }
  class BadgeUtils {
    +getBadgeOffsetBackground(size: Size): MapEntry<double, double>
    +getBadgeSize(offsetHeight: double, offsetWidth: double, size: Size): MapEntry<double, double>
    +getCellStartCoordinate(offsetWidth: double, offsetHeight: double, badgeWidth: double, badgeHeight: double): MapEntry<double, double>
  }
  BMBadge "1" *-- "1" _BMBadgeState
  _BMBadgeState "1" -- "1" BadgeUtils
Loading

File-Level Changes

Change Details Files
Dynamic grid coordinate conversion via BadgeUtils
  • Imported and instantiated BadgeUtils
  • Added gridWidth/gridHeight constants
  • Implemented _getBadgeRenderSize and _localToGrid methods using badgeUtils
  • Updated _getLocalPosition to handle null render boxes safely
lib/virtualbadge/view/draw_badge.dart
Immediate rendering of initial freehand touch
  • Push undo state at pan start
  • On freehand start, compute grid pos and set cell without preview
lib/virtualbadge/view/draw_badge.dart
Badge rendering aspect ratio adjustment
  • Changed AspectRatio from 3.2 to 4.0
  • Updated CustomPaint size to match new aspect ratio
lib/virtualbadge/view/draw_badge.dart
CI workflow cleanup
  • Removed extra blank line at end of push.yml
.github/workflows/push.yml

Assessment against linked issues

Issue Objective Addressed Explanation
#1520 Ensure the Draw Clipart feature follows finger movements accurately when drawing.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `lib/virtualbadge/view/draw_badge.dart:79-80` </location>
<code_context>
+    double relativeX = localPosition.dx - cellStartX;
+    double relativeY = localPosition.dy - cellStartY;
+
+    int col = (relativeX / (cellSize * 0.93)).floor().clamp(0, gridWidth - 1);
+    int row = (relativeY / cellSize).floor().clamp(0, gridHeight - 1);
+
+    return (x: row, y: col);
</code_context>

<issue_to_address>
**suggestion:** The horizontal compression factor (0.93) is hardcoded; consider centralizing or documenting its origin.

Defining the compression factor as a constant or sourcing it from a shared configuration will improve maintainability and prevent inconsistencies if the value changes or is reused.

Suggested implementation:

```
    // Convert touch position to grid coordinates
    // Accounting for the horizontal compression factor used in rendering
    const double _horizontalCompressionFactor = 0.93;
    double relativeX = localPosition.dx - cellStartX;
    double relativeY = localPosition.dy - cellStartY;

    int col = (relativeX / (cellSize * _horizontalCompressionFactor)).floor().clamp(0, gridWidth - 1);
    int row = (relativeY / cellSize).floor().clamp(0, gridHeight - 1);

    return (x: row, y: col);

```

If this code is inside a class, consider moving the constant definition (`const double _horizontalCompressionFactor = 0.93;`) to the top of the class for better visibility and reuse. If the compression factor is used in multiple files, you may want to define it in a shared configuration or constants file and import it where needed.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@samruddhi-Rahegaonkar
Copy link
Member Author

@mariobehling @hpdang Corrected finger-to-grid coordinate mapping so drawing follows finger movements accurately.

@github-actions
Copy link
Contributor

Build Status

Build successful. APKs to test: https://github.com/fossasia/badgemagic-app/actions/runs/18929357777/artifacts/4413444683.

Screenshots

Android Screenshots
iPhone Screenshots
iPad Screenshots

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The Draw Clipart feature does not respond correctly to finger movements.

1 participant