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]
|
[dependencies]
|
||||||
stretch = "0.2"
|
stretch = "0.2"
|
||||||
nalgebra = "0.18"
|
|
||||||
twox-hash = "1.5"
|
twox-hash = "1.5"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|||||||
@ -29,7 +29,7 @@ impl button::Renderer for Renderer<'_> {
|
|||||||
fn draw(
|
fn draw(
|
||||||
&mut self,
|
&mut self,
|
||||||
cursor_position: iced::Point,
|
cursor_position: iced::Point,
|
||||||
mut bounds: iced::Rectangle<f32>,
|
mut bounds: iced::Rectangle,
|
||||||
state: &button::State,
|
state: &button::State,
|
||||||
label: &str,
|
label: &str,
|
||||||
class: button::Class,
|
class: button::Class,
|
||||||
|
|||||||
@ -14,8 +14,8 @@ impl checkbox::Renderer for Renderer<'_> {
|
|||||||
fn draw(
|
fn draw(
|
||||||
&mut self,
|
&mut self,
|
||||||
cursor_position: iced::Point,
|
cursor_position: iced::Point,
|
||||||
bounds: iced::Rectangle<f32>,
|
bounds: iced::Rectangle,
|
||||||
text_bounds: iced::Rectangle<f32>,
|
text_bounds: iced::Rectangle,
|
||||||
is_checked: bool,
|
is_checked: bool,
|
||||||
) -> MouseCursor {
|
) -> MouseCursor {
|
||||||
let mouse_over = bounds.contains(cursor_position)
|
let mouse_over = bounds.contains(cursor_position)
|
||||||
|
|||||||
@ -14,8 +14,8 @@ impl radio::Renderer for Renderer<'_> {
|
|||||||
fn draw(
|
fn draw(
|
||||||
&mut self,
|
&mut self,
|
||||||
cursor_position: Point,
|
cursor_position: Point,
|
||||||
bounds: Rectangle<f32>,
|
bounds: Rectangle,
|
||||||
bounds_with_label: Rectangle<f32>,
|
bounds_with_label: Rectangle,
|
||||||
is_selected: bool,
|
is_selected: bool,
|
||||||
) -> MouseCursor {
|
) -> MouseCursor {
|
||||||
let mouse_over = bounds_with_label.contains(cursor_position);
|
let mouse_over = bounds_with_label.contains(cursor_position);
|
||||||
|
|||||||
@ -22,7 +22,7 @@ impl slider::Renderer for Renderer<'_> {
|
|||||||
fn draw(
|
fn draw(
|
||||||
&mut self,
|
&mut self,
|
||||||
cursor_position: Point,
|
cursor_position: Point,
|
||||||
bounds: Rectangle<f32>,
|
bounds: Rectangle,
|
||||||
state: &slider::State,
|
state: &slider::State,
|
||||||
range: RangeInclusive<f32>,
|
range: RangeInclusive<f32>,
|
||||||
value: f32,
|
value: f32,
|
||||||
|
|||||||
@ -69,7 +69,7 @@ impl text::Renderer<Color> for Renderer<'_> {
|
|||||||
|
|
||||||
fn draw(
|
fn draw(
|
||||||
&mut self,
|
&mut self,
|
||||||
bounds: iced::Rectangle<f32>,
|
bounds: iced::Rectangle,
|
||||||
content: &str,
|
content: &str,
|
||||||
size: f32,
|
size: f32,
|
||||||
color: Option<Color>,
|
color: Option<Color>,
|
||||||
|
|||||||
@ -110,7 +110,7 @@ impl<'a, Message, Renderer> Element<'a, Message, Renderer> {
|
|||||||
/// # fn draw(
|
/// # fn draw(
|
||||||
/// # &mut self,
|
/// # &mut self,
|
||||||
/// # _cursor_position: Point,
|
/// # _cursor_position: Point,
|
||||||
/// # _bounds: Rectangle<f32>,
|
/// # _bounds: Rectangle,
|
||||||
/// # _state: &button::State,
|
/// # _state: &button::State,
|
||||||
/// # _label: &str,
|
/// # _label: &str,
|
||||||
/// # _class: button::Class,
|
/// # _class: button::Class,
|
||||||
|
|||||||
@ -41,7 +41,7 @@ impl<'a> Layout<'a> {
|
|||||||
/// [`Layout`]: struct.Layout.html
|
/// [`Layout`]: struct.Layout.html
|
||||||
/// [`Rectangle`]: struct.Rectangle.html
|
/// [`Rectangle`]: struct.Rectangle.html
|
||||||
/// [`Node`]: struct.Node.html
|
/// [`Node`]: struct.Node.html
|
||||||
pub fn bounds(&self) -> Rectangle<f32> {
|
pub fn bounds(&self) -> Rectangle {
|
||||||
Rectangle {
|
Rectangle {
|
||||||
x: self.position.x,
|
x: self.position.x,
|
||||||
y: self.position.y,
|
y: self.position.y,
|
||||||
|
|||||||
@ -87,7 +87,7 @@
|
|||||||
//! # fn draw(
|
//! # fn draw(
|
||||||
//! # &mut self,
|
//! # &mut self,
|
||||||
//! # _cursor_position: Point,
|
//! # _cursor_position: Point,
|
||||||
//! # _bounds: Rectangle<f32>,
|
//! # _bounds: Rectangle,
|
||||||
//! # _state: &button::State,
|
//! # _state: &button::State,
|
||||||
//! # _label: &str,
|
//! # _label: &str,
|
||||||
//! # _class: button::Class,
|
//! # _class: button::Class,
|
||||||
@ -103,7 +103,7 @@
|
|||||||
//! #
|
//! #
|
||||||
//! # fn draw(
|
//! # fn draw(
|
||||||
//! # &mut self,
|
//! # &mut self,
|
||||||
//! # _bounds: Rectangle<f32>,
|
//! # _bounds: Rectangle,
|
||||||
//! # _content: &str,
|
//! # _content: &str,
|
||||||
//! # _size: f32,
|
//! # _size: f32,
|
||||||
//! # _color: Option<[f32; 4]>,
|
//! # _color: Option<[f32; 4]>,
|
||||||
|
|||||||
28
src/point.rs
28
src/point.rs
@ -1,2 +1,28 @@
|
|||||||
|
use crate::Vector;
|
||||||
|
|
||||||
/// A 2D point.
|
/// 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;
|
use crate::Point;
|
||||||
|
|
||||||
/// A generic rectangle.
|
/// A rectangle.
|
||||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
#[derive(Debug, PartialEq, Copy, Clone)]
|
||||||
pub struct Rectangle<T> {
|
pub struct Rectangle {
|
||||||
/// X coordinate of the top-left corner.
|
/// X coordinate of the top-left corner.
|
||||||
pub x: T,
|
pub x: f32,
|
||||||
|
|
||||||
/// Y coordinate of the top-left corner.
|
/// Y coordinate of the top-left corner.
|
||||||
pub y: T,
|
pub y: f32,
|
||||||
|
|
||||||
/// Width of the rectangle.
|
/// Width of the rectangle.
|
||||||
pub width: T,
|
pub width: f32,
|
||||||
|
|
||||||
/// Height of the rectangle.
|
/// 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`].
|
/// Returns true if the given [`Point`] is contained in the [`Rectangle`].
|
||||||
///
|
///
|
||||||
/// [`Point`]: type.Point.html
|
/// [`Point`]: struct.Point.html
|
||||||
/// [`Rectangle`]: struct.Rectangle.html
|
/// [`Rectangle`]: struct.Rectangle.html
|
||||||
pub fn contains(&self, point: Point) -> bool {
|
pub fn contains(&self, point: Point) -> bool {
|
||||||
self.x <= point.x
|
self.x <= point.x
|
||||||
|
|||||||
@ -1,2 +1,15 @@
|
|||||||
/// A 2D vector.
|
/// 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(
|
fn draw(
|
||||||
&mut self,
|
&mut self,
|
||||||
cursor_position: Point,
|
cursor_position: Point,
|
||||||
bounds: Rectangle<f32>,
|
bounds: Rectangle,
|
||||||
state: &State,
|
state: &State,
|
||||||
label: &str,
|
label: &str,
|
||||||
class: Class,
|
class: Class,
|
||||||
|
|||||||
@ -182,8 +182,8 @@ pub trait Renderer {
|
|||||||
fn draw(
|
fn draw(
|
||||||
&mut self,
|
&mut self,
|
||||||
cursor_position: Point,
|
cursor_position: Point,
|
||||||
bounds: Rectangle<f32>,
|
bounds: Rectangle,
|
||||||
label_bounds: Rectangle<f32>,
|
label_bounds: Rectangle,
|
||||||
is_checked: bool,
|
is_checked: bool,
|
||||||
) -> MouseCursor;
|
) -> MouseCursor;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -90,5 +90,5 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub trait Renderer {
|
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(
|
fn draw(
|
||||||
&mut self,
|
&mut self,
|
||||||
cursor_position: Point,
|
cursor_position: Point,
|
||||||
bounds: Rectangle<f32>,
|
bounds: Rectangle,
|
||||||
label_bounds: Rectangle<f32>,
|
label_bounds: Rectangle,
|
||||||
is_selected: bool,
|
is_selected: bool,
|
||||||
) -> MouseCursor;
|
) -> MouseCursor;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -222,7 +222,7 @@ pub trait Renderer {
|
|||||||
fn draw(
|
fn draw(
|
||||||
&mut self,
|
&mut self,
|
||||||
cursor_position: Point,
|
cursor_position: Point,
|
||||||
bounds: Rectangle<f32>,
|
bounds: Rectangle,
|
||||||
state: &State,
|
state: &State,
|
||||||
range: RangeInclusive<f32>,
|
range: RangeInclusive<f32>,
|
||||||
value: f32,
|
value: f32,
|
||||||
|
|||||||
@ -177,7 +177,7 @@ pub trait Renderer<Color> {
|
|||||||
/// [`VerticalAlignment`]: enum.VerticalAlignment.html
|
/// [`VerticalAlignment`]: enum.VerticalAlignment.html
|
||||||
fn draw(
|
fn draw(
|
||||||
&mut self,
|
&mut self,
|
||||||
bounds: Rectangle<f32>,
|
bounds: Rectangle,
|
||||||
content: &str,
|
content: &str,
|
||||||
size: f32,
|
size: f32,
|
||||||
color: Option<Color>,
|
color: Option<Color>,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user