From 1d68ad09ef86fd0375aed004313856abbd7b93f4 Mon Sep 17 00:00:00 2001 From: "Spencer C. Imbleau" Date: Fri, 5 Jul 2024 02:12:28 -0400 Subject: [PATCH] fix: color name adjustments --- examples/demo/src/ui.rs | 6 +++--- examples/scene_ui/src/main.rs | 4 ++-- src/debug.rs | 37 +++++++++++++++++------------------ 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/examples/demo/src/ui.rs b/examples/demo/src/ui.rs index 8c3457b..464cdb3 100644 --- a/examples/demo/src/ui.rs +++ b/examples/demo/src/ui.rs @@ -245,7 +245,7 @@ pub fn controls_ui( ui.heading("Theme"); for layer in composition.as_ref().get_layers() { let color = theme.get_mut(layer).cloned().unwrap_or_default(); - let color = color.to_srgba(); + let color = color.to_linear(); let mut color_edit = [color.red, color.green, color.blue, color.alpha]; ui.horizontal(|ui| { if ui @@ -258,8 +258,8 @@ pub fn controls_ui( .theme .as_mut() .unwrap() - .edit(layer, Color::srgba(r, g, b, a)); - theme.edit(layer, Color::srgba(r, g, b, a)); + .edit(layer, Color::linear_rgba(r, g, b, a)); + theme.edit(layer, Color::linear_rgba(r, g, b, a)); }; ui.label(layer); }); diff --git a/examples/scene_ui/src/main.rs b/examples/scene_ui/src/main.rs index ba31c0e..2ec9fd6 100644 --- a/examples/scene_ui/src/main.rs +++ b/examples/scene_ui/src/main.rs @@ -1,6 +1,6 @@ use std::f64::consts::{FRAC_PI_4, SQRT_2}; -use bevy::prelude::*; +use bevy::{color::palettes::css, prelude::*}; use bevy_vello::{prelude::*, VelloPlugin}; fn main() { @@ -27,7 +27,7 @@ fn setup_ui(mut commands: Commands) { border: UiRect::all(Val::Px(2.0)), ..default() }, - border_color: Srgba::rgb(1.0, 0.0, 1.0).with_alpha(0.5).into(), + border_color: css::FUCHSIA.with_alpha(0.5).into(), ..default() }, Interaction::default(), diff --git a/src/debug.rs b/src/debug.rs index 3c09cea..4ec1a49 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -3,7 +3,7 @@ use crate::{ text::VelloTextAlignment, CoordinateSpace, VelloAsset, VelloAssetAlignment, VelloFont, VelloText, ZFunction, }; -use bevy::{math::Vec3Swizzles, prelude::*}; +use bevy::{color::palettes::css, math::Vec3Swizzles, prelude::*}; const RED_X_SIZE: f32 = 8.0; @@ -150,7 +150,7 @@ fn render_text_debug( } }; let rect_center = origin + rect.size() / 2.0; - gizmos.rect_2d(rect_center, 0.0, rect.size(), Color::WHITE); + gizmos.rect_2d(rect_center, 0.0, rect.size(), css::WHITE); } CoordinateSpace::ScreenSpace => { let Some(rect) = text.bb_in_screen_space(font, gtransform, camera, view) else { @@ -200,7 +200,7 @@ fn render_text_debug( rect_center, 0.0, rect.size() * Vec2::new(1.0, 1.0), - Color::WHITE, + css::WHITE, ); } } @@ -213,12 +213,12 @@ fn draw_origin(gizmos: &mut Gizmos, projection: &OrthographicProjection, origin: let from = origin + RED_X_SIZE * Vec2::splat(1.0) * projection.scale; let to = origin + RED_X_SIZE * Vec2::splat(-1.0) * projection.scale; - gizmos.line_2d(from, to, Srgba::RED); + gizmos.line_2d(from, to, css::RED); let from = origin + RED_X_SIZE * Vec2::new(1.0, -1.0) * projection.scale; let to = origin + RED_X_SIZE * Vec2::new(-1.0, 1.0) * projection.scale; - gizmos.line_2d(from, to, Srgba::RED); + gizmos.line_2d(from, to, css::RED); } /// A helper method to draw the bounding box @@ -231,25 +231,25 @@ fn draw_bounding_box(gizmos: &mut Gizmos, z_fn: &ZFunction, position: Vec2, size gizmos.line_2d( position + Vec2::new(-half_width, -half_height), position + Vec2::new(-half_width, half_height), - Color::WHITE, + css::WHITE, ); // Top gizmos.line_2d( position + Vec2::new(-half_width, -half_height), position + Vec2::new(half_width, -half_height), - Color::WHITE, + css::WHITE, ); // Right gizmos.line_2d( position + Vec2::new(half_width, -half_height), position + Vec2::new(half_width, half_height), - Color::WHITE, + css::WHITE, ); // Bottom gizmos.line_2d( position + Vec2::new(-half_width, half_height), position + Vec2::new(half_width, half_height), - Color::WHITE, + css::WHITE, ); // TODO: When bevy_gizmos get text, I'd *much rather* just show the Z value with text. @@ -261,50 +261,49 @@ fn draw_bounding_box(gizmos: &mut Gizmos, z_fn: &ZFunction, position: Vec2, size // position, // 0.0, // size, - // Color::WHITE, + // css::WHITE, // ); // ``` - const Z_COLOR: Srgba = Srgba::GREEN; match z_fn { ZFunction::TransformX => gizmos.line_2d( position + Vec2::new(0.0, -half_height), position + Vec2::new(0.0, half_height), - Z_COLOR, + css::GREEN, ), ZFunction::TransformY => gizmos.line_2d( position + Vec2::new(-half_width, 0.0), position + Vec2::new(half_width, 0.0), - Z_COLOR, + css::GREEN, ), ZFunction::TransformXOffset(offset) => gizmos.line_2d( position + Vec2::new(*offset, -half_height), position + Vec2::new(*offset, half_height), - Z_COLOR, + css::GREEN, ), ZFunction::TransformYOffset(offset) => gizmos.line_2d( position + Vec2::new(-half_width, *offset), position + Vec2::new(half_width, *offset), - Z_COLOR, + css::GREEN, ), ZFunction::BbTop | ZFunction::BbTopInverse => gizmos.line_2d( position + Vec2::new(-half_width, half_height), position + Vec2::new(half_width, half_height), - Z_COLOR, + css::GREEN, ), ZFunction::BbBottom | ZFunction::BbBottomInverse => gizmos.line_2d( position + Vec2::new(-half_width, -half_height), position + Vec2::new(half_width, -half_height), - Z_COLOR, + css::GREEN, ), ZFunction::BbLeft | ZFunction::BbLeftInverse => gizmos.line_2d( position + Vec2::new(-half_width, -half_height), position + Vec2::new(-half_width, half_height), - Z_COLOR, + css::GREEN, ), ZFunction::BbRight | ZFunction::BbRightInverse => gizmos.line_2d( position + Vec2::new(half_width, -half_height), position + Vec2::new(half_width, half_height), - Z_COLOR, + css::GREEN, ), ZFunction::TransformZ | ZFunction::TransformZOffset(_)