summaryrefslogtreecommitdiffstats
path: root/wgpu/src/widget
diff options
context:
space:
mode:
Diffstat (limited to 'wgpu/src/widget')
-rw-r--r--wgpu/src/widget/button.rs5
-rw-r--r--wgpu/src/widget/canvas.rs147
-rw-r--r--wgpu/src/widget/canvas/drawable.rs12
-rw-r--r--wgpu/src/widget/canvas/fill.rs14
-rw-r--r--wgpu/src/widget/canvas/frame.rs310
-rw-r--r--wgpu/src/widget/canvas/layer.rs25
-rw-r--r--wgpu/src/widget/canvas/layer/cache.rs99
-rw-r--r--wgpu/src/widget/canvas/path.rs49
-rw-r--r--wgpu/src/widget/canvas/path/arc.rs44
-rw-r--r--wgpu/src/widget/canvas/path/builder.rs177
-rw-r--r--wgpu/src/widget/canvas/stroke.rs83
-rw-r--r--wgpu/src/widget/canvas/text.rs34
-rw-r--r--wgpu/src/widget/checkbox.rs2
-rw-r--r--wgpu/src/widget/container.rs2
-rw-r--r--wgpu/src/widget/pane_grid.rs31
-rw-r--r--wgpu/src/widget/pick_list.rs9
-rw-r--r--wgpu/src/widget/progress_bar.rs10
-rw-r--r--wgpu/src/widget/qr_code.rs2
-rw-r--r--wgpu/src/widget/radio.rs2
-rw-r--r--wgpu/src/widget/rule.rs10
-rw-r--r--wgpu/src/widget/scrollable.rs2
-rw-r--r--wgpu/src/widget/slider.rs7
-rw-r--r--wgpu/src/widget/text_input.rs5
23 files changed, 65 insertions, 1016 deletions
diff --git a/wgpu/src/widget/button.rs b/wgpu/src/widget/button.rs
index b738c55e..fc729cd5 100644
--- a/wgpu/src/widget/button.rs
+++ b/wgpu/src/widget/button.rs
@@ -1,13 +1,10 @@
//! Allow your users to perform actions by pressing a button.
//!
//! A [`Button`] has some local [`State`].
-//!
-//! [`Button`]: type.Button.html
-//! [`State`]: struct.State.html
use crate::Renderer;
+pub use iced_graphics::button::{Style, StyleSheet};
pub use iced_native::button::State;
-pub use iced_style::button::{Style, StyleSheet};
/// A widget that produces a message when clicked.
///
diff --git a/wgpu/src/widget/canvas.rs b/wgpu/src/widget/canvas.rs
index 3a9605c9..399dd19c 100644
--- a/wgpu/src/widget/canvas.rs
+++ b/wgpu/src/widget/canvas.rs
@@ -3,149 +3,4 @@
//! A [`Canvas`] widget can be used to draw different kinds of 2D shapes in a
//! [`Frame`]. It can be used for animation, data visualization, game graphics,
//! and more!
-//!
-//! [`Canvas`]: struct.Canvas.html
-//! [`Frame`]: struct.Frame.html
-use crate::{Defaults, Primitive, Renderer};
-
-use iced_native::{
- layout, Element, Hasher, Layout, Length, MouseCursor, Point, Size, Widget,
-};
-use std::hash::Hash;
-
-pub mod layer;
-pub mod path;
-
-mod drawable;
-mod fill;
-mod frame;
-mod stroke;
-mod text;
-
-pub use drawable::Drawable;
-pub use fill::Fill;
-pub use frame::Frame;
-pub use layer::Layer;
-pub use path::Path;
-pub use stroke::{LineCap, LineJoin, Stroke};
-pub use text::Text;
-
-/// A widget capable of drawing 2D graphics.
-///
-/// A [`Canvas`] may contain multiple layers. A [`Layer`] is drawn using the
-/// painter's algorithm. In other words, layers will be drawn on top of each in
-/// the same order they are pushed into the [`Canvas`].
-///
-/// [`Canvas`]: struct.Canvas.html
-/// [`Layer`]: layer/trait.Layer.html
-#[derive(Debug)]
-pub struct Canvas<'a> {
- width: Length,
- height: Length,
- layers: Vec<Box<dyn Layer + 'a>>,
-}
-
-impl<'a> Canvas<'a> {
- const DEFAULT_SIZE: u16 = 100;
-
- /// Creates a new [`Canvas`] with no layers.
- ///
- /// [`Canvas`]: struct.Canvas.html
- pub fn new() -> Self {
- Canvas {
- width: Length::Units(Self::DEFAULT_SIZE),
- height: Length::Units(Self::DEFAULT_SIZE),
- layers: Vec::new(),
- }
- }
-
- /// Sets the width of the [`Canvas`].
- ///
- /// [`Canvas`]: struct.Canvas.html
- pub fn width(mut self, width: Length) -> Self {
- self.width = width;
- self
- }
-
- /// Sets the height of the [`Canvas`].
- ///
- /// [`Canvas`]: struct.Canvas.html
- pub fn height(mut self, height: Length) -> Self {
- self.height = height;
- self
- }
-
- /// Adds a [`Layer`] to the [`Canvas`].
- ///
- /// It will be drawn on top of previous layers.
- ///
- /// [`Layer`]: layer/trait.Layer.html
- /// [`Canvas`]: struct.Canvas.html
- pub fn push(mut self, layer: impl Layer + 'a) -> Self {
- self.layers.push(Box::new(layer));
- self
- }
-}
-
-impl<'a, Message> Widget<Message, Renderer> for Canvas<'a> {
- fn width(&self) -> Length {
- self.width
- }
-
- fn height(&self) -> Length {
- self.height
- }
-
- fn layout(
- &self,
- _renderer: &Renderer,
- limits: &layout::Limits,
- ) -> layout::Node {
- let limits = limits.width(self.width).height(self.height);
- let size = limits.resolve(Size::ZERO);
-
- layout::Node::new(size)
- }
-
- fn draw(
- &self,
- _renderer: &mut Renderer,
- _defaults: &Defaults,
- layout: Layout<'_>,
- _cursor_position: Point,
- ) -> (Primitive, MouseCursor) {
- let bounds = layout.bounds();
- let origin = Point::new(bounds.x, bounds.y);
- let size = Size::new(bounds.width, bounds.height);
-
- (
- Primitive::Group {
- primitives: self
- .layers
- .iter()
- .map(|layer| Primitive::Cached {
- origin,
- cache: layer.draw(size),
- })
- .collect(),
- },
- MouseCursor::Idle,
- )
- }
-
- fn hash_layout(&self, state: &mut Hasher) {
- std::any::TypeId::of::<Canvas<'static>>().hash(state);
-
- self.width.hash(state);
- self.height.hash(state);
- }
-}
-
-impl<'a, Message> From<Canvas<'a>> for Element<'a, Message, Renderer>
-where
- Message: 'static,
-{
- fn from(canvas: Canvas<'a>) -> Element<'a, Message, Renderer> {
- Element::new(canvas)
- }
-}
+pub use iced_graphics::canvas::*;
diff --git a/wgpu/src/widget/canvas/drawable.rs b/wgpu/src/widget/canvas/drawable.rs
deleted file mode 100644
index 6c74071c..00000000
--- a/wgpu/src/widget/canvas/drawable.rs
+++ /dev/null
@@ -1,12 +0,0 @@
-use crate::canvas::Frame;
-
-/// A type that can be drawn on a [`Frame`].
-///
-/// [`Frame`]: struct.Frame.html
-pub trait Drawable {
- /// Draws the [`Drawable`] on the given [`Frame`].
- ///
- /// [`Drawable`]: trait.Drawable.html
- /// [`Frame`]: struct.Frame.html
- fn draw(&self, frame: &mut Frame);
-}
diff --git a/wgpu/src/widget/canvas/fill.rs b/wgpu/src/widget/canvas/fill.rs
deleted file mode 100644
index 5ce24cf3..00000000
--- a/wgpu/src/widget/canvas/fill.rs
+++ /dev/null
@@ -1,14 +0,0 @@
-use iced_native::Color;
-
-/// The style used to fill geometry.
-#[derive(Debug, Clone, Copy)]
-pub enum Fill {
- /// Fill with a color.
- Color(Color),
-}
-
-impl Default for Fill {
- fn default() -> Fill {
- Fill::Color(Color::BLACK)
- }
-}
diff --git a/wgpu/src/widget/canvas/frame.rs b/wgpu/src/widget/canvas/frame.rs
deleted file mode 100644
index 7d7ce06a..00000000
--- a/wgpu/src/widget/canvas/frame.rs
+++ /dev/null
@@ -1,310 +0,0 @@
-use iced_native::{Point, Rectangle, Size, Vector};
-
-use crate::{
- canvas::{Fill, Path, Stroke, Text},
- triangle, Primitive,
-};
-
-/// The frame of a [`Canvas`].
-///
-/// [`Canvas`]: struct.Canvas.html
-#[derive(Debug)]
-pub struct Frame {
- width: f32,
- height: f32,
- buffers: lyon::tessellation::VertexBuffers<triangle::Vertex2D, u32>,
- primitives: Vec<Primitive>,
- transforms: Transforms,
-}
-
-#[derive(Debug)]
-struct Transforms {
- previous: Vec<Transform>,
- current: Transform,
-}
-
-#[derive(Debug, Clone, Copy)]
-struct Transform {
- raw: lyon::math::Transform,
- is_identity: bool,
-}
-
-impl Frame {
- /// Creates a new empty [`Frame`] with the given dimensions.
- ///
- /// The default coordinate system of a [`Frame`] has its origin at the
- /// top-left corner of its bounds.
- ///
- /// [`Frame`]: struct.Frame.html
- pub fn new(width: f32, height: f32) -> Frame {
- Frame {
- width,
- height,
- buffers: lyon::tessellation::VertexBuffers::new(),
- primitives: Vec::new(),
- transforms: Transforms {
- previous: Vec::new(),
- current: Transform {
- raw: lyon::math::Transform::identity(),
- is_identity: true,
- },
- },
- }
- }
-
- /// Returns the width of the [`Frame`].
- ///
- /// [`Frame`]: struct.Frame.html
- #[inline]
- pub fn width(&self) -> f32 {
- self.width
- }
-
- /// Returns the width of the [`Frame`].
- ///
- /// [`Frame`]: struct.Frame.html
- #[inline]
- pub fn height(&self) -> f32 {
- self.height
- }
-
- /// Returns the dimensions of the [`Frame`].
- ///
- /// [`Frame`]: struct.Frame.html
- #[inline]
- pub fn size(&self) -> Size {
- Size::new(self.width, self.height)
- }
-
- /// Returns the coordinate of the center of the [`Frame`].
- ///
- /// [`Frame`]: struct.Frame.html
- #[inline]
- pub fn center(&self) -> Point {
- Point::new(self.width / 2.0, self.height / 2.0)
- }
-
- /// Draws the given [`Path`] on the [`Frame`] by filling it with the
- /// provided style.
- ///
- /// [`Path`]: path/struct.Path.html
- /// [`Frame`]: struct.Frame.html
- pub fn fill(&mut self, path: &Path, fill: Fill) {
- use lyon::tessellation::{
- BuffersBuilder, FillOptions, FillTessellator,
- };
-
- let mut buffers = BuffersBuilder::new(
- &mut self.buffers,
- FillVertex(match fill {
- Fill::Color(color) => color.into_linear(),
- }),
- );
-
- let mut tessellator = FillTessellator::new();
-
- let result = if self.transforms.current.is_identity {
- tessellator.tessellate_path(
- path.raw(),
- &FillOptions::default(),
- &mut buffers,
- )
- } else {
- let path = path.transformed(&self.transforms.current.raw);
-
- tessellator.tessellate_path(
- path.raw(),
- &FillOptions::default(),
- &mut buffers,
- )
- };
-
- let _ = result.expect("Tessellate path");
- }
-
- /// Draws the stroke of the given [`Path`] on the [`Frame`] with the
- /// provided style.
- ///
- /// [`Path`]: path/struct.Path.html
- /// [`Frame`]: struct.Frame.html
- pub fn stroke(&mut self, path: &Path, stroke: Stroke) {
- use lyon::tessellation::{
- BuffersBuilder, StrokeOptions, StrokeTessellator,
- };
-
- let mut buffers = BuffersBuilder::new(
- &mut self.buffers,
- StrokeVertex(stroke.color.into_linear()),
- );
-
- let mut tessellator = StrokeTessellator::new();
-
- let mut options = StrokeOptions::default();
- options.line_width = stroke.width;
- options.start_cap = stroke.line_cap.into();
- options.end_cap = stroke.line_cap.into();
- options.line_join = stroke.line_join.into();
-
- let result = if self.transforms.current.is_identity {
- tessellator.tessellate_path(path.raw(), &options, &mut buffers)
- } else {
- let path = path.transformed(&self.transforms.current.raw);
-
- tessellator.tessellate_path(path.raw(), &options, &mut buffers)
- };
-
- let _ = result.expect("Stroke path");
- }
-
- /// Draws the characters of the given [`Text`] on the [`Frame`], filling
- /// them with the given color.
- ///
- /// __Warning:__ Text currently does not work well with rotations and scale
- /// transforms! The position will be correctly transformed, but the
- /// resulting glyphs will not be rotated or scaled properly.
- ///
- /// Additionally, all text will be rendered on top of all the layers of
- /// a [`Canvas`]. Therefore, it is currently only meant to be used for
- /// overlays, which is the most common use case.
- ///
- /// Support for vectorial text is planned, and should address all these
- /// limitations.
- ///
- /// [`Text`]: struct.Text.html
- /// [`Frame`]: struct.Frame.html
- pub fn fill_text(&mut self, text: Text) {
- use std::f32;
-
- let position = if self.transforms.current.is_identity {
- text.position
- } else {
- let transformed = self.transforms.current.raw.transform_point(
- lyon::math::Point::new(text.position.x, text.position.y),
- );
-
- Point::new(transformed.x, transformed.y)
- };
-
- // TODO: Use vectorial text instead of primitive
- self.primitives.push(Primitive::Text {
- content: text.content,
- bounds: Rectangle {
- x: position.x,
- y: position.y,
- width: f32::INFINITY,
- height: f32::INFINITY,
- },
- color: text.color,
- size: text.size,
- font: text.font,
- horizontal_alignment: text.horizontal_alignment,
- vertical_alignment: text.vertical_alignment,
- });
- }
-
- /// Stores the current transform of the [`Frame`] and executes the given
- /// drawing operations, restoring the transform afterwards.
- ///
- /// This method is useful to compose transforms and perform drawing
- /// operations in different coordinate systems.
- ///
- /// [`Frame`]: struct.Frame.html
- #[inline]
- pub fn with_save(&mut self, f: impl FnOnce(&mut Frame)) {
- self.transforms.previous.push(self.transforms.current);
-
- f(self);
-
- self.transforms.current = self.transforms.previous.pop().unwrap();
- }
-
- /// Applies a translation to the current transform of the [`Frame`].
- ///
- /// [`Frame`]: struct.Frame.html
- #[inline]
- pub fn translate(&mut self, translation: Vector) {
- self.transforms.current.raw = self
- .transforms
- .current
- .raw
- .pre_translate(lyon::math::Vector::new(
- translation.x,
- translation.y,
- ));
- self.transforms.current.is_identity = false;
- }
-
- /// Applies a rotation to the current transform of the [`Frame`].
- ///
- /// [`Frame`]: struct.Frame.html
- #[inline]
- pub fn rotate(&mut self, angle: f32) {
- self.transforms.current.raw = self
- .transforms
- .current
- .raw
- .pre_rotate(lyon::math::Angle::radians(-angle));
- self.transforms.current.is_identity = false;
- }
-
- /// Applies a scaling to the current transform of the [`Frame`].
- ///
- /// [`Frame`]: struct.Frame.html
- #[inline]
- pub fn scale(&mut self, scale: f32) {
- self.transforms.current.raw =
- self.transforms.current.raw.pre_scale(scale, scale);
- self.transforms.current.is_identity = false;
- }
-
- /// Produces the primitive representing everything drawn on the [`Frame`].
- ///
- /// [`Frame`]: struct.Frame.html
- pub fn into_primitive(mut self) -> Primitive {
- self.primitives.push(Primitive::Mesh2D {
- origin: Point::ORIGIN,
- buffers: triangle::Mesh2D {
- vertices: self.buffers.vertices,
- indices: self.buffers.indices,
- },
- });
-
- Primitive::Group {
- primitives: self.primitives,
- }
- }
-}
-
-struct FillVertex([f32; 4]);
-
-impl lyon::tessellation::FillVertexConstructor<triangle::Vertex2D>
- for FillVertex
-{
- fn new_vertex(
- &mut self,
- position: lyon::math::Point,
- _attributes: lyon::tessellation::FillAttributes<'_>,
- ) -> triangle::Vertex2D {
- triangle::Vertex2D {
- position: [position.x, position.y],
- color: self.0,
- }
- }
-}
-
-struct StrokeVertex([f32; 4]);
-
-impl lyon::tessellation::StrokeVertexConstructor<triangle::Vertex2D>
- for StrokeVertex
-{
- fn new_vertex(
- &mut self,
- position: lyon::math::Point,
- _attributes: lyon::tessellation::StrokeAttributes<'_, '_>,
- ) -> triangle::Vertex2D {
- triangle::Vertex2D {
- position: [position.x, position.y],
- color: self.0,
- }
- }
-}
diff --git a/wgpu/src/widget/canvas/layer.rs b/wgpu/src/widget/canvas/layer.rs
deleted file mode 100644
index a46b7fb1..00000000
--- a/wgpu/src/widget/canvas/layer.rs
+++ /dev/null
@@ -1,25 +0,0 @@
-//! Produce, store, and reuse geometry.
-mod cache;
-
-pub use cache::Cache;
-
-use crate::Primitive;
-use iced_native::Size;
-
-use std::sync::Arc;
-
-/// A layer that can be presented at a [`Canvas`].
-///
-/// [`Canvas`]: ../struct.Canvas.html
-pub trait Layer: std::fmt::Debug {
- /// Draws the [`Layer`] in the given bounds and produces a [`Primitive`] as
- /// a result.
- ///
- /// The [`Layer`] may choose to store the produced [`Primitive`] locally and
- /// only recompute it when the bounds change, its contents change, or is
- /// otherwise explicitly cleared by other means.
- ///
- /// [`Layer`]: trait.Layer.html
- /// [`Primitive`]: ../../../enum.Primitive.html
- fn draw(&self, bounds: Size) -> Arc<Primitive>;
-}
diff --git a/wgpu/src/widget/canvas/layer/cache.rs b/wgpu/src/widget/canvas/layer/cache.rs
deleted file mode 100644
index 6b69f01e..00000000
--- a/wgpu/src/widget/canvas/layer/cache.rs
+++ /dev/null
@@ -1,99 +0,0 @@
-use crate::{
- canvas::{Drawable, Frame, Layer},
- Primitive,
-};
-
-use iced_native::Size;
-use std::{cell::RefCell, marker::PhantomData, sync::Arc};
-
-/// A simple cache that stores generated geometry to avoid recomputation.
-///
-/// A [`Cache`] will not redraw its geometry unless the dimensions of its layer
-/// change or it is explicitly cleared.
-///
-/// [`Layer`]: ../trait.Layer.html
-/// [`Cached`]: struct.Cached.html
-#[derive(Debug)]
-pub struct Cache<T: Drawable> {
- input: PhantomData<T>,
- state: RefCell<State>,
-}
-
-#[derive(Debug)]
-enum State {
- Empty,
- Filled {
- bounds: Size,
- primitive: Arc<Primitive>,
- },
-}
-
-impl<T> Cache<T>
-where
- T: Drawable + std::fmt::Debug,
-{
- /// Creates a new empty [`Cache`].
- ///
- /// [`Cache`]: struct.Cache.html
- pub fn new() -> Self {
- Cache {
- input: PhantomData,
- state: RefCell::new(State::Empty),
- }
- }
-
- /// Clears the cache, forcing a redraw the next time it is used.
- ///
- /// [`Cached`]: struct.Cached.html
- pub fn clear(&mut self) {
- *self.state.borrow_mut() = State::Empty;
- }
-
- /// Binds the [`Cache`] with some data, producing a [`Layer`] that can be
- /// added to a [`Canvas`].
- ///
- /// [`Cache`]: struct.Cache.html
- /// [`Layer`]: ../trait.Layer.html
- /// [`Canvas`]: ../../struct.Canvas.html
- pub fn with<'a>(&'a self, input: &'a T) -> impl Layer + 'a {
- Bind {
- cache: self,
- input: input,
- }
- }
-}
-
-#[derive(Debug)]
-struct Bind<'a, T: Drawable> {
- cache: &'a Cache<T>,
- input: &'a T,
-}
-
-impl<'a, T> Layer for Bind<'a, T>
-where
- T: Drawable + std::fmt::Debug,
-{
- fn draw(&self, current_bounds: Size) -> Arc<Primitive> {
- use std::ops::Deref;
-
- if let State::Filled { bounds, primitive } =
- self.cache.state.borrow().deref()
- {
- if *bounds == current_bounds {
- return primitive.clone();
- }
- }
-
- let mut frame = Frame::new(current_bounds.width, current_bounds.height);
- self.input.draw(&mut frame);
-
- let primitive = Arc::new(frame.into_primitive());
-
- *self.cache.state.borrow_mut() = State::Filled {
- bounds: current_bounds,
- primitive: primitive.clone(),
- };
-
- primitive
- }
-}
diff --git a/wgpu/src/widget/canvas/path.rs b/wgpu/src/widget/canvas/path.rs
deleted file mode 100644
index 15c2e853..00000000
--- a/wgpu/src/widget/canvas/path.rs
+++ /dev/null
@@ -1,49 +0,0 @@
-//! Build different kinds of 2D shapes.
-pub mod arc;
-
-mod builder;
-
-pub use arc::Arc;
-pub use builder::Builder;
-
-/// An immutable set of points that may or may not be connected.
-///
-/// A single [`Path`] can represent different kinds of 2D shapes!
-///
-/// [`Path`]: struct.Path.html
-#[derive(Debug, Clone)]
-pub struct Path {
- raw: lyon::path::Path,
-}
-
-impl Path {
- /// Creates a new [`Path`] with the provided closure.
- ///
- /// Use the [`Builder`] to configure your [`Path`].
- ///
- /// [`Path`]: struct.Path.html
- /// [`Builder`]: struct.Builder.html
- pub fn new(f: impl FnOnce(&mut Builder)) -> Self {
- let mut builder = Builder::new();
-
- // TODO: Make it pure instead of side-effect-based (?)
- f(&mut builder);
-
- builder.build()
- }
-
- #[inline]
- pub(crate) fn raw(&self) -> &lyon::path::Path {
- &self.raw
- }
-
- #[inline]
- pub(crate) fn transformed(
- &self,
- transform: &lyon::math::Transform,
- ) -> Path {
- Path {
- raw: self.raw.transformed(transform),
- }
- }
-}
diff --git a/wgpu/src/widget/canvas/path/arc.rs b/wgpu/src/widget/canvas/path/arc.rs
deleted file mode 100644
index 343191f1..00000000
--- a/wgpu/src/widget/canvas/path/arc.rs
+++ /dev/null
@@ -1,44 +0,0 @@
-//! Build and draw curves.
-use iced_native::{Point, Vector};
-
-/// A segment of a differentiable curve.
-#[derive(Debug, Clone, Copy)]
-pub struct Arc {
- /// The center of the arc.
- pub center: Point,
- /// The radius of the arc.
- pub radius: f32,
- /// The start of the segment's angle, clockwise rotation.
- pub start_angle: f32,
- /// The end of the segment's angle, clockwise rotation.
- pub end_angle: f32,
-}
-
-/// An elliptical [`Arc`].
-///
-/// [`Arc`]: struct.Arc.html
-#[derive(Debug, Clone, Copy)]
-pub struct Elliptical {
- /// The center of the arc.
- pub center: Point,
- /// The radii of the arc's ellipse, defining its axes.
- pub radii: Vector,
- /// The rotation of the arc's ellipse.
- pub rotation: f32,
- /// The start of the segment's angle, clockwise rotation.
- pub start_angle: f32,
- /// The end of the segment's angle, clockwise rotation.
- pub end_angle: f32,
-}
-
-impl From<Arc> for Elliptical {
- fn from(arc: Arc) -> Elliptical {
- Elliptical {
- center: arc.center,
- radii: Vector::new(arc.radius, arc.radius),
- rotation: 0.0,
- start_angle: arc.start_angle,
- end_angle: arc.end_angle,
- }
- }
-}
diff --git a/wgpu/src/widget/canvas/path/builder.rs b/wgpu/src/widget/canvas/path/builder.rs
deleted file mode 100644
index a013149e..00000000
--- a/wgpu/src/widget/canvas/path/builder.rs
+++ /dev/null
@@ -1,177 +0,0 @@
-use crate::canvas::path::{arc, Arc, Path};
-
-use iced_native::{Point, Size};
-use lyon::path::builder::{Build, FlatPathBuilder, PathBuilder, SvgBuilder};
-
-/// A [`Path`] builder.
-///
-/// Once a [`Path`] is built, it can no longer be mutated.
-///
-/// [`Path`]: struct.Path.html
-#[allow(missing_debug_implementations)]
-pub struct Builder {
- raw: lyon::path::builder::SvgPathBuilder<lyon::path::Builder>,
-}
-
-impl Builder {
- /// Creates a new [`Builder`].
- ///
- /// [`Builder`]: struct.Builder.html
- pub fn new() -> Builder {
- Builder {
- raw: lyon::path::Path::builder().with_svg(),
- }
- }
-
- /// Moves the starting point of a new sub-path to the given `Point`.
- #[inline]
- pub fn move_to(&mut self, point: Point) {
- let _ = self.raw.move_to(lyon::math::Point::new(point.x, point.y));
- }
-
- /// Connects the last point in the [`Path`] to the given `Point` with a
- /// straight line.
- ///
- /// [`Path`]: struct.Path.html
- #[inline]
- pub fn line_to(&mut self, point: Point) {
- let _ = self.raw.line_to(lyon::math::Point::new(point.x, point.y));
- }
-
- /// Adds an [`Arc`] to the [`Path`] from `start_angle` to `end_angle` in
- /// a clockwise direction.
- ///
- /// [`Arc`]: struct.Arc.html
- /// [`Path`]: struct.Path.html
- #[inline]
- pub fn arc(&mut self, arc: Arc) {
- self.ellipse(arc.into());
- }
-
- /// Adds a circular arc to the [`Path`] with the given control points and
- /// radius.
- ///
- /// The arc is connected to the previous point by a straight line, if
- /// necessary.
- ///
- /// [`Path`]: struct.Path.html
- pub fn arc_to(&mut self, a: Point, b: Point, radius: f32) {
- use lyon::{math, path};
-
- let a = math::Point::new(a.x, a.y);
-
- if self.raw.current_position() != a {
- let _ = self.raw.line_to(a);
- }
-
- let _ = self.raw.arc_to(
- math::Vector::new(radius, radius),
- math::Angle::radians(0.0),
- path::ArcFlags::default(),
- math::Point::new(b.x, b.y),
- );
- }
-
- /// Adds an [`Ellipse`] to the [`Path`] using a clockwise direction.
- ///
- /// [`Ellipse`]: struct.Arc.html
- /// [`Path`]: struct.Path.html
- pub fn ellipse(&mut self, arc: arc::Elliptical) {
- use lyon::{geom, math};
-
- let arc = geom::Arc {
- center: math::Point::new(arc.center.x, arc.center.y),
- radii: math::Vector::new(arc.radii.x, arc.radii.y),
- x_rotation: math::Angle::radians(arc.rotation),
- start_angle: math::Angle::radians(arc.start_angle),
- sweep_angle: math::Angle::radians(arc.end_angle),
- };
-
- let _ = self.raw.move_to(arc.sample(0.0));
-
- arc.for_each_quadratic_bezier(&mut |curve| {
- let _ = self.raw.quadratic_bezier_to(curve.ctrl, curve.to);
- });
- }
-
- /// Adds a cubic Bézier curve to the [`Path`] given its two control points
- /// and its end point.
- ///
- /// [`Path`]: struct.Path.html
- #[inline]
- pub fn bezier_curve_to(
- &mut self,
- control_a: Point,
- control_b: Point,
- to: Point,
- ) {
- use lyon::math;
-
- let _ = self.raw.cubic_bezier_to(
- math::Point::new(control_a.x, control_a.y),
- math::Point::new(control_b.x, control_b.y),
- math::Point::new(to.x, to.y),
- );
- }
-
- /// Adds a quadratic Bézier curve to the [`Path`] given its control point
- /// and its end point.
- ///
- /// [`Path`]: struct.Path.html
- #[inline]
- pub fn quadratic_curve_to(&mut self, control: Point, to: Point) {
- use lyon::math;
-
- let _ = self.raw.quadratic_bezier_to(
- math::Point::new(control.x, control.y),
- math::Point::new(to.x, to.y),
- );
- }
-
- /// Adds a rectangle to the [`Path`] given its top-left corner coordinate
- /// and its `Size`.
- ///
- /// [`Path`]: struct.Path.html
- #[inline]
- pub fn rectangle(&mut self, p: Point, size: Size) {
- self.move_to(p);
- self.line_to(Point::new(p.x + size.width, p.y));
- self.line_to(Point::new(p.x + size.width, p.y + size.height));
- self.line_to(Point::new(p.x, p.y + size.height));
- self.close();
- }
-
- /// Adds a circle to the [`Path`] given its center coordinate and its
- /// radius.
- ///
- /// [`Path`]: struct.Path.html
- #[inline]
- pub fn circle(&mut self, center: Point, radius: f32) {
- self.arc(Arc {
- center,
- radius,
- start_angle: 0.0,
- end_angle: 2.0 * std::f32::consts::PI,
- });
- }
-
- /// Closes the current sub-path in the [`Path`] with a straight line to
- /// the starting point.
- ///
- /// [`Path`]: struct.Path.html
- #[inline]
- pub fn close(&mut self) {
- self.raw.close()
- }
-
- /// Builds the [`Path`] of this [`Builder`].
- ///
- /// [`Path`]: struct.Path.html
- /// [`Builder`]: struct.Builder.html
- #[inline]
- pub fn build(self) -> Path {
- Path {
- raw: self.raw.build(),
- }
- }
-}
diff --git a/wgpu/src/widget/canvas/stroke.rs b/wgpu/src/widget/canvas/stroke.rs
deleted file mode 100644
index 46d669c4..00000000
--- a/wgpu/src/widget/canvas/stroke.rs
+++ /dev/null
@@ -1,83 +0,0 @@
-use iced_native::Color;
-
-/// The style of a stroke.
-#[derive(Debug, Clone, Copy)]
-pub struct Stroke {
- /// The color of the stroke.
- pub color: Color,
- /// The distance between the two edges of the stroke.
- pub width: f32,
- /// The shape to be used at the end of open subpaths when they are stroked.
- pub line_cap: LineCap,
- /// The shape to be used at the corners of paths or basic shapes when they
- /// are stroked.
- pub line_join: LineJoin,
-}
-
-impl Default for Stroke {
- fn default() -> Stroke {
- Stroke {
- color: Color::BLACK,
- width: 1.0,
- line_cap: LineCap::default(),
- line_join: LineJoin::default(),
- }
- }
-}
-
-/// The shape used at the end of open subpaths when they are stroked.
-#[derive(Debug, Clone, Copy)]
-pub enum LineCap {
- /// The stroke for each sub-path does not extend beyond its two endpoints.
- Butt,
- /// At the end of each sub-path, the shape representing the stroke will be
- /// extended by a square.
- Square,
- /// At the end of each sub-path, the shape representing the stroke will be
- /// extended by a semicircle.
- Round,
-}
-
-impl Default for LineCap {
- fn default() -> LineCap {
- LineCap::Butt
- }
-}
-
-impl From<LineCap> for lyon::tessellation::LineCap {
- fn from(line_cap: LineCap) -> lyon::tessellation::LineCap {
- match line_cap {
- LineCap::Butt => lyon::tessellation::LineCap::Butt,
- LineCap::Square => lyon::tessellation::LineCap::Square,
- LineCap::Round => lyon::tessellation::LineCap::Round,
- }
- }
-}
-
-/// The shape used at the corners of paths or basic shapes when they are
-/// stroked.
-#[derive(Debug, Clone, Copy)]
-pub enum LineJoin {
- /// A sharp corner.
- Miter,
- /// A round corner.
- Round,
- /// A bevelled corner.
- Bevel,
-}
-
-impl Default for LineJoin {
- fn default() -> LineJoin {
- LineJoin::Miter
- }
-}
-
-impl From<LineJoin> for lyon::tessellation::LineJoin {
- fn from(line_join: LineJoin) -> lyon::tessellation::LineJoin {
- match line_join {
- LineJoin::Miter => lyon::tessellation::LineJoin::Miter,
- LineJoin::Round => lyon::tessellation::LineJoin::Round,
- LineJoin::Bevel => lyon::tessellation::LineJoin::Bevel,
- }
- }
-}
diff --git a/wgpu/src/widget/canvas/text.rs b/wgpu/src/widget/canvas/text.rs
deleted file mode 100644
index d1cf1a0f..00000000
--- a/wgpu/src/widget/canvas/text.rs
+++ /dev/null
@@ -1,34 +0,0 @@
-use iced_native::{Color, Font, HorizontalAlignment, Point, VerticalAlignment};
-
-/// A bunch of text that can be drawn to a canvas
-#[derive(Debug, Clone)]
-pub struct Text {
- /// The contents of the text
- pub content: String,
- /// The position where to begin drawing the text (top-left corner coordinates)
- pub position: Point,
- /// The color of the text
- pub color: Color,
- /// The size of the text
- pub size: f32,
- /// The font of the text
- pub font: Font,
- /// The horizontal alignment of the text
- pub horizontal_alignment: HorizontalAlignment,
- /// The vertical alignment of the text
- pub vertical_alignment: VerticalAlignment,
-}
-
-impl Default for Text {
- fn default() -> Text {
- Text {
- content: String::new(),
- position: Point::ORIGIN,
- color: Color::BLACK,
- size: 16.0,
- font: Font::Default,
- horizontal_alignment: HorizontalAlignment::Left,
- vertical_alignment: VerticalAlignment::Top,
- }
- }
-}
diff --git a/wgpu/src/widget/checkbox.rs b/wgpu/src/widget/checkbox.rs
index da0d7a84..d27d77cc 100644
--- a/wgpu/src/widget/checkbox.rs
+++ b/wgpu/src/widget/checkbox.rs
@@ -1,7 +1,7 @@
//! Show toggle controls using checkboxes.
use crate::Renderer;
-pub use iced_style::checkbox::{Style, StyleSheet};
+pub use iced_graphics::checkbox::{Style, StyleSheet};
/// A box that can be checked.
///
diff --git a/wgpu/src/widget/container.rs b/wgpu/src/widget/container.rs
index 9a93a246..bc26cef2 100644
--- a/wgpu/src/widget/container.rs
+++ b/wgpu/src/widget/container.rs
@@ -1,7 +1,7 @@
//! Decorate content and apply alignment.
use crate::Renderer;
-pub use iced_style::container::{Style, StyleSheet};
+pub use iced_graphics::container::{Style, StyleSheet};
/// An element decorating some content.
///
diff --git a/wgpu/src/widget/pane_grid.rs b/wgpu/src/widget/pane_grid.rs
new file mode 100644
index 00000000..c26dde48
--- /dev/null
+++ b/wgpu/src/widget/pane_grid.rs
@@ -0,0 +1,31 @@
+//! Let your users split regions of your application and organize layout dynamically.
+//!
+//! [![Pane grid - Iced](https://thumbs.gfycat.com/MixedFlatJellyfish-small.gif)](https://gfycat.com/mixedflatjellyfish)
+//!
+//! # Example
+//! The [`pane_grid` example] showcases how to use a [`PaneGrid`] with resizing,
+//! drag and drop, and hotkey support.
+//!
+//! [`pane_grid` example]: https://github.com/hecrj/iced/tree/0.2/examples/pane_grid
+use crate::Renderer;
+
+pub use iced_native::pane_grid::{
+ Axis, Configuration, Direction, DragEvent, Node, Pane, ResizeEvent, Split,
+ State,
+};
+
+/// A collection of panes distributed using either vertical or horizontal splits
+/// to completely fill the space available.
+///
+/// [![Pane grid - Iced](https://thumbs.gfycat.com/MixedFlatJellyfish-small.gif)](https://gfycat.com/mixedflatjellyfish)
+///
+/// This is an alias of an `iced_native` pane grid with an `iced_wgpu::Renderer`.
+pub type PaneGrid<'a, Message> = iced_native::PaneGrid<'a, Message, Renderer>;
+
+/// The content of a [`Pane`].
+pub type Content<'a, Message> =
+ iced_native::pane_grid::Content<'a, Message, Renderer>;
+
+/// The title bar of a [`Pane`].
+pub type TitleBar<'a, Message> =
+ iced_native::pane_grid::TitleBar<'a, Message, Renderer>;
diff --git a/wgpu/src/widget/pick_list.rs b/wgpu/src/widget/pick_list.rs
new file mode 100644
index 00000000..fccc68c9
--- /dev/null
+++ b/wgpu/src/widget/pick_list.rs
@@ -0,0 +1,9 @@
+//! Display a dropdown list of selectable values.
+pub use iced_native::pick_list::State;
+
+pub use iced_graphics::overlay::menu::Style as Menu;
+pub use iced_graphics::pick_list::{Style, StyleSheet};
+
+/// A widget allowing the selection of a single value from a list of options.
+pub type PickList<'a, T, Message> =
+ iced_native::PickList<'a, T, Message, crate::Renderer>;
diff --git a/wgpu/src/widget/progress_bar.rs b/wgpu/src/widget/progress_bar.rs
index 34450b5e..45a25d00 100644
--- a/wgpu/src/widget/progress_bar.rs
+++ b/wgpu/src/widget/progress_bar.rs
@@ -1,12 +1,10 @@
-//! Allow your users to perform actions by pressing a button.
+//! Allow your users to visually track the progress of a computation.
//!
-//! A [`Button`] has some local [`State`].
-//!
-//! [`Button`]: type.Button.html
-//! [`State`]: struct.State.html
+//! A [`ProgressBar`] has a range of possible values and a current value,
+//! as well as a length, height and style.
use crate::Renderer;
-pub use iced_style::progress_bar::{Style, StyleSheet};
+pub use iced_graphics::progress_bar::{Style, StyleSheet};
/// A bar that displays progress.
///
diff --git a/wgpu/src/widget/qr_code.rs b/wgpu/src/widget/qr_code.rs
new file mode 100644
index 00000000..7b1c2408
--- /dev/null
+++ b/wgpu/src/widget/qr_code.rs
@@ -0,0 +1,2 @@
+//! Encode and display information in a QR code.
+pub use iced_graphics::qr_code::*;
diff --git a/wgpu/src/widget/radio.rs b/wgpu/src/widget/radio.rs
index 6e5cf042..0b843d1f 100644
--- a/wgpu/src/widget/radio.rs
+++ b/wgpu/src/widget/radio.rs
@@ -1,7 +1,7 @@
//! Create choices using radio buttons.
use crate::Renderer;
-pub use iced_style::radio::{Style, StyleSheet};
+pub use iced_graphics::radio::{Style, StyleSheet};
/// A circular button representing a choice.
///
diff --git a/wgpu/src/widget/rule.rs b/wgpu/src/widget/rule.rs
new file mode 100644
index 00000000..3f7bc67a
--- /dev/null
+++ b/wgpu/src/widget/rule.rs
@@ -0,0 +1,10 @@
+//! Display a horizontal or vertical rule for dividing content.
+
+use crate::Renderer;
+
+pub use iced_graphics::rule::{FillMode, Style, StyleSheet};
+
+/// Display a horizontal or vertical rule for dividing content.
+///
+/// This is an alias of an `iced_native` rule with an `iced_wgpu::Renderer`.
+pub type Rule = iced_native::Rule<Renderer>;
diff --git a/wgpu/src/widget/scrollable.rs b/wgpu/src/widget/scrollable.rs
index 1d236105..fabb4318 100644
--- a/wgpu/src/widget/scrollable.rs
+++ b/wgpu/src/widget/scrollable.rs
@@ -1,8 +1,8 @@
//! Navigate an endless amount of content with a scrollbar.
use crate::Renderer;
+pub use iced_graphics::scrollable::{Scrollbar, Scroller, StyleSheet};
pub use iced_native::scrollable::State;
-pub use iced_style::scrollable::{Scrollbar, Scroller, StyleSheet};
/// A widget that can vertically display an infinite amount of content
/// with a scrollbar.
diff --git a/wgpu/src/widget/slider.rs b/wgpu/src/widget/slider.rs
index 4e47978f..9a269858 100644
--- a/wgpu/src/widget/slider.rs
+++ b/wgpu/src/widget/slider.rs
@@ -1,16 +1,13 @@
//! Display an interactive selector of a single value from a range of values.
//!
//! A [`Slider`] has some local [`State`].
-//!
-//! [`Slider`]: struct.Slider.html
-//! [`State`]: struct.State.html
use crate::Renderer;
+pub use iced_graphics::slider::{Handle, HandleShape, Style, StyleSheet};
pub use iced_native::slider::State;
-pub use iced_style::slider::{Handle, HandleShape, Style, StyleSheet};
/// An horizontal bar and a handle that selects a single value from a range of
/// values.
///
/// This is an alias of an `iced_native` slider with an `iced_wgpu::Renderer`.
-pub type Slider<'a, Message> = iced_native::Slider<'a, Message, Renderer>;
+pub type Slider<'a, T, Message> = iced_native::Slider<'a, T, Message, Renderer>;
diff --git a/wgpu/src/widget/text_input.rs b/wgpu/src/widget/text_input.rs
index 260fe3a6..db18b1cc 100644
--- a/wgpu/src/widget/text_input.rs
+++ b/wgpu/src/widget/text_input.rs
@@ -1,13 +1,10 @@
//! Display fields that can be filled with text.
//!
//! A [`TextInput`] has some local [`State`].
-//!
-//! [`TextInput`]: struct.TextInput.html
-//! [`State`]: struct.State.html
use crate::Renderer;
+pub use iced_graphics::text_input::{Style, StyleSheet};
pub use iced_native::text_input::State;
-pub use iced_style::text_input::{Style, StyleSheet};
/// A field that can be filled with text.
///