mirror of
https://github.com/italicsjenga/vello.git
synced 2025-01-10 04:31:30 +11:00
Use clap to parse base-color option; remove unused width/height parameters
This commit is contained in:
parent
acfd570440
commit
12d5dcd34f
|
@ -130,7 +130,7 @@ async fn render(mut scenes: SceneSet, index: usize, args: &Args) -> Result<()> {
|
|||
let render_params = vello::RenderParams {
|
||||
base_color: args
|
||||
.args
|
||||
.get_base_color()?
|
||||
.base_color
|
||||
.or(scene_params.base_color)
|
||||
.unwrap_or(vello::peniko::Color::BLACK),
|
||||
width,
|
||||
|
|
|
@ -48,11 +48,11 @@ pub struct Arguments {
|
|||
/// The svg files paths to render
|
||||
svgs: Option<Vec<PathBuf>>,
|
||||
#[arg(help_heading = "Render Parameters")]
|
||||
#[arg(long, global(false))]
|
||||
#[arg(long, global(false), value_parser = parse_color)]
|
||||
/// The base color applied as the blend background to the rasterizer.
|
||||
/// Format is CSS style hexidecimal (#RGB, #RGBA, #RRGGBB, #RRGGBBAA) or
|
||||
/// an SVG color name such as "aliceblue"
|
||||
base_color: Option<String>,
|
||||
pub base_color: Option<Color>,
|
||||
#[clap(subcommand)]
|
||||
command: Option<Command>,
|
||||
}
|
||||
|
@ -86,17 +86,6 @@ impl Arguments {
|
|||
.map(Some)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_base_color(&self) -> Result<Option<Color>> {
|
||||
self.base_color.as_ref().map_or_else(
|
||||
|| Ok(None),
|
||||
|s| {
|
||||
Color::parse(&s)
|
||||
.ok_or_else(|| anyhow!("malformed color: {}", s))
|
||||
.map(Some)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Command {
|
||||
|
@ -106,3 +95,7 @@ impl Command {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_color(s: &str) -> Result<Color> {
|
||||
Color::parse(s).ok_or(anyhow!("'{s}' is not a valid color"))
|
||||
}
|
||||
|
|
|
@ -50,18 +50,11 @@ struct Args {
|
|||
/// Switch between scenes with left and right arrow keys
|
||||
#[arg(long)]
|
||||
scene: Option<i32>,
|
||||
/// The base color used as the
|
||||
#[command(flatten)]
|
||||
args: scenes::Arguments,
|
||||
}
|
||||
|
||||
async fn run(
|
||||
event_loop: EventLoop<UserEvent>,
|
||||
window: Window,
|
||||
args: Args,
|
||||
base_color_arg: Option<Color>,
|
||||
mut scenes: SceneSet,
|
||||
) {
|
||||
async fn run(event_loop: EventLoop<UserEvent>, window: Window, args: Args, mut scenes: SceneSet) {
|
||||
use winit::{event::*, event_loop::ControlFlow};
|
||||
let mut render_cx = RenderContext::new().unwrap();
|
||||
let size = window.inner_size();
|
||||
|
@ -184,7 +177,9 @@ async fn run(
|
|||
// If the user specifies a base color in the CLI we use that. Otherwise we use any
|
||||
// color specified by the scene. The default is black.
|
||||
let render_params = vello::RenderParams {
|
||||
base_color: base_color_arg
|
||||
base_color: args
|
||||
.args
|
||||
.base_color
|
||||
.or(scene_params.base_color)
|
||||
.unwrap_or(Color::BLACK),
|
||||
width,
|
||||
|
@ -262,7 +257,6 @@ fn main() -> Result<()> {
|
|||
env_logger::init();
|
||||
let args = Args::parse();
|
||||
let scenes = args.args.select_scene_set(|| Args::command())?;
|
||||
let base_color = args.args.get_base_color()?;
|
||||
if let Some(scenes) = scenes {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
|
@ -280,7 +274,7 @@ fn main() -> Result<()> {
|
|||
.with_title("Vello demo")
|
||||
.build(&event_loop)
|
||||
.unwrap();
|
||||
pollster::block_on(run(event_loop, window, args, base_color, scenes));
|
||||
pollster::block_on(run(event_loop, window, args, scenes));
|
||||
}
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
|
@ -300,7 +294,7 @@ fn main() -> Result<()> {
|
|||
.and_then(|doc| doc.body())
|
||||
.and_then(|body| body.append_child(&web_sys::Element::from(canvas)).ok())
|
||||
.expect("couldn't append canvas to document body");
|
||||
wasm_bindgen_futures::spawn_local(run(event_loop, window, args, base_color, scenes));
|
||||
wasm_bindgen_futures::spawn_local(run(event_loop, window, args, scenes));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
@ -114,8 +114,6 @@ impl Renderer {
|
|||
scene: &Scene,
|
||||
surface: &SurfaceTexture,
|
||||
params: &RenderParams,
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> Result<()> {
|
||||
let width = params.width;
|
||||
let height = params.height;
|
||||
|
|
Loading…
Reference in a new issue