plottery_runtime 0.20.0

What a Plottery project compiles against: param types, the PlotteryParams derive and the project's entry point. Plottery is a creative coding framework for generative vector graphics and pen plotting.
Documentation
use serde::{Deserialize, Serialize};

/// Value of a `#[derive(PlotteryEnum)]` field: the selected variant and all variant names.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ProjectParamEnum {
    pub selected: String,
    pub variants: Vec<String>,
}

impl ProjectParamEnum {
    pub fn new(selected: &str, variants: &[&str]) -> Self {
        Self {
            selected: selected.to_string(),
            variants: variants.iter().map(|v| v.to_string()).collect(),
        }
    }

    pub fn selected_index(&self) -> Option<usize> {
        self.variants.iter().position(|v| *v == self.selected)
    }
}