diff --git a/common/src/pattern.rs b/common/src/pattern.rs index 9a4f8a3..871b166 100644 --- a/common/src/pattern.rs +++ b/common/src/pattern.rs @@ -117,7 +117,7 @@ impl InputRender for u16 { } } -#[derive(Serialize, Deserialize, Clone, Debug, strum::Display)] +#[derive(Serialize, Deserialize, Clone, Debug, strum::Display, strum::EnumString)] pub enum Parameters { Collide(CollideParams), Slide(SlideParams), @@ -153,21 +153,6 @@ impl FormRender for Parameters { } impl Parameters { - pub fn default_with_name(name: &str) -> Option { - match name { - "Collide" => Some(Self::Collide(CollideParams::default())), - "Slide" => Some(Self::Slide(SlideParams::default())), - "Fade" => Some(Self::Fade(FadeParams::default())), - "MovingPixel" => Some(Self::MovingPixel(MovingPixelParams::default())), - "MovingRainbow" => Some(Self::MovingRainbow(MovingRainbowParams::default())), - "Orb" => Some(Self::Orb(OrbParams::default())), - "Solid" => Some(Self::Solid(SolidParams::default())), - "Visualizer" => Some(Self::Visualizer(VisualizerParams::default())), - "Flashing" => Some(Self::Flashing(FlashingParams::default())), - _ => None, - } - } - pub const fn get_names() -> &'static [&'static str] { &[ "Solid", diff --git a/webui/src/lib.rs b/webui/src/lib.rs index affc7d7..407ca27 100644 --- a/webui/src/lib.rs +++ b/webui/src/lib.rs @@ -4,6 +4,7 @@ use actix_web_actors::ws; use common::{error, pattern, strip}; use live_view::{LiveView, StateSocket, Template}; use template::{AppTemplate, ControlTemplate}; +use std::str::FromStr; use actix_web::{ error::{ErrorInternalServerError, JsonPayloadError, UrlencodedError}, @@ -100,7 +101,7 @@ async fn start_socket( println!("Got change template event: {event:?}"); let template_name = event.data.as_ref()?; - let params = pattern::Parameters::default_with_name(template_name)?; + let params = pattern::Parameters::from_str(template_name).ok()?; state.parameters = params; state