slint/tools/viewer/main.rs
Simon Hausmann c258a907f0 Simplify event loop start-up
Move the layout constraint tracker into the window where we can apply
the constraints right before drawing, instead of doing that from within
the event loop. This allows to remove the component parameter from the
run function.
2020-11-12 15:04:48 +01:00

49 lines
1.5 KiB
Rust

/* LICENSE BEGIN
This file is part of the SixtyFPS Project -- https://sixtyfps.io
Copyright (c) 2020 Olivier Goffart <olivier.goffart@sixtyfps.io>
Copyright (c) 2020 Simon Hausmann <simon.hausmann@sixtyfps.io>
SPDX-License-Identifier: GPL-3.0-only
This file is also available under commercial licensing terms.
Please contact info@sixtyfps.io for more information.
LICENSE END */
use structopt::StructOpt;
#[derive(StructOpt)]
struct Cli {
#[structopt(short = "I", name = "include path for other .60 files", number_of_values = 1)]
include_paths: Vec<std::path::PathBuf>,
#[structopt(name = "path to .60 file", parse(from_os_str))]
path: std::path::PathBuf,
/// The style name (empty, or 'qt')
#[structopt(long, name = "style name", default_value)]
style: String,
}
fn main() -> std::io::Result<()> {
let args = Cli::from_args();
let source = std::fs::read_to_string(&args.path)?;
let compiler_config = sixtyfps_compilerlib::CompilerConfiguration {
include_paths: args.include_paths,
style: if args.style.is_empty() { None } else { Some(args.style) },
..Default::default()
};
let c = match spin_on::spin_on(sixtyfps_interpreter::load(source, args.path, compiler_config)) {
(Ok(c), warnings) => {
warnings.print();
c
}
(Err(()), errors) => {
errors.print();
std::process::exit(-1);
}
};
let component = c.create();
component.window().run();
Ok(())
}