Remove nalgebra dependency
- Implement our own `Point` and `Vector` types - Make `Rectangle` not generic
This commit is contained in:
parent
343cafa1ee
commit
eecac7b5d1
@ -13,7 +13,6 @@ categories = ["gui"]
|
||||
|
||||
[dependencies]
|
||||
stretch = "0.2"
|
||||
nalgebra = "0.18"
|
||||
twox-hash = "1.5"
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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>,
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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]>,
|
||||
|
||||
28
src/point.rs
28
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 }
|
||||
}
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -90,5 +90,5 @@ where
|
||||
}
|
||||
|
||||
pub trait Renderer {
|
||||
fn draw(&mut self, bounds: Rectangle<f32>);
|
||||
fn draw(&mut self, bounds: Rectangle);
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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>,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user