diff options
author | 2019-11-10 01:55:32 +0100 | |
---|---|---|
committer | 2019-11-10 01:55:32 +0100 | |
commit | 2303111e09d806ef2a652bddc2b73be6dccf6ae2 (patch) | |
tree | ba57c5a2fe67d8a58d4f9b32c2b32fee32932f06 /wgpu | |
parent | 839e039dbf2fb89dcb8c141503740777d2af2eb3 (diff) | |
download | iced-2303111e09d806ef2a652bddc2b73be6dccf6ae2.tar.gz iced-2303111e09d806ef2a652bddc2b73be6dccf6ae2.tar.bz2 iced-2303111e09d806ef2a652bddc2b73be6dccf6ae2.zip |
Draft new layout API
Diffstat (limited to 'wgpu')
-rw-r--r-- | wgpu/src/renderer.rs | 4 | ||||
-rw-r--r-- | wgpu/src/renderer/widget/button.rs | 26 | ||||
-rw-r--r-- | wgpu/src/renderer/widget/checkbox.rs | 31 | ||||
-rw-r--r-- | wgpu/src/renderer/widget/column.rs | 2 | ||||
-rw-r--r-- | wgpu/src/renderer/widget/image.rs | 30 | ||||
-rw-r--r-- | wgpu/src/renderer/widget/radio.rs | 29 | ||||
-rw-r--r-- | wgpu/src/renderer/widget/row.rs | 2 | ||||
-rw-r--r-- | wgpu/src/renderer/widget/scrollable.rs | 6 | ||||
-rw-r--r-- | wgpu/src/renderer/widget/slider.rs | 25 | ||||
-rw-r--r-- | wgpu/src/renderer/widget/text.rs | 71 |
10 files changed, 86 insertions, 140 deletions
diff --git a/wgpu/src/renderer.rs b/wgpu/src/renderer.rs index 235eefc6..664853ba 100644 --- a/wgpu/src/renderer.rs +++ b/wgpu/src/renderer.rs @@ -423,7 +423,7 @@ impl Debugger for Renderer { fn explain<Message>( &mut self, widget: &dyn Widget<Message, Self>, - layout: Layout<'_>, + layout: &Layout, cursor_position: Point, color: Color, ) -> Self::Output { @@ -438,7 +438,7 @@ impl Debugger for Renderer { } fn explain_layout( - layout: Layout, + layout: &Layout, color: Color, primitives: &mut Vec<Primitive>, ) { diff --git a/wgpu/src/renderer/widget/button.rs b/wgpu/src/renderer/widget/button.rs index 0ac1c0a6..e8a97385 100644 --- a/wgpu/src/renderer/widget/button.rs +++ b/wgpu/src/renderer/widget/button.rs @@ -1,25 +1,27 @@ use crate::{Primitive, Renderer}; use iced_native::{ - button, Align, Background, Button, Layout, Length, MouseCursor, - Node, Point, Rectangle, Style, + button, layout, Background, Button, Layout, MouseCursor, Point, Rectangle, }; impl button::Renderer for Renderer { - fn node<Message>(&self, button: &Button<Message, Self>) -> Node { - let style = Style::default() - .width(button.width) - .padding(button.padding) - .min_width(Length::Units(100)) - .align_self(button.align_self) - .align_items(Align::Stretch); - - Node::with_children(style, vec![button.content.node(self)]) + fn layout<Message>( + &self, + button: &Button<Message, Self>, + limits: &layout::Limits, + ) -> Layout { + // TODO + Layout::new(Rectangle { + x: 0.0, + y: 0.0, + width: 0.0, + height: 0.0, + }) } fn draw<Message>( &mut self, button: &Button<Message, Self>, - layout: Layout<'_>, + layout: &Layout, cursor_position: Point, ) -> Self::Output { let bounds = layout.bounds(); diff --git a/wgpu/src/renderer/widget/checkbox.rs b/wgpu/src/renderer/widget/checkbox.rs index 1594c769..de921e6b 100644 --- a/wgpu/src/renderer/widget/checkbox.rs +++ b/wgpu/src/renderer/widget/checkbox.rs @@ -1,31 +1,30 @@ use crate::{Primitive, Renderer}; use iced_native::{ - checkbox, text, text::HorizontalAlignment, text::VerticalAlignment, Align, - Background, Checkbox, Column, Layout, Length, MouseCursor, Node, - Point, Rectangle, Row, Text, Widget, + checkbox, layout, text, text::HorizontalAlignment, text::VerticalAlignment, + Background, Checkbox, Layout, MouseCursor, Point, Rectangle, Text, }; const SIZE: f32 = 28.0; impl checkbox::Renderer for Renderer { - fn node<Message>(&self, checkbox: &Checkbox<Message>) -> Node { - Row::<(), Self>::new() - .width(Length::Fill) - .spacing(15) - .align_items(Align::Center) - .push( - Column::new() - .width(Length::Units(SIZE as u16)) - .height(Length::Units(SIZE as u16)), - ) - .push(Text::new(&checkbox.label)) - .node(self) + fn layout<Message>( + &self, + checkbox: &Checkbox<Message>, + limits: &layout::Limits, + ) -> Layout { + // TODO + Layout::new(Rectangle { + x: 0.0, + y: 0.0, + width: 0.0, + height: 0.0, + }) } fn draw<Message>( &mut self, checkbox: &Checkbox<Message>, - layout: Layout<'_>, + layout: &Layout, cursor_position: Point, ) -> Self::Output { let bounds = layout.bounds(); diff --git a/wgpu/src/renderer/widget/column.rs b/wgpu/src/renderer/widget/column.rs index cac6da77..6355f000 100644 --- a/wgpu/src/renderer/widget/column.rs +++ b/wgpu/src/renderer/widget/column.rs @@ -5,7 +5,7 @@ impl column::Renderer for Renderer { fn draw<Message>( &mut self, column: &Column<'_, Message, Self>, - layout: Layout<'_>, + layout: &Layout, cursor_position: Point, ) -> Self::Output { let mut mouse_cursor = MouseCursor::OutOfBounds; diff --git a/wgpu/src/renderer/widget/image.rs b/wgpu/src/renderer/widget/image.rs index 0e312706..ea9d19c7 100644 --- a/wgpu/src/renderer/widget/image.rs +++ b/wgpu/src/renderer/widget/image.rs @@ -1,28 +1,18 @@ use crate::{Primitive, Renderer}; -use iced_native::{image, Image, Layout, Length, MouseCursor, Node, Style}; +use iced_native::{image, layout, Image, Layout, MouseCursor, Rectangle}; impl image::Renderer for Renderer { - fn node(&self, image: &Image) -> Node { - let (width, height) = self.image_pipeline.dimensions(&image.path); - - let aspect_ratio = width as f32 / height as f32; - - let mut style = Style::default().align_self(image.align_self); - - // TODO: Deal with additional cases - style = match (image.width, image.height) { - (Length::Units(width), _) => style.width(image.width).height( - Length::Units((width as f32 / aspect_ratio).round() as u16), - ), - (_, _) => style - .width(Length::Units(width as u16)) - .height(Length::Units(height as u16)), - }; - - Node::new(style) + fn layout(&self, image: &Image, limits: &layout::Limits) -> Layout { + // TODO + Layout::new(Rectangle { + x: 0.0, + y: 0.0, + width: 0.0, + height: 0.0, + }) } - fn draw(&mut self, image: &Image, layout: Layout<'_>) -> Self::Output { + fn draw(&mut self, image: &Image, layout: &Layout) -> Self::Output { ( Primitive::Image { path: image.path.clone(), diff --git a/wgpu/src/renderer/widget/radio.rs b/wgpu/src/renderer/widget/radio.rs index 61f5ce47..9f3c528f 100644 --- a/wgpu/src/renderer/widget/radio.rs +++ b/wgpu/src/renderer/widget/radio.rs @@ -1,30 +1,31 @@ use crate::{Primitive, Renderer}; use iced_native::{ - radio, text, Align, Background, Column, Layout, Length, MouseCursor, - Node, Point, Radio, Rectangle, Row, Text, Widget, + layout, radio, text, Background, Layout, MouseCursor, Point, Radio, + Rectangle, Text, }; const SIZE: f32 = 28.0; const DOT_SIZE: f32 = SIZE / 2.0; impl radio::Renderer for Renderer { - fn node<Message>(&self, radio: &Radio<Message>) -> Node { - Row::<(), Self>::new() - .spacing(15) - .align_items(Align::Center) - .push( - Column::new() - .width(Length::Units(SIZE as u16)) - .height(Length::Units(SIZE as u16)), - ) - .push(Text::new(&radio.label)) - .node(self) + fn layout<Message>( + &self, + radio: &Radio<Message>, + limits: &layout::Limits, + ) -> Layout { + // TODO + Layout::new(Rectangle { + x: 0.0, + y: 0.0, + width: 0.0, + height: 0.0, + }) } fn draw<Message>( &mut self, radio: &Radio<Message>, - layout: Layout<'_>, + layout: &Layout, cursor_position: Point, ) -> Self::Output { let bounds = layout.bounds(); diff --git a/wgpu/src/renderer/widget/row.rs b/wgpu/src/renderer/widget/row.rs index bbfef9a1..4f7cb10e 100644 --- a/wgpu/src/renderer/widget/row.rs +++ b/wgpu/src/renderer/widget/row.rs @@ -5,7 +5,7 @@ impl row::Renderer for Renderer { fn draw<Message>( &mut self, row: &Row<'_, Message, Self>, - layout: Layout<'_>, + layout: &Layout, cursor_position: Point, ) -> Self::Output { let mut mouse_cursor = MouseCursor::OutOfBounds; diff --git a/wgpu/src/renderer/widget/scrollable.rs b/wgpu/src/renderer/widget/scrollable.rs index 5eadf275..4b318d6d 100644 --- a/wgpu/src/renderer/widget/scrollable.rs +++ b/wgpu/src/renderer/widget/scrollable.rs @@ -1,7 +1,7 @@ use crate::{Primitive, Renderer}; use iced_native::{ - scrollable, Background, Layout, MouseCursor, Point, Rectangle, - Scrollable, Vector, Widget, + scrollable, Background, Layout, MouseCursor, Point, Rectangle, Scrollable, + Vector, Widget, }; const SCROLLBAR_WIDTH: u16 = 10; @@ -32,7 +32,7 @@ impl scrollable::Renderer for Renderer { &mut self, scrollable: &Scrollable<'_, Message, Self>, bounds: Rectangle, - content: Layout<'_>, + content: &Layout, cursor_position: Point, ) -> Self::Output { let is_mouse_over = bounds.contains(cursor_position); diff --git a/wgpu/src/renderer/widget/slider.rs b/wgpu/src/renderer/widget/slider.rs index 789e7bd4..a3423785 100644 --- a/wgpu/src/renderer/widget/slider.rs +++ b/wgpu/src/renderer/widget/slider.rs @@ -1,26 +1,31 @@ use crate::{Primitive, Renderer}; use iced_native::{ - slider, Background, Color, Layout, Length, MouseCursor, Node, Point, - Rectangle, Slider, Style, + layout, slider, Background, Color, Layout, MouseCursor, Point, Rectangle, + Slider, }; const HANDLE_WIDTH: f32 = 8.0; const HANDLE_HEIGHT: f32 = 22.0; impl slider::Renderer for Renderer { - fn node<Message>(&self, slider: &Slider<Message>) -> Node { - let style = Style::default() - .width(slider.width) - .height(Length::Units(HANDLE_HEIGHT as u16)) - .min_width(Length::Units(100)); - - Node::new(style) + fn layout<Message>( + &self, + slider: &Slider<Message>, + limits: &layout::Limits, + ) -> Layout { + // TODO + Layout::new(Rectangle { + x: 0.0, + y: 0.0, + width: 0.0, + height: 0.0, + }) } fn draw<Message>( &mut self, slider: &Slider<Message>, - layout: Layout<'_>, + layout: &Layout, cursor_position: Point, ) -> Self::Output { let bounds = layout.bounds(); diff --git a/wgpu/src/renderer/widget/text.rs b/wgpu/src/renderer/widget/text.rs index 29e07ff7..d824c07c 100644 --- a/wgpu/src/renderer/widget/text.rs +++ b/wgpu/src/renderer/widget/text.rs @@ -1,76 +1,25 @@ use crate::{Primitive, Renderer}; -use iced_native::{text, Color, Layout, MouseCursor, Node, Style, Text}; +use iced_native::{layout, text, Color, Layout, MouseCursor, Rectangle, Text}; -use wgpu_glyph::{GlyphCruncher, Section}; +//use wgpu_glyph::{GlyphCruncher, Section}; -use std::cell::RefCell; use std::f32; // TODO: Obtain from renderer configuration const DEFAULT_TEXT_SIZE: f32 = 20.0; impl text::Renderer for Renderer { - fn node(&self, text: &Text) -> Node { - let glyph_brush = self.glyph_brush.clone(); - let content = text.content.clone(); - - // TODO: Investigate why stretch tries to measure this MANY times - // with every ancestor's bounds. - // Bug? Using the library wrong? I should probably open an issue on - // the stretch repository. - // I noticed that the first measure is the one that matters in - // practice. Here, we use a RefCell to store the cached measurement. - let measure = RefCell::new(None); - let size = text.size.map(f32::from).unwrap_or(DEFAULT_TEXT_SIZE); - - let style = Style::default().width(text.width); - - iced_native::Node::with_measure(style, move |bounds| { - let mut measure = measure.borrow_mut(); - - if measure.is_none() { - let bounds = ( - match bounds.width { - iced_native::Number::Undefined => f32::INFINITY, - iced_native::Number::Defined(w) => w, - }, - match bounds.height { - iced_native::Number::Undefined => f32::INFINITY, - iced_native::Number::Defined(h) => h, - }, - ); - - let text = Section { - text: &content, - scale: wgpu_glyph::Scale { x: size, y: size }, - bounds, - ..Default::default() - }; - - let (width, height) = if let Some(bounds) = - glyph_brush.borrow_mut().glyph_bounds(&text) - { - (bounds.width().ceil(), bounds.height().ceil()) - } else { - (0.0, 0.0) - }; - - let size = iced_native::Size { width, height }; - - // If the text has no width boundary we avoid caching as the - // layout engine may just be measuring text in a row. - if bounds.0 == f32::INFINITY { - return size; - } else { - *measure = Some(size); - } - } - - measure.unwrap() + fn layout(&self, text: &Text, limits: &layout::Limits) -> Layout { + // TODO + Layout::new(Rectangle { + x: 0.0, + y: 0.0, + width: 0.0, + height: 0.0, }) } - fn draw(&mut self, text: &Text, layout: Layout<'_>) -> Self::Output { + fn draw(&mut self, text: &Text, layout: &Layout) -> Self::Output { ( Primitive::Text { content: text.content.clone(), |