S005: overlay layer, menu with submenu, modal dialog, toast stack
Menus, dialogs and toasts draw on an own full-window layer so they can play exit motion; gallery pages show them open for screenshots. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
parent
cc83e978c8
commit
c94b868b2e
1 changed files with 1071 additions and 40 deletions
|
|
@ -5,13 +5,14 @@ use std::process::ExitCode;
|
|||
|
||||
slint::include_modules!();
|
||||
|
||||
const USAGE: &str = "usage: tunal [--gallery] [--screenshot <png> [--dark] [--size WxH]]";
|
||||
const USAGE: &str =
|
||||
"usage: tunal [--gallery [--page menu|dialog]] [--screenshot <png> [--dark] [--size WxH]]";
|
||||
|
||||
fn main() -> ExitCode {
|
||||
let result = parse(std::env::args().skip(1)).and_then(|args| match args.screenshot {
|
||||
None if args.gallery => Gallery::new().and_then(run).map_err(|e| e.to_string()),
|
||||
None if args.gallery => gallery(args.page).and_then(run).map_err(|e| e.to_string()),
|
||||
None => MainWindow::new().and_then(run).map_err(|e| e.to_string()),
|
||||
Some(options) if args.gallery => screenshot::run(options, Gallery::new),
|
||||
Some(options) if args.gallery => screenshot::run(options, || gallery(args.page)),
|
||||
Some(options) => screenshot::run(options, MainWindow::new),
|
||||
});
|
||||
match result {
|
||||
|
|
@ -23,6 +24,13 @@ fn main() -> ExitCode {
|
|||
}
|
||||
}
|
||||
|
||||
fn gallery(page: GalleryPage) -> Result<Gallery, slint::PlatformError> {
|
||||
let ui = Gallery::new()?;
|
||||
ui.set_page(page);
|
||||
ui.invoke_stage();
|
||||
Ok(ui)
|
||||
}
|
||||
|
||||
fn run(ui: impl theme_bridge::Themed) -> Result<(), slint::PlatformError> {
|
||||
theme_bridge::start(&ui, theme_bridge::Overrides::from_env());
|
||||
ui.run()
|
||||
|
|
@ -30,11 +38,13 @@ fn run(ui: impl theme_bridge::Themed) -> Result<(), slint::PlatformError> {
|
|||
|
||||
struct Args {
|
||||
gallery: bool,
|
||||
page: GalleryPage,
|
||||
screenshot: Option<screenshot::Options>,
|
||||
}
|
||||
|
||||
fn parse(mut args: impl Iterator<Item = String>) -> Result<Args, String> {
|
||||
let mut gallery = false;
|
||||
let mut page = GalleryPage::Controls;
|
||||
let mut options = screenshot::Options {
|
||||
path: String::new(),
|
||||
dark: false,
|
||||
|
|
@ -43,23 +53,40 @@ fn parse(mut args: impl Iterator<Item = String>) -> Result<Args, String> {
|
|||
};
|
||||
let mut screenshot_flags = false;
|
||||
while let Some(arg) = args.next() {
|
||||
screenshot_flags |= arg != "--gallery";
|
||||
match arg.as_str() {
|
||||
"--gallery" => gallery = true,
|
||||
"--screenshot" => options.path = args.next().ok_or(USAGE)?,
|
||||
"--dark" => options.dark = true,
|
||||
"--page" => {
|
||||
page = match args.next().as_deref() {
|
||||
Some("menu") => GalleryPage::Menu,
|
||||
Some("dialog") => GalleryPage::Dialog,
|
||||
_ => return Err(USAGE.into()),
|
||||
}
|
||||
}
|
||||
"--screenshot" => {
|
||||
options.path = args.next().ok_or(USAGE)?;
|
||||
screenshot_flags = true;
|
||||
}
|
||||
"--dark" => {
|
||||
options.dark = true;
|
||||
screenshot_flags = true;
|
||||
}
|
||||
"--size" => {
|
||||
let size = args.next().ok_or(USAGE)?;
|
||||
let (w, h) = size.split_once('x').ok_or(USAGE)?;
|
||||
let parse = |n: &str| n.parse::<u32>().ok().filter(|&n| n > 0).ok_or(USAGE);
|
||||
options.size = (parse(w)?, parse(h)?);
|
||||
screenshot_flags = true;
|
||||
}
|
||||
_ => return Err(USAGE.into()),
|
||||
}
|
||||
}
|
||||
if page != GalleryPage::Controls && !gallery {
|
||||
return Err(USAGE.into());
|
||||
}
|
||||
if !screenshot_flags {
|
||||
return Ok(Args {
|
||||
gallery,
|
||||
page,
|
||||
screenshot: None,
|
||||
});
|
||||
}
|
||||
|
|
@ -69,6 +96,7 @@ fn parse(mut args: impl Iterator<Item = String>) -> Result<Args, String> {
|
|||
options.reduced_motion = gallery;
|
||||
Ok(Args {
|
||||
gallery,
|
||||
page,
|
||||
screenshot: Some(options),
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue