fix: Apply opacity to text shadows and keep the style color of TextComponent - #4043
Draft
spydon wants to merge 1 commit into
Draft
fix: Apply opacity to text shadows and keep the style color of TextComponent#4043spydon wants to merge 1 commit into
spydon wants to merge 1 commit into
Conversation
4 tasks
spydon
force-pushed
the
fix/text-component-opacity-shadows
branch
from
September 8, 2026 19:47
5334a1f to
8ae253e
Compare
5 tasks
spydon
force-pushed
the
fix/text-component-opacity-shadows
branch
from
September 8, 2026 20:10
8ae253e to
8d51db4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When an
OpacityEffectran on aTextComponent,TextPaint.copyWithPaintreplaced the style'sforeground with the component's paint. That threw away the color defined in the
TextStyle(thetext snapped to white when the effect started) and left the
shadowsat their original alpha, so afading text left a non-fading glow behind.
TextPaint.copyWithPaintnow treats the component paint as a layer on top of the style. The opacityof the paint scales the opacity of the text color, the shadows, the decoration color and the
background, and the paint's color filter, mask filter and shader are applied to the glyphs so
ColorEffect,tintandhuekeep working. An existingforegroundpaint on the style, forexample stroked text, keeps its other properties instead of being thrown away. Only the opacity of
the paint color is used, which matches how sprites and every other renderer treat the paint color.
TextComponentkeeps the renderer that was set on it:textRendereralways returns that renderer,and the copy with the paint applied is the new internal
paintedTextRenderer, derived again onevery paint change. Repeated opacity updates therefore never compound, and the pattern of reading
textRenderer, copying it with a change, and setting it back is safe after an effect has run.Setting a new
textRendererwhile the paint has been changed applies the current paint to it rightaway.
TextBoxComponentpreviously only picked up paint changes on its next redraw, which for a staticbox never happened. It now draws its cached image with the component's
paint, so opacity and colorfilters apply to the whole box, including the background, without re-rendering the text. Its
onChangedis a no-op since the text does not need to be formatted again.SpriteFontRenderer.copyWithPainthad the same class of bug: it droppedscale,letterSpacingand the color filter set through
fromFont(color:). It now keeps them and only multiplies in theopacity.
DebugTextRendererinflame_testkeeps its own color as well, and the contract is nowdocumented on the abstract
TextRenderer.copyWithPaint.Behavior notes:
setColoron a text component no longer changes the text color, only its opacity,since the paint color's RGB is ignored like it is for sprites; use
ColorEffectortintto colortext. Stroke settings on the component paint are no longer forwarded to the glyphs; set them on the
style's
foregroundinstead.Checklist
docsand added dartdoc comments with///.examplesordocs.Breaking Change?
Related Issues
Closes #4013