Skip to content

Conversation

samruddhi-Rahegaonkar
Copy link
Member

@samruddhi-Rahegaonkar samruddhi-Rahegaonkar commented Jul 18, 2025

Fixes #1374

Changes

  • Added Options for shapes in draw clipart

Screenshots / Recordings

WhatsApp.Video.2025-07-18.at.18.51.27.mp4

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

Enable drawing of predefined shapes in the clipart drawing screen by adding a shapes toggle and selection panel, implement shape-based drawing algorithms in the badge view, and refactor UI and provider logic to support the new modes.

New Features:

  • Introduce shape drawing modes (freehand, square, rectangle, circle, triangle) in the clipart tool
  • Add a Shapes toggle and horizontal option panel in the draw toolbar for selecting drawing shapes
  • Implement gesture handlers to draw selected shapes onto the LED badge grid

Enhancements:

  • Refactor draw badge UI by modularizing toolbar buttons and updating layout structure
  • Add DrawShape enum and extend provider to manage selected shape and drawing state
  • Replace custom badge utility positioning with consistent cell sizing and remove unused BadgeUtils dependency
  • After saving clipart, automatically navigate back to the home screen

Copy link
Contributor

sourcery-ai bot commented Jul 18, 2025

Reviewer's Guide

This PR adds predefined shape support to the draw clipart feature by refactoring the draw badge screen layout to include a scrollable shape selector, modularizing button builders, unifying gesture handling in BMBadge for freehand and shape drawing, and extending the DrawBadgeProvider to manage selected shapes and rendering logic.

Class diagram for updated BMBadge gesture handling

classDiagram
    class BMBadge {
      + void _handlePanStart(DragStartDetails details)
      + void _handlePanUpdate(DragUpdateDetails details)
      + void _handlePanEnd(DragEndDetails details)
      + void _drawLine(int r1, int c1, int r2, int c2)
      + void _drawSquare(int row, int col, int radius, bool state)
      + void _drawRectangle(int row, int col, int halfWidth, int halfHeight, bool state)
      + void _drawCircle(int row, int col, int radius, bool state)
      + void _drawTriangle(int row, int col, int height, bool state)
      + void _safeSet(int row, int col, bool value)
    }
    BMBadge --> DrawBadgeProvider
Loading

Class diagram for updated DrawBadge UI structure

classDiagram
    class DrawBadge {
      + Widget _buildDrawEraseButton(bool isDraw, IconData icon, String label)
      + Widget _buildResetButton()
      + Widget _buildSaveButton(FileHelper fileHelper)
      + Widget _buildShapesToggleButton()
      + Widget _buildShapeCard(BuildContext context, DrawShape shape, IconData icon, String label)
    }
    DrawBadge --> DrawBadgeProvider
    DrawBadge --> BMBadge
    DrawBadge --> DrawShape
Loading

File-Level Changes

Change Details Files
Refactor draw badge UI and integrate shape selector toolbar
  • Switch to LayoutBuilder with ConstrainedBox and IntrinsicHeight for responsive layout
  • Modularize action buttons via _buildDrawEraseButton, _buildResetButton, _buildSaveButton
  • Add _showShapeOptions toggle and _buildShapesToggleButton to show/hide shape toolbar
  • Introduce horizontal scrollable row of shape selector cards with _buildShapeCard
lib/view/draw_badge_screen.dart
Simplify gesture handling and implement shape drawing in BMBadge
  • Replace BadgeUtils with direct cellSize calculation based on screen width
  • Unify pan start/update/end to track dragStart and compute grid coordinates
  • Implement Bresenham line algorithm for freehand and add _drawSquare, _drawRectangle, _drawCircle, _drawTriangle with _safeSet boundary checks
lib/virtualbadge/view/draw_badge.dart
Extend DrawBadgeProvider with shape management and clean up
  • Introduce DrawShape enum and _selectedShape state with setter/getter
  • Refactor setDrawViewGrid to only update cells in freehand mode
  • Consolidate toggleIsDrawing, resetDrawViewGrid, updateDrawViewGrid and remove duplicates
lib/providers/draw_badge_provider.dart

Assessment against linked issues

Issue Objective Addressed Explanation
#1374 Enable the draw clipart function to support drawing with different shapes such as Square, Rectangle, Circle, and Triangle, in addition to freehand.

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

github-actions bot commented Jul 18, 2025

Build Status

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

Screenshots (Android)

Screenshots (iPhone)

Screenshots (iPad)

@samruddhi-Rahegaonkar samruddhi-Rahegaonkar marked this pull request as ready for review July 18, 2025 14:32
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 @samruddhi-Rahegaonkar - I've reviewed your changes - here's some feedback:

  • After drawing shapes via the BMBadge shape methods you’re mutating the grid directly but not notifying listeners—add notifyListeners() (or equivalent setState) after shape updates so the UI stays in sync.
  • The code for converting touch positions into grid rows/columns (with clamping and cell size math) is duplicated—extract that into a shared helper to reduce repetition and improve readability.
  • Currently each pan update draws a new shape on top of the last, leading to overlapping previews—consider clearing or redrawing the previous preview shape before rendering the updated one to avoid artifacts.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- After drawing shapes via the BMBadge shape methods you’re mutating the grid directly but not notifying listeners—add notifyListeners() (or equivalent setState) after shape updates so the UI stays in sync.
- The code for converting touch positions into grid rows/columns (with clamping and cell size math) is duplicated—extract that into a shared helper to reduce repetition and improve readability.
- Currently each pan update draws a new shape on top of the last, leading to overlapping previews—consider clearing or redrawing the previous preview shape before rendering the updated one to avoid artifacts.

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.

@hpdang
Copy link
Member

hpdang commented Jul 23, 2025

@samruddhi-Rahegaonkar Good idea, but the implementation needs improvement. The moving preview screen makes drawing difficult, compared to the previous version where the preview/drawing screen stayed stable.

@samruddhi-Rahegaonkar
Copy link
Member Author

samruddhi-Rahegaonkar commented Jul 23, 2025

@hpdang How about reducing the preview size little bit and adding the tools to right of the preview vertically ? or keeping it strictly vertical without scrolling ?

@samruddhi-Rahegaonkar
Copy link
Member Author

@nope3472 Please Share your insights what you were talking in todays meeting.

@nope3472
Copy link
Contributor

nope3472 commented Aug 1, 2025

@samruddhi-Rahegaonkar yeah just need to recheck will update you

Copy link
Contributor

@nope3472 nope3472 left a comment

Choose a reason for hiding this comment

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

Update all shape-drawing routines (circle, rectangle, triangle, etc.) so that if a shape extends beyond a grid edge, the overflowing part wraps around to the opposite edge.

@hpdang
Copy link
Member

hpdang commented Aug 11, 2025

@nope3472 please review this

@hpdang hpdang merged commit 7494700 into fossasia:development Aug 15, 2025
6 checks passed
@mariobehling mariobehling changed the title feat: Added Support for the shapes in draw clipart. feat: Added Support for the shapes in draw clipart Sep 1, 2025
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.

Support to add Shapes to the draw clipart function
3 participants