Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added emoji rendering #1200 #1213

Open
wants to merge 2 commits into
base: flutter_app
Choose a base branch
from

Conversation

nope3472
Copy link
Contributor

@nope3472 nope3472 commented Feb 26, 2025

Fixes #1200

Changes

  • Updated the message rendering logic to ensure that emojis and text are not cut off .
  • Improved the downsampling algorithm to reliably convert the rendered image into an LED matrix without clipping.
  • Added Marque effect

Checklist:

  • No hard coding: All values are sourced appropriately without hard coding.
  • No end of file edits: No modifications at the end of resource files.
  • Code reformatting: Code has been reformatted and indentation fixed throughout.
  • Code analyzation: Code passes flutter analyze and tests run with flutter test.

Summary by Sourcery

Improves the badge's text rendering capabilities by adding font selection and marquee effect, and fixes clipping issues with emojis and text.

New Features:

  • Introduces a marquee effect for the badge message.
  • Adds the ability to select from a list of Google Fonts for the badge message.

Bug Fixes:

  • Fixes an issue where emojis and text were being cut off in the message rendering.

Enhancements:

  • Improves the message rendering logic to prevent text and emoji cut-off.
  • Enhances the downsampling algorithm for more reliable conversion of rendered images to LED matrices, avoiding clipping.

Summary by Sourcery

Improves the badge's text rendering capabilities by adding font selection and marquee effect, and fixes clipping issues with emojis and text.

New Features:

  • Introduces a marquee effect for the badge message.
  • Adds the ability to select from a list of Google Fonts for the badge message.

Bug Fixes:

  • Fixes an issue where emojis and text were being cut off in the message rendering.

Enhancements:

  • Improves the message rendering logic to prevent text and emoji cut-off.
  • Enhances the downsampling algorithm for more reliable conversion of rendered images to LED matrices, avoiding clipping.

Copy link
Contributor

sourcery-ai bot commented Feb 26, 2025

Reviewer's Guide by Sourcery

This pull request introduces enhanced text and emoji rendering capabilities to the badge, including font selection, a marquee effect, and improved clipping prevention. It also refactors the rendering pipeline to support these new features.

Sequence diagram for message rendering with text style

sequenceDiagram
    participant User
    participant HomeScreen
    participant AnimationBadgeProvider
    participant Converters
    participant BadgePaint

    User->>HomeScreen: Types message and selects font
    HomeScreen->>AnimationBadgeProvider: badgeAnimation(message, isInverted, textStyle)
    AnimationBadgeProvider->>Converters: messageTohex(message, isInverted, textStyle)
    Converters->>Converters: renderTextToMatrix(message, textStyle)
    Converters-->>AnimationBadgeProvider: hexStrings
    AnimationBadgeProvider->>AnimationBadgeProvider: setNewGrid(binaryArray)
    AnimationBadgeProvider->>BadgePaint: getPaintGrid()
    BadgePaint->>BadgePaint: paint(canvas, size)
Loading

File-Level Changes

Change Details Files
Implements text and emoji rendering with font selection and marquee effect.
  • Adds Google Fonts integration for text styling.
  • Introduces a marquee effect for the badge message.
  • Improves message rendering logic to prevent text and emoji cut-off.
  • Enhances the downsampling algorithm for more reliable conversion of rendered images to LED matrices, avoiding clipping.
lib/view/homescreen.dart
lib/bademagic_module/utils/converters.dart
lib/virtualbadge/view/draw_badge.dart
lib/virtualbadge/view/badge_paint.dart
lib/virtualbadge/view/animated_badge.dart
lib/providers/animation_badge_provider.dart
lib/badge_animation/ani_fixed.dart
lib/view/save_badge_screen.dart
Updates the AnimationBadge widget to accept text and textStyle properties.
  • Modifies the AnimationBadge widget to receive text and textStyle parameters.
  • Updates the BadgePaint to render text using the provided textStyle.
lib/virtualbadge/view/badge_paint.dart
lib/virtualbadge/view/animated_badge.dart
Refactors the messageToHex function in Converters to support text rendering with custom fonts and emoji handling.
  • Adds textStyle parameter to messageToHex function.
  • Implements renderTextToMatrix function to convert text and emojis to a boolean matrix.
  • Updates messageToHex to use renderTextToMatrix when a textStyle is provided.
lib/bademagic_module/utils/converters.dart

Assessment against linked issues

Issue Objective Addressed Explanation
#1200 Fix emoji rendering issues by correctly rendering both emojis and text without cutoff or clipping.
#1200 Improve the downsampling algorithm to reliably convert the rendered image into an LED matrix.
#1200 Add a marquee effect for the badge message.

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!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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

Overall Comments:

  • Consider extracting the font selection logic into a separate widget for better organization.
  • The animation provider is initialized twice, once as a field and again in initState; prefer initializing it only once.
Here's what I looked at during the review
  • 🟡 General issues: 4 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: 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.

@@ -92,17 +124,23 @@ class _HomeScreenState extends State<HomeScreen>
} else {
previousText = currentText;
}
_controllerListner();
}

