diff options
author | 2019-11-10 06:05:20 +0100 | |
---|---|---|
committer | 2019-11-11 03:08:00 +0100 | |
commit | 0240c3981b716c82ecb3364945815335b420a63e (patch) | |
tree | 441eebaa9441649a4e878bde71cdec20d4a67391 /native/src/user_interface.rs | |
parent | 2303111e09d806ef2a652bddc2b73be6dccf6ae2 (diff) | |
download | iced-0240c3981b716c82ecb3364945815335b420a63e.tar.gz iced-0240c3981b716c82ecb3364945815335b420a63e.tar.bz2 iced-0240c3981b716c82ecb3364945815335b420a63e.zip |
Draft custom layout engine based on `druid`
Diffstat (limited to 'native/src/user_interface.rs')
-rw-r--r-- | native/src/user_interface.rs | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/native/src/user_interface.rs b/native/src/user_interface.rs index 7c166094..4343086b 100644 --- a/native/src/user_interface.rs +++ b/native/src/user_interface.rs @@ -1,4 +1,4 @@ -use crate::{input::mouse, layout, Element, Event, Layout, Point, Rectangle}; +use crate::{input::mouse, layout, Element, Event, Layout, Point, Size}; use std::hash::Hasher; @@ -14,7 +14,7 @@ use std::hash::Hasher; pub struct UserInterface<'a, Message, Renderer> { hash: u64, root: Element<'a, Message, Renderer>, - layout: Layout, + layout: layout::Node, cursor_position: Point, } @@ -109,7 +109,11 @@ where let layout = if hash == cache.hash { cache.layout } else { - root.layout(renderer, &layout::Limits::NONE) + let layout_start = std::time::Instant::now(); + let layout = root.layout(renderer, &layout::Limits::NONE); + dbg!(std::time::Instant::now() - layout_start); + + layout }; UserInterface { @@ -209,7 +213,7 @@ where self.root.widget.on_event( event, - &self.layout, + Layout::new(&self.layout), self.cursor_position, &mut messages, renderer, @@ -298,9 +302,11 @@ where /// } /// ``` pub fn draw(&self, renderer: &mut Renderer) -> Renderer::Output { - self.root - .widget - .draw(renderer, &self.layout, self.cursor_position) + self.root.widget.draw( + renderer, + Layout::new(&self.layout), + self.cursor_position, + ) } /// Extract the [`Cache`] of the [`UserInterface`], consuming it in the @@ -323,7 +329,7 @@ where #[derive(Debug, Clone)] pub struct Cache { hash: u64, - layout: Layout, + layout: layout::Node, cursor_position: Point, } @@ -338,12 +344,7 @@ impl Cache { pub fn new() -> Cache { Cache { hash: 0, - layout: Layout::new(Rectangle { - x: 0.0, - y: 0.0, - width: 0.0, - height: 0.0, - }), + layout: layout::Node::new(Size::new(0.0, 0.0)), cursor_position: Point::new(-1.0, -1.0), } } |