Skip to content

Refactor: extract renderColoredText to deduplicate text rendering#800

Open
blade-running-man wants to merge 1 commit intoBlueforcer:mainfrom
blade-running-man:refactor/render-colored-text
Open

Refactor: extract renderColoredText to deduplicate text rendering#800
blade-running-man wants to merge 1 commit intoBlueforcer:mainfrom
blade-running-man:refactor/render-colored-text

Conversation

@blade-running-man
Copy link

Extract rainbow/gradient/plain text rendering into a shared DisplayManager::renderColoredText() method, replacing 4 identical blocks across Apps.cpp and Overlays.cpp.

Bug fix

Scrolling notification text in rainbow mode was missing textOffset, causing inconsistent positioning compared to gradient and plain text modes (Overlays.cpp:325).

Changes

  • src/DisplayManager.h — new method declaration
  • src/DisplayManager.cpprenderColoredText() implementation
  • src/Apps.cpp — replaced 2 duplicated blocks (non-scrolling + scrolling)
  • src/Overlays.cpp — replaced 2 duplicated blocks (non-scrolling + scrolling, includes textOffset fix)

…ering

Extract rainbow/gradient/plain text rendering into a shared
DisplayManager method, replacing 4 identical blocks in Apps.cpp
and Overlays.cpp.

Also fixes a bug in Overlays.cpp where scrolling rainbow text
was missing textOffset, causing inconsistent positioning compared
to gradient and plain text modes.
@eku
Copy link
Contributor

eku commented Feb 27, 2026

Robert C. Martin famously said "Functions should do one thing. They should do it well. They should do it only".

Different behaviour of a function depending on the argument is a bad design.

@blade-running-man
Copy link
Author

Robert C. Martin famously said "Functions should do one thing. They should do it well. They should do it only".

Different behaviour of a function depending on the argument is a bad design.

Fair point about SRP, but I'd argue this function does one thing - renders text with the app's color settings. The mode branching is an implementation detail, similar to how printf handles different format specifiers internally.

The reason I extracted it: the same 12-line if/else chain was copy-pasted 4 times across Apps.cpp and Overlays.cpp. One of those copies already had a bug — rainbow mode in Overlays.cpp:325 was missing textOffset, so scrolling rainbow text was offset differently from gradient/plain. That's exactly the kind of bug duplication creates.

I'm ok to close this if you'd rather keep it inline

@blade-running-man
Copy link
Author

Robert C. Martin famously said "Functions should do one thing. They should do it well. They should do it only".

Different behaviour of a function depending on the argument is a bad design.

To add some context - the existing codebase already follows this same pattern in several places: indicatorParser has 5 switch blocks branching on indicator, printText branches on bool centered, HSVtext/GradientText both branch on bool clear, drawBarChart/drawLineChart branch on bool withIcon. So this isn't introducing a new pattern, it's consistent with what's already here.

Also "duplication is the root of all evil in software design" and these two principles are often in tension. In this case I leaned toward reducing duplication since it already caused an actual bug

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