Refactor many usages of Color to natively store linear not gamma (#2457)

This commit is contained in:
Keavon Chambers
2025-03-18 05:37:20 -07:00
committed by GitHub
parent 056020a56c
commit 6292dea103
36 changed files with 232 additions and 183 deletions
+1 -1
View File
@@ -454,7 +454,7 @@ export class Gradient {
}
}
// All channels range from 0 to 1
// All channels range are represented by 0-1, sRGB, gamma.
export class Color {
readonly red!: number;
+10 -8
View File
@@ -481,12 +481,13 @@ impl EditorHandle {
/// Update primary color with values on a scale from 0 to 1.
#[wasm_bindgen(js_name = updatePrimaryColor)]
pub fn update_primary_color(&self, red: f32, green: f32, blue: f32, alpha: f32) -> Result<(), JsValue> {
let primary_color = match Color::from_rgbaf32(red, green, blue, alpha) {
Some(color) => color,
None => return Err(Error::new("Invalid color").into()),
let Some(primary_color) = Color::from_rgbaf32(red, green, blue, alpha) else {
return Err(Error::new("Invalid color").into());
};
let message = ToolMessage::SelectPrimaryColor { color: primary_color };
let message = ToolMessage::SelectPrimaryColor {
color: primary_color.to_linear_srgb(),
};
self.dispatch(message);
Ok(())
@@ -495,12 +496,13 @@ impl EditorHandle {
/// Update secondary color with values on a scale from 0 to 1.
#[wasm_bindgen(js_name = updateSecondaryColor)]
pub fn update_secondary_color(&self, red: f32, green: f32, blue: f32, alpha: f32) -> Result<(), JsValue> {
let secondary_color = match Color::from_rgbaf32(red, green, blue, alpha) {
Some(color) => color,
None => return Err(Error::new("Invalid color").into()),
let Some(secondary_color) = Color::from_rgbaf32(red, green, blue, alpha) else {
return Err(Error::new("Invalid color").into());
};
let message = ToolMessage::SelectSecondaryColor { color: secondary_color };
let message = ToolMessage::SelectSecondaryColor {
color: secondary_color.to_linear_srgb(),
};
self.dispatch(message);
Ok(())