Skip to content

fix: added canvas color change support according to the display's colors using ColorPaletteProvider#45

Merged
AsCress merged 2 commits intofossasia:mainfrom
Vishveshwara:canvas_color_fix
Jun 5, 2025
Merged

fix: added canvas color change support according to the display's colors using ColorPaletteProvider#45
AsCress merged 2 commits intofossasia:mainfrom
Vishveshwara:canvas_color_fix

Conversation

@Vishveshwara
Copy link
Copy Markdown
Contributor

@Vishveshwara Vishveshwara commented Jun 4, 2025

Fixes #44

Before the Fix(The black/white display should not switch to the red canvas)

canvas_color_issue.mp4

After The Fix

canvas_color_fixed.mp4

Summary by Sourcery

Enable dynamic cycling of canvas background colors based on each display’s supported color palette and prevent unsupported red canvas on black/white e-paper displays.

New Features:

  • Add canvas color change support driven by display-specific palettes via ColorPaletteProvider.

Bug Fixes:

  • Prevent red canvas selection on black/white only displays.

Enhancements:

  • Fetch available canvas colors from ColorPaletteProvider using GetIt locator.
  • Reorder color arrays in EPD utility classes to list white first according to display capabilities.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Jun 4, 2025

Reviewer's Guide

Implements dynamic canvas color cycling by sourcing the display’s palette from ColorPaletteProvider and corrects the ordering of color arrays in EPD utility classes.

Sequence Diagram: Dynamic Canvas Color Update

sequenceDiagram
    actor User
    participant MBIES as MovableBackgroundImageExampleState
    participant GSL as getItLocator
    participant CPP as ColorPaletteProvider

    %% Initialization of availableCanvasColors (typically happens once)
    MBIES->>GSL: getIt<ColorPaletteProvider>()
    activate GSL
    GSL-->>MBIES: ColorPaletteProvider instance
    deactivate GSL

    MBIES->>CPP: .colors (access property)
    activate CPP
    CPP-->>MBIES: availableCanvasColors
    deactivate CPP

    %% User triggers the canvas color change
    User->>MBIES: Triggers changeCanvasColor()
    activate MBIES
    MBIES->>MBIES: currentCanvasColorIndex = (idx + 1) % availableCanvasColors.length
    MBIES->>MBIES: newColor = availableCanvasColors[currentCanvasColorIndex]
    MBIES->>MBIES: _currentCanvasColor = _getCanvasColorName(newColor)
    MBIES->>MBIES: setState()
    deactivate MBIES
Loading

Class Diagram: Updates for Dynamic Canvas Color Palette

classDiagram
    class _MovableBackgroundImageExampleState {
      +List~Color~ availableCanvasColors
      +int currentCanvasColorIndex
      -_getCanvasColorName(Color color) String
      +_changeCanvasColor() void
    }
    class ColorPaletteProvider {
      +List~Color~ colors
    }
    class Gdey037z03 {
      +List~Color~ colors
    }
    class Gdey037z03BW {
      +List~Color~ colors
    }
    _MovableBackgroundImageExampleState ..> ColorPaletteProvider : uses colors from
Loading

File-Level Changes

Change Details Files
Dynamic canvas color cycling via ColorPaletteProvider
  • Inject ColorPaletteProvider via getIt to retrieve available canvas colors
  • Define availableCanvasColors list and currentCanvasColorIndex state
  • Add _getCanvasColorName helper to map Color to its name
  • Replace hard-coded switch-case in _changeCanvasColor with index-based cycling
  • Update _currentCanvasColor based on provider-supplied palette
lib/pro_image_editor/features/movable_background_image.dart
Reordered color definitions in EPD display implementations
  • Swap colors array to start with white in Gdey037z03
  • Swap colors array to start with white in Gdey037z03BW
lib/util/epd/gdey037z03.dart
lib/util/epd/gdey037z03bw.dart

Assessment against linked issues

Issue Objective Addressed Explanation
#44 Change the canvas color based on the display's supported colors.

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
Copy Markdown
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 @Vishveshwara - I've reviewed your changes - here's some feedback:

  • Rather than mapping Colors to hard-coded string names in _getCanvasColorName, consider storing the current canvas color as a Color (or using a name–color pair from your provider) to eliminate the manual mapping and support future palette changes.
  • Since availableCanvasColors is captured once via getIt, any runtime updates to the ColorPaletteProvider won’t be reflected—consider listening to the provider or rebuilding that list in build/initState so it stays in sync.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

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.

// Add this method to handle canvas color changes
final List<Color> availableCanvasColors =
getIt<ColorPaletteProvider>().colors;
int currentCanvasColorIndex = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Initial canvas color state may be out of sync

Initialize _currentCanvasColor in initState using currentCanvasColorIndex to keep the displayed name and actual color in sync.

@AsCress AsCress changed the title fix: Added canvas color change support according to the display's colors using ColorPaletteProvider. fix: added canvas color change support according to the display's colors using ColorPaletteProvider Jun 5, 2025
Copy link
Copy Markdown
Collaborator

@AsCress AsCress left a comment

Choose a reason for hiding this comment

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

LGTM !

@AsCress AsCress merged commit 136bbe6 into fossasia:main Jun 5, 2025
3 checks passed
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.

Canvas Color should be changed according to the display's supported colors

2 participants