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 {
|
let render_params = vello::RenderParams {
|
||||||
base_color: args
|
base_color: args
|
||||||
.args
|
.args
|
||||||
.get_base_color()?
|
.base_color
|
||||||
.or(scene_params.base_color)
|
.or(scene_params.base_color)
|
||||||
.unwrap_or(vello::peniko::Color::BLACK),
|
.unwrap_or(vello::peniko::Color::BLACK),
|
||||||
width,
|
width,
|
||||||
|
|
|
@ -48,11 +48,11 @@ pub struct Arguments {
|
||||||
/// The svg files paths to render
|
/// The svg files paths to render
|
||||||
svgs: Option<Vec<PathBuf>>,
|
svgs: Option<Vec<PathBuf>>,
|
||||||
#[arg(help_heading = "Render Parameters")]
|
#[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.
|
/// The base color applied as the blend background to the rasterizer.
|
||||||
/// Format is CSS style hexidecimal (#RGB, #RGBA, #RRGGBB, #RRGGBBAA) or
|
/// Format is CSS style hexidecimal (#RGB, #RGBA, #RRGGBB, #RRGGBBAA) or
|
||||||
/// an SVG color name such as "aliceblue"
|
/// an SVG color name such as "aliceblue"
|
||||||
base_color: Option<String>,
|
pub base_color: Option<Color>,
|
||||||
#[clap(subcommand)]
|
#[clap(subcommand)]
|
||||||
command: Option<Command>,
|
command: Option<Command>,
|
||||||
}
|
}
|
||||||
|
@ -86,17 +86,6 @@ impl Arguments {
|
||||||
.map(Some)
|
.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 {
|
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
|
/// Switch between scenes with left and right arrow keys
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
scene: Option<i32>,
|
scene: Option<i32>,
|
||||||
/// The base color used as the
|
|
||||||
#[command(flatten)]
|
#[command(flatten)]
|
||||||
args: scenes::Arguments,
|
args: scenes::Arguments,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn run(
|
async fn run(event_loop: EventLoop<UserEvent>, window: Window, args: Args, mut scenes: SceneSet) {
|
||||||
event_loop: EventLoop<UserEvent>,
|
|
||||||
window: Window,
|
|
||||||
args: Args,
|
|
||||||
base_color_arg: Option<Color>,
|
|
||||||
mut scenes: SceneSet,
|
|
||||||
) {
|
|
||||||
use winit::{event::*, event_loop::ControlFlow};
|
use winit::{event::*, event_loop::ControlFlow};
|
||||||
let mut render_cx = RenderContext::new().unwrap();
|
let mut render_cx = RenderContext::new().unwrap();
|
||||||
let size = window.inner_size();
|
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
|
// 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.
|
// color specified by the scene. The default is black.
|
||||||
let render_params = vello::RenderParams {
|
let render_params = vello::RenderParams {
|
||||||
base_color: base_color_arg
|
base_color: args
|
||||||
|
.args
|
||||||
|
.base_color
|
||||||
.or(scene_params.base_color)
|
.or(scene_params.base_color)
|
||||||
.unwrap_or(Color::BLACK),
|
.unwrap_or(Color::BLACK),
|
||||||
width,
|
width,
|
||||||
|
@ -262,7 +257,6 @@ fn main() -> Result<()> {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
let scenes = args.args.select_scene_set(|| Args::command())?;
|
let scenes = args.args.select_scene_set(|| Args::command())?;
|
||||||
let base_color = args.args.get_base_color()?;
|
|
||||||
if let Some(scenes) = scenes {
|
if let Some(scenes) = scenes {
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
{
|
{
|
||||||
|
@ -280,7 +274,7 @@ fn main() -> Result<()> {
|
||||||
.with_title("Vello demo")
|
.with_title("Vello demo")
|
||||||
.build(&event_loop)
|
.build(&event_loop)
|
||||||
.unwrap();
|
.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")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
{
|
{
|
||||||
|
@ -300,7 +294,7 @@ fn main() -> Result<()> {
|
||||||
.and_then(|doc| doc.body())
|
.and_then(|doc| doc.body())
|
||||||
.and_then(|body| body.append_child(&web_sys::Element::from(canvas)).ok())
|
.and_then(|body| body.append_child(&web_sys::Element::from(canvas)).ok())
|
||||||
.expect("couldn't append canvas to document body");
|
.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(())
|
Ok(())
|
||||||
|
|
|
@ -114,8 +114,6 @@ impl Renderer {
|
||||||
scene: &Scene,
|
scene: &Scene,
|
||||||
surface: &SurfaceTexture,
|
surface: &SurfaceTexture,
|
||||||
params: &RenderParams,
|
params: &RenderParams,
|
||||||
width: u32,
|
|
||||||
height: u32,
|
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let width = params.width;
|
let width = params.width;
|
||||||
let height = params.height;
|
let height = params.height;
|
||||||
|
|
Loading…
Reference in a new issue