summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-08-31 04:31:13 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-08-31 04:31:13 +0200
commiteecac7b5d163794645bcce8e450c74e3eb5e999f (patch)
treebf55576b1941bffae422050f72e7c9a6c1c0d282 /src
parent343cafa1ee0b6d29d6e739dfebb13ebe3656a9aa (diff)
downloadiced-eecac7b5d163794645bcce8e450c74e3eb5e999f.tar.gz
iced-eecac7b5d163794645bcce8e450c74e3eb5e999f.tar.bz2
iced-eecac7b5d163794645bcce8e450c74e3eb5e999f.zip
Remove `nalgebra` dependency
- Implement our own `Point` and `Vector` types - Make `Rectangle` not generic
Diffstat (limited to 'src')
-rw-r--r--src/element.rs2
-rw-r--r--src/layout.rs2
-rw-r--r--src/lib.rs4
-rw-r--r--src/point.rs28
-rw-r--r--src/rectangle.rs18
-rw-r--r--src/vector.rs15
-rw-r--r--src/widget/button.rs2
-rw-r--r--src/widget/checkbox.rs4
-rw-r--r--src/widget/panel.rs2
-rw-r--r--src/widget/radio.rs4
-rw-r--r--src/widget/slider.rs2
-rw-r--r--src/widget/text.rs2
12 files changed, 62 insertions, 23 deletions
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,
diff --git a/src/lib.rs b/src/lib.rs
index e2908f73..821c0dd0 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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>,