Commit e0fbf91e authored by Florian Blasius's avatar Florian Blasius 🤘

web: refactoring

parent 5e5c6244
Pipeline #9142 passed with stage
in 1 minute and 15 seconds
......@@ -50,6 +50,8 @@ features = [
"FocusEvent",
"DragEvent",
"DataTransfer",
"Navigator",
"Clipboard",
"DomRect"
]
......
......@@ -197,10 +197,13 @@ impl Window {
// }
pub fn clipboard(&self) -> String {
log("clipboard not yet implemented for web");
String::default()
}
pub fn set_clipboard(&mut self, text: &str) {}
pub fn set_clipboard(&mut self, _text: &str) {
log("set_clipboard not yet implemented for web");
}
/// Pops the content of the last drop event from the window.
pub fn pop_drop_content(&self) -> Option<String> {
......@@ -210,16 +213,22 @@ impl Window {
result
}
pub fn sync_path(&mut self) {}
pub fn sync_path(&mut self) {
self.x = self.canvas.offset_left();
self.y = self.canvas.offset_top();
self.w = self.canvas.width();
self.h = self.canvas.height();
if let Ok(document) = document() {
self.t = document.title();
}
}
/// Get x
// TODO: Sync with window movements
pub fn x(&self) -> i32 {
self.x
}
/// Get y
// TODO: Sync with window movements
pub fn y(&self) -> i32 {
self.y
}
......@@ -250,8 +259,6 @@ impl Window {
/// Set position
pub fn set_pos(&mut self, x: i32, y: i32) {
self.x = x;
self.y = y;
self.canvas
.style()
.set_property("left", x.to_string().as_str())
......@@ -260,14 +267,16 @@ impl Window {
.style()
.set_property("top", y.to_string().as_str())
.unwrap();
self.sync_path();
}
/// Set size
pub fn set_size(&mut self, width: u32, height: u32) {
self.w = width;
self.h = height;
self.canvas.set_width(width);
self.canvas.set_height(height);
self.sync_path();
}
/// Set title
......@@ -275,6 +284,7 @@ impl Window {
if let Ok(document) = document() {
document.set_title(title);
}
self.sync_path();
}
/// Blocking iterator over events
......@@ -285,7 +295,12 @@ impl Window {
count: 0,
};
let mut sync_path = false;
for event in self.events.borrow_mut().pop() {
match event.code {
EVENT_RESIZE | EVENT_MOVE => sync_path = true,
_ => {}
}
if iter.count < iter.events.len() {
iter.events[iter.count] = event;
iter.count += 1;
......@@ -294,6 +309,10 @@ impl Window {
}
}
if sync_path {
self.sync_path();
}
iter
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment