diff --git a/packages/graphite-editor/src/color.rs b/packages/graphite-editor/src/color.rs index fdc4b7ade..70af190d3 100644 --- a/packages/graphite-editor/src/color.rs +++ b/packages/graphite-editor/src/color.rs @@ -1,3 +1,5 @@ +use crate::EditorError; + #[repr(C)] #[derive(Debug, Clone, Copy)] pub struct Color { @@ -11,12 +13,12 @@ impl Color { pub fn from_rgbaf32(red: f32, green: f32, blue: f32, alpha: f32) -> Result { let color = Color { red, green, blue, alpha }; if [red, green, blue, alpha].iter().any(|c| c.is_sign_negative() || !c.is_finite()) { - return EditorError::Color(color); + Err(color)? } Ok(color) } pub fn from_rgb8(red: u8, green: u8, blue: u8) -> Color { - from_rgba8(red, green, blue, 255) + Color::from_rgba8(red, green, blue, 255) } pub fn from_rgba8(red: u8, green: u8, blue: u8, alpha: u8) -> Color { let map = |int_color| int_color as f32 / 255.0; @@ -40,6 +42,6 @@ impl Color { self.alpha } pub fn components(&self) -> (f32, f32, f32, f32) { - (red, green, blue, alpha) + (self.red, self.green, self.blue, self.alpha) } } diff --git a/packages/graphite-editor/src/error.rs b/packages/graphite-editor/src/error.rs index f54a9b328..f5b2a8c9c 100644 --- a/packages/graphite-editor/src/error.rs +++ b/packages/graphite-editor/src/error.rs @@ -7,15 +7,15 @@ use std::fmt::{self, Display}; pub enum EditorError { InvalidOperation(String), Misc(String), - Color(Color), + Color(String), } -impl Display for EngineError { +impl Display for EditorError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - EngineError::InvalidOperation(e) => write!(f, "Failed to execute operation: {}", e), - EngineError::Misc(e) => write!(f, "{}", e), - EngineError::Color(c) => write!(f, "Tried to construct an invalid color {:?}", c), + EditorError::InvalidOperation(e) => write!(f, "Failed to execute operation: {}", e), + EditorError::Misc(e) => write!(f, "{}", e), + EditorError::Color(c) => write!(f, "Tried to construct an invalid color {:?}", c), } } } @@ -24,9 +24,9 @@ impl Error for EditorError {} macro_rules! derive_from { ($type:ty, $kind:ident) => { - impl From<$type> for EngineError { + impl From<$type> for EditorError { fn from(error: $type) -> Self { - EngineError::$kind(format!("{}", error)) + EditorError::$kind(format!("{:?}", error)) } } }; diff --git a/packages/graphite-editor/src/tools/mod.rs b/packages/graphite-editor/src/tools/mod.rs index 6ab0a70e4..879ef0297 100644 --- a/packages/graphite-editor/src/tools/mod.rs +++ b/packages/graphite-editor/src/tools/mod.rs @@ -2,7 +2,7 @@ use crate::Color; const TOOL_COUNT: usize = 10; -struct ToolState { +pub struct ToolState { primary_color: Color, secondary_color: Color, active_tool: ToolType, @@ -11,12 +11,12 @@ struct ToolState { impl ToolState { pub fn select_tool(&mut self, tool: ToolType) { - self.active_tool = ToolType + self.active_tool = tool } } #[repr(usize)] -enum ToolType { +pub enum ToolType { Select = 0, Crop = 1, Navigate = 2, @@ -30,11 +30,11 @@ enum ToolType { // all discriminats must be strictly smaller than TOOL_COUNT! } -enum ToolSettings { +pub enum ToolSettings { Select { append_mode: SelectAppendMode }, } -enum SelectAppendMode { +pub enum SelectAppendMode { New, Add, Substract,