bevy/crates/bevy_ui/src
Gagnus 298b01f10d
Adds back in way to convert color to u8 array, implemented for the two RGB color types, also renames Color::linear to Color::to_linear. (#13759)
# Objective

One thing missing from the new Color implementation in 0.14 is the
ability to easily convert to a u8 representation of the rgb color.

(note this is a redo of PR https://github.com/bevyengine/bevy/pull/13739
as I needed to move the source branch

## Solution

I have added to_u8_array and to_u8_array_no_alpha to a new trait called
ColorToPacked to mirror the f32 conversions in ColorToComponents and
implemented the new trait for Srgba and LinearRgba.
To go with those I also added matching from_u8... functions and
converted a couple of cases that used ad-hoc implementations of that
conversion to use these.
After discussion on Discord of the experience of using the API I renamed
Color::linear to Color::to_linear, as without that it looks like a
constructor (like Color::rgb).
I also added to_srgba which is the other commonly converted to type of
color (for UI and 2D) to match to_linear.
Removed a redundant extra implementation of to_f32_array for LinearColor
as it is also supplied in ColorToComponents (I'm surprised that's
allowed?)

## Testing

Ran all tests and manually tested.
Added to_and_from_u8 to linear_rgba::tests

## Changelog

visible change is Color::linear becomes Color::to_linear.

---------

Co-authored-by: John Payne <20407779+johngpayne@users.noreply.github.com>
2024-06-10 13:03:46 +00:00
..
layout Fix image measure function to apply inherent aspect ratio to style sizes (#13555) 2024-05-30 18:37:39 +00:00
render Adds back in way to convert color to u8 array, implemented for the two RGB color types, also renames Color::linear to Color::to_linear. (#13759) 2024-06-10 13:03:46 +00:00
widget make UI text rendering camera driven (#13697) 2024-06-06 00:20:50 +00:00
accessibility.rs fix: use try_insert instead of insert in bevy_ui to prevent panics when despawning ui nodes (#13000) 2024-04-19 18:12:08 +00:00
focus.rs don't attempt to set cursor relative position for zero sized nodes (#12395) 2024-03-10 02:18:40 +00:00
geometry.rs Fix uses of "it's" vs "its". (#13033) 2024-04-19 18:17:31 +00:00
lib.rs Run CheckVisibility after all the other visibility system sets have… (#12962) 2024-04-18 20:33:29 +00:00
measurement.rs Fix image measure function to apply inherent aspect ratio to style sizes (#13555) 2024-05-30 18:37:39 +00:00
node_bundles.rs Fix uses of "it's" vs "its". (#13033) 2024-04-19 18:17:31 +00:00
stack.rs Reduce steady-state allocations in ui_stack_system (#12413) 2024-03-12 13:57:57 +00:00
texture_slice.rs fix: use try_insert instead of insert in bevy_ui to prevent panics when despawning ui nodes (#13000) 2024-04-19 18:12:08 +00:00
ui_material.rs Fix incorrect link in UiMaterial documentation (#12361) 2024-03-07 22:09:57 +00:00
ui_node.rs Upgrade to Taffy 0.4 (#10690) 2024-04-30 14:13:17 +00:00
update.rs fix: use try_insert instead of insert in bevy_ui to prevent panics when despawning ui nodes (#13000) 2024-04-19 18:12:08 +00:00