diff options
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | examples/ggez/renderer/button.rs | 2 | ||||
-rw-r--r-- | examples/ggez/renderer/checkbox.rs | 4 | ||||
-rw-r--r-- | examples/ggez/renderer/radio.rs | 4 | ||||
-rw-r--r-- | examples/ggez/renderer/slider.rs | 2 | ||||
-rw-r--r-- | examples/ggez/renderer/text.rs | 2 | ||||
-rw-r--r-- | src/element.rs | 2 | ||||
-rw-r--r-- | src/layout.rs | 2 | ||||
-rw-r--r-- | src/lib.rs | 4 | ||||
-rw-r--r-- | src/point.rs | 28 | ||||
-rw-r--r-- | src/rectangle.rs | 18 | ||||
-rw-r--r-- | src/vector.rs | 15 | ||||
-rw-r--r-- | src/widget/button.rs | 2 | ||||
-rw-r--r-- | src/widget/checkbox.rs | 4 | ||||
-rw-r--r-- | src/widget/panel.rs | 2 | ||||
-rw-r--r-- | src/widget/radio.rs | 4 | ||||
-rw-r--r-- | src/widget/slider.rs | 2 | ||||
-rw-r--r-- | src/widget/text.rs | 2 |
18 files changed, 69 insertions, 31 deletions
@@ -13,7 +13,6 @@ categories = ["gui"] [dependencies] stretch = "0.2" -nalgebra = "0.18" twox-hash = "1.5" [dev-dependencies] diff --git a/examples/ggez/renderer/button.rs b/examples/ggez/renderer/button.rs index 2423efe1..fc3ea7ca 100644 --- a/examples/ggez/renderer/button.rs +++ b/examples/ggez/renderer/button.rs @@ -29,7 +29,7 @@ impl button::Renderer for Renderer<'_> { fn draw( &mut self, cursor_position: iced::Point, - mut bounds: iced::Rectangle<f32>, + mut bounds: iced::Rectangle, state: &button::State, label: &str, class: button::Class, diff --git a/examples/ggez/renderer/checkbox.rs b/examples/ggez/renderer/checkbox.rs index 1930631d..20a91be5 100644 --- a/examples/ggez/renderer/checkbox.rs +++ b/examples/ggez/renderer/checkbox.rs @@ -14,8 +14,8 @@ impl checkbox::Renderer for Renderer<'_> { fn draw( &mut self, cursor_position: iced::Point, - bounds: iced::Rectangle<f32>, - text_bounds: iced::Rectangle<f32>, + bounds: iced::Rectangle, + text_bounds: iced::Rectangle, is_checked: bool, ) -> MouseCursor { let mouse_over = bounds.contains(cursor_position) diff --git a/examples/ggez/renderer/radio.rs b/examples/ggez/renderer/radio.rs index 64310f9b..0f7815d6 100644 --- a/examples/ggez/renderer/radio.rs +++ b/examples/ggez/renderer/radio.rs @@ -14,8 +14,8 @@ impl radio::Renderer for Renderer<'_> { fn draw( &mut self, cursor_position: Point, - bounds: Rectangle<f32>, - bounds_with_label: Rectangle<f32>, + bounds: Rectangle, + bounds_with_label: Rectangle, is_selected: bool, ) -> MouseCursor { let mouse_over = bounds_with_label.contains(cursor_position); diff --git a/examples/ggez/renderer/slider.rs b/examples/ggez/renderer/slider.rs index 86757127..146cee18 100644 --- a/examples/ggez/renderer/slider.rs +++ b/examples/ggez/renderer/slider.rs @@ -22,7 +22,7 @@ impl slider::Renderer for Renderer<'_> { fn draw( &mut self, cursor_position: Point, - bounds: Rectangle<f32>, + bounds: Rectangle, state: &slider::State, range: RangeInclusive<f32>, value: f32, diff --git a/examples/ggez/renderer/text.rs b/examples/ggez/renderer/text.rs index db393873..7eab91fc 100644 --- a/examples/ggez/renderer/text.rs +++ b/examples/ggez/renderer/text.rs @@ -69,7 +69,7 @@ impl text::Renderer<Color> for Renderer<'_> { fn draw( &mut self, - bounds: iced::Rectangle<f32>, + bounds: iced::Rectangle, content: &str, size: f32, color: Option<Color>, diff --git a/src/element.rs b/src/element.rs index 098ca16f..70d06f42 100644 --- a/src/element.rs +++ b/src/element.rs @@ -110,7 +110,7 @@ impl<'a, Message, Renderer> Element<'a, Message, Renderer> { /// # fn draw( /// # &mut self, /// # _cursor_position: Point, - /// # _bounds: Rectangle<f32>, + /// # _bounds: Rectangle, /// # _state: &button::State, /// # _label: &str, /// # _class: button::Class, diff --git a/src/layout.rs b/src/layout.rs index 16d4f685..de284a43 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -41,7 +41,7 @@ impl<'a> Layout<'a> { /// [`Layout`]: struct.Layout.html /// [`Rectangle`]: struct.Rectangle.html /// [`Node`]: struct.Node.html - pub fn bounds(&self) -> Rectangle<f32> { + pub fn bounds(&self) -> Rectangle { Rectangle { x: self.position.x, y: self.position.y, @@ -87,7 +87,7 @@ //! # fn draw( //! # &mut self, //! # _cursor_position: Point, -//! # _bounds: Rectangle<f32>, +//! # _bounds: Rectangle, //! # _state: &button::State, //! # _label: &str, //! # _class: button::Class, @@ -103,7 +103,7 @@ //! # //! # fn draw( //! # &mut self, -//! # _bounds: Rectangle<f32>, +//! # _bounds: Rectangle, //! # _content: &str, //! # _size: f32, //! # _color: Option<[f32; 4]>, diff --git a/src/point.rs b/src/point.rs index 8f172689..80afffb7 100644 --- a/src/point.rs +++ b/src/point.rs @@ -1,2 +1,28 @@ +use crate::Vector; + /// A 2D point. -pub type Point = nalgebra::Point2<f32>; +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct Point { + pub x: f32, + pub y: f32, +} + +impl Point { + /// Creates a new [`Point`] with the given coordinates. + /// + /// [`Point`]: struct.Point.html + pub fn new(x: f32, y: f32) -> Self { + Self { x, y } + } +} + +impl std::ops::Add<Vector> for Point { + type Output = Self; + + fn add(self, vector: Vector) -> Self { + Self { + x: self.x + vector.x, + y: self.y + vector.y, + } + } +} diff --git a/src/rectangle.rs b/src/rectangle.rs index ca224dad..9f2a1350 100644 --- a/src/rectangle.rs +++ b/src/rectangle.rs @@ -1,25 +1,25 @@ use crate::Point; -/// A generic rectangle. -#[derive(Debug, PartialEq, Eq, Copy, Clone)] -pub struct Rectangle<T> { +/// A rectangle. +#[derive(Debug, PartialEq, Copy, Clone)] +pub struct Rectangle { /// X coordinate of the top-left corner. - pub x: T, + pub x: f32, /// Y coordinate of the top-left corner. - pub y: T, + pub y: f32, /// Width of the rectangle. - pub width: T, + pub width: f32, /// Height of the rectangle. - pub height: T, + pub height: f32, } -impl Rectangle<f32> { +impl Rectangle { /// Returns true if the given [`Point`] is contained in the [`Rectangle`]. /// - /// [`Point`]: type.Point.html + /// [`Point`]: struct.Point.html /// [`Rectangle`]: struct.Rectangle.html pub fn contains(&self, point: Point) -> bool { self.x <= point.x diff --git a/src/vector.rs b/src/vector.rs index 12f1f082..f45daab9 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -1,2 +1,15 @@ /// A 2D vector. -pub type Vector = nalgebra::Vector2<f32>; +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct Vector { + pub x: f32, + pub y: f32, +} + +impl Vector { + /// Creates a new [`Vector`] with the given components. + /// + /// [`Vector`]: struct.Vector.html + pub fn new(x: f32, y: f32) -> Self { + Self { x, y } + } +} diff --git a/src/widget/button.rs b/src/widget/button.rs index a3ee493c..14fd3852 100644 --- a/src/widget/button.rs +++ b/src/widget/button.rs @@ -263,7 +263,7 @@ pub trait Renderer { fn draw( &mut self, cursor_position: Point, - bounds: Rectangle<f32>, + bounds: Rectangle, state: &State, label: &str, class: Class, diff --git a/src/widget/checkbox.rs b/src/widget/checkbox.rs index b8a20d2c..a7561df1 100644 --- a/src/widget/checkbox.rs +++ b/src/widget/checkbox.rs @@ -182,8 +182,8 @@ pub trait Renderer { fn draw( &mut self, cursor_position: Point, - bounds: Rectangle<f32>, - label_bounds: Rectangle<f32>, + bounds: Rectangle, + label_bounds: Rectangle, is_checked: bool, ) -> MouseCursor; } diff --git a/src/widget/panel.rs b/src/widget/panel.rs index 28e5989c..d43d6fb6 100644 --- a/src/widget/panel.rs +++ b/src/widget/panel.rs @@ -90,5 +90,5 @@ where } pub trait Renderer { - fn draw(&mut self, bounds: Rectangle<f32>); + fn draw(&mut self, bounds: Rectangle); } diff --git a/src/widget/radio.rs b/src/widget/radio.rs index f7ee04e1..a59d52aa 100644 --- a/src/widget/radio.rs +++ b/src/widget/radio.rs @@ -192,8 +192,8 @@ pub trait Renderer { fn draw( &mut self, cursor_position: Point, - bounds: Rectangle<f32>, - label_bounds: Rectangle<f32>, + bounds: Rectangle, + label_bounds: Rectangle, is_selected: bool, ) -> MouseCursor; } diff --git a/src/widget/slider.rs b/src/widget/slider.rs index 531c2992..c7adbb51 100644 --- a/src/widget/slider.rs +++ b/src/widget/slider.rs @@ -222,7 +222,7 @@ pub trait Renderer { fn draw( &mut self, cursor_position: Point, - bounds: Rectangle<f32>, + bounds: Rectangle, state: &State, range: RangeInclusive<f32>, value: f32, diff --git a/src/widget/text.rs b/src/widget/text.rs index 2663765d..c4b7eabb 100644 --- a/src/widget/text.rs +++ b/src/widget/text.rs @@ -177,7 +177,7 @@ pub trait Renderer<Color> { /// [`VerticalAlignment`]: enum.VerticalAlignment.html fn draw( &mut self, - bounds: Rectangle<f32>, + bounds: Rectangle, content: &str, size: f32, color: Option<Color>, |