Skip to content

Clean up usage of rgba()#3967

Merged
freakboy3742 merged 7 commits intobeeware:mainfrom
HalfWhitt:rgb-consistency
Dec 12, 2025
Merged

Clean up usage of rgba()#3967
freakboy3742 merged 7 commits intobeeware:mainfrom
HalfWhitt:rgb-consistency

Conversation

@HalfWhitt
Copy link
Copy Markdown
Member

As of, #3665, rgba is now an alias for the preferred rgb, as in CSS. Toga's code base is still using rgba in a number of places.

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

Copy link
Copy Markdown
Member Author

@HalfWhitt HalfWhitt left a comment

Choose a reason for hiding this comment

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

Most of these are very straightforward and mechanical — comments inline on a couple of places where I did more beyond search-and-replace.

requested_color = rgba(0, 0, 0, 0)
else:
requested_color = color.rgba
parent_color = toga_color(SystemColors.Control)
Copy link
Copy Markdown
Member Author

@HalfWhitt HalfWhitt Dec 11, 2025

Choose a reason for hiding this comment

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

toga_color() returns an rgb instance; since there's no difference now between that and rgba, no conversion needs to be done. (It was toga_color(SystemColors.Control).rgba.)

match color, self._default_background_color:
case (colors.TRANSPARENT, _) | (None, colors.TRANSPARENT):
requested_color = rgb(0, 0, 0, 0)
case None, _:
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Condensed four cases to three with spiffy new syntax : )

return rgba(r, g, b, a[0])
else:
return rgba(r, g, b)
return rgb(r, g, b, a[0] if a else 1)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Since rgb can take an alpha parameter, the conditional can be on the argument itself rather than what class to construct.

@HalfWhitt HalfWhitt marked this pull request as ready for review December 12, 2025 01:25
Copy link
Copy Markdown
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

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

👍 All looks good to me! Thanks for the cleanup!

@freakboy3742 freakboy3742 merged commit e1897a3 into beeware:main Dec 12, 2025
56 checks passed
@HalfWhitt HalfWhitt deleted the rgb-consistency branch December 12, 2025 03:20
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