summaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-11-24 11:33:50 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-11-24 11:33:50 +0100
commit2b2a0f12c75032453fbefd2491d3ef51ff0ba88e (patch)
tree694fe37966ed62a42419ef64ac86e4a0de8b5c4c /web
parent9f3abe920271996cc4a9c533ad5e0e75e3d18a3d (diff)
downloadiced-2b2a0f12c75032453fbefd2491d3ef51ff0ba88e.tar.gz
iced-2b2a0f12c75032453fbefd2491d3ef51ff0ba88e.tar.bz2
iced-2b2a0f12c75032453fbefd2491d3ef51ff0ba88e.zip
Update document title properly in `iced_web`
Diffstat (limited to 'web')
-rw-r--r--web/src/lib.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/web/src/lib.rs b/web/src/lib.rs
index dd401c31..8239ffc9 100644
--- a/web/src/lib.rs
+++ b/web/src/lib.rs
@@ -143,7 +143,10 @@ pub trait Application {
instance.spawn(command);
let window = web_sys::window().unwrap();
+
let document = window.document().unwrap();
+ document.set_title(&instance.title);
+
let body = document.body().unwrap();
let vdom = dodrio::Vdom::new(&body, instance);
@@ -153,6 +156,7 @@ pub trait Application {
#[derive(Clone)]
struct Instance<Message> {
+ title: String,
ui: Rc<RefCell<Box<dyn Application<Message = Message>>>>,
}
@@ -162,14 +166,25 @@ where
{
fn new(ui: impl Application<Message = Message> + 'static) -> Self {
Self {
+ title: ui.title(),
ui: Rc::new(RefCell::new(Box::new(ui))),
}
}
fn update(&mut self, message: Message) {
let command = self.ui.borrow_mut().update(message);
+ let title = self.ui.borrow().title();
self.spawn(command);
+
+ let window = web_sys::window().unwrap();
+ let document = window.document().unwrap();
+
+ if self.title != title {
+ document.set_title(&title);
+
+ self.title = title;
+ }
}
fn spawn(&mut self, command: Command<Message>) {