dioxus/examples/window_zoom.rs

29 lines
737 B
Rust
Raw Normal View History

2024-02-14 20:33:07 +00:00
//! Adjust the zoom of a desktop app
//!
//! This example shows how to adjust the zoom of a desktop app using the webview.zoom method.
2022-05-11 16:03:42 +00:00
use dioxus::prelude::*;
fn main() {
launch_desktop(app);
2022-05-11 16:03:42 +00:00
}
fn app() -> Element {
let mut level = use_signal(|| 1.0);
2022-12-30 07:09:02 +00:00
2024-01-16 19:18:46 +00:00
rsx! {
2024-02-14 20:33:07 +00:00
h1 { "Zoom level: {level}" }
p { "Change the zoom level of the webview by typing a number in the input below."}
2022-05-11 16:03:42 +00:00
input {
r#type: "number",
2022-05-11 16:05:59 +00:00
value: "{level}",
2024-01-15 21:06:05 +00:00
oninput: move |e| {
2023-09-01 20:38:55 +00:00
if let Ok(new_zoom) = e.value().parse::<f64>() {
2022-12-30 07:32:53 +00:00
level.set(new_zoom);
2024-01-20 00:36:40 +00:00
dioxus::desktop::window().webview.zoom(new_zoom);
2022-12-30 07:32:53 +00:00
}
2022-05-11 16:03:42 +00:00
}
}
2024-01-14 05:12:21 +00:00
}
2022-05-11 16:03:42 +00:00
}