void _controllerListner() {
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick (typo): Consider renaming '_controllerListner' to '_controllerListener'.

This minor naming adjustment would improve code readability and reduce potential confusion.

Suggested implementation:

    _controllerListener();

  void _controllerListener() {

Comment on lines +181 to +184
final ui.Picture picture = recorder.endRecording();
final ui.Image image = await picture.toImage(canvasWidth, canvasHeight);
final ByteData? byteData =
await image.toByteData(format: ui.ImageByteFormat.rawRgba);
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Consider handling the null case from toByteData more gracefully.

Instead of throwing an exception when byteData is null, you might want to consider a fallback mechanism or clearer logging for better error tracing.

Suggested change
final ui.Picture picture = recorder.endRecording();
final ui.Image image = await picture.toImage(canvasWidth, canvasHeight);
final ByteData? byteData =
await image.toByteData(format: ui.ImageByteFormat.rawRgba);
final ui.Picture picture = recorder.endRecording();
final ui.Image image = await picture.toImage(canvasWidth, canvasHeight);
final ByteData? rawByteData =
await image.toByteData(format: ui.ImageByteFormat.rawRgba);
final ByteData byteData = rawByteData ?? (() {
debugPrint("Warning: image.toByteData returned null. Using fallback empty byte data.");
final Uint8List fallback = Uint8List(canvasWidth * canvasHeight * 4);
return ByteData.sublistView(fallback);
})();


// Draw the outer rectangle
double horizontalPadding = 8.0;
badgeWidth -= 1.0 * horizontalPadding;
final Paint rectPaint = Paint()
..style = PaintingStyle.fill
..color = Colors.black
..strokeWidth = 2.0;

final RRect gridRect = RRect.fromLTRBR(
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Extract layout magic numbers into named constants.

The expressions like 'offsetWidthBadgeBackground + horizontalPadding - 10' are hard to follow. Abstracting these values as well-named constants can improve maintainability and readability.

Suggested implementation:

    double horizontalPadding = 8.0; 
    const double leftOffsetAdjustment = 10.0;
    const double badgeCornerRadius = 10.0;

    final RRect gridRect = RRect.fromLTRBR(
      offsetWidthBadgeBackground + horizontalPadding - leftOffsetAdjustment,
      offsetHeightBadgeBackground,
      offsetWidthBadgeBackground + badgeWidth + horizontalPadding,
      offsetHeightBadgeBackground + badgeHeight,
      Radius.circular(badgeCornerRadius),
    );

Ensure that if the extracted constants are used elsewhere in the file, they are consistently named and placed in a suitable location for shared layout constants.

String message, Converters converters, bool isInverted) async {
if (message == "") {
//geerate a 2d list with all values as 0
void badgeAnimation(String message, Converters converters, bool isInverted,
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Review the default TextStyle fallback in badgeAnimation.

The current fallback uses 'TextStyle(fontSize: 11, color: Colors.black)'. Ensure that this default aligns with overall design expectations or consider defining it as a class-level constant.

Suggested implementation:

class AnimationBadgeProvider extends ChangeNotifier {
  static const TextStyle defaultTextStyle = TextStyle(fontSize: 11, color: Colors.black);

  void badgeAnimation(String message, Converters converters, bool isInverted,
      {TextStyle? textStyle}
      ) async {
    if (message.isEmpty) {
      List<List<bool>> image =
          List.generate(16, (i) => List.generate(45, (j) => false));
      setNewGrid(image);
    } else {
      final effectiveTextStyle = textStyle ?? defaultTextStyle;

Please ensure that the rest of the badgeAnimation function uses effectiveTextStyle where a TextStyle is needed.

@nope3472 nope3472 changed the title feat : add both text and emoji rendering feat: added emoji rendering #1200 Feb 26, 2025
Copy link
Contributor

List<List<bool>> _paintGrid =
List.generate(11, (i) => List.generate(44, (j) => false));
List.generate(16, (i) => List.generate(45, (j) => false));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are we changing the badge size?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The hardware badge is 11x44

@@ -4,7 +4,10 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class AnimationBadge extends StatefulWidget {
const AnimationBadge({super.key});
final String text;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Animation badge should have no relation to the text. It just displays whatever binary data is passed on

import 'package:badgemagic/bademagic_module/utils/badge_utils.dart';
import 'package:flutter/material.dart';

class BadgePaint extends CustomPainter {
BadgeUtils badgeUtils = BadgeUtils();
final List<List<bool>> grid;
final TextStyle? textStyle;
Copy link
Collaborator

Choose a reason for hiding this comment

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

There should be no changes to animation and badge view

Copy link
Collaborator

@adityastic adityastic left a comment

Choose a reason for hiding this comment

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

You might want to spend some time understanding the low level design of the app. Based on your changes you break every separation of concern principle we adhere to.

@adityastic adityastic force-pushed the flutter_app branch 2 times, most recently from d14b7e1 to 381b8c8 Compare March 14, 2025 13:48
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.

2 participants