summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/src/color.rs25
-rw-r--r--core/src/keyboard.rs4
-rw-r--r--core/src/keyboard/event.rs8
-rw-r--r--core/src/keyboard/modifiers.rs (renamed from core/src/keyboard/modifiers_state.rs)17
-rw-r--r--core/src/length.rs2
-rw-r--r--core/src/point.rs6
-rw-r--r--core/src/rectangle.rs28
-rw-r--r--core/src/size.rs10
-rw-r--r--core/src/vector.rs6
9 files changed, 12 insertions, 94 deletions
diff --git a/core/src/color.rs b/core/src/color.rs
index a4c3d87c..c66ee97c 100644
--- a/core/src/color.rs
+++ b/core/src/color.rs
@@ -43,8 +43,6 @@ impl Color {
///
/// In debug mode, it will panic if the values are not in the correct
/// range: 0.0 - 1.0
- ///
- /// [`Color`]: struct.Color.html
pub fn new(r: f32, g: f32, b: f32, a: f32) -> Color {
debug_assert!(
(0.0..=1.0).contains(&r),
@@ -67,29 +65,21 @@ impl Color {
}
/// Creates a [`Color`] from its RGB components.
- ///
- /// [`Color`]: struct.Color.html
pub const fn from_rgb(r: f32, g: f32, b: f32) -> Color {
Color::from_rgba(r, g, b, 1.0f32)
}
/// Creates a [`Color`] from its RGBA components.
- ///
- /// [`Color`]: struct.Color.html
pub const fn from_rgba(r: f32, g: f32, b: f32, a: f32) -> Color {
Color { r, g, b, a }
}
/// Creates a [`Color`] from its RGB8 components.
- ///
- /// [`Color`]: struct.Color.html
pub fn from_rgb8(r: u8, g: u8, b: u8) -> Color {
Color::from_rgba8(r, g, b, 1.0)
}
/// Creates a [`Color`] from its RGB8 components and an alpha value.
- ///
- /// [`Color`]: struct.Color.html
pub fn from_rgba8(r: u8, g: u8, b: u8, a: f32) -> Color {
Color {
r: f32::from(r) / 255.0,
@@ -100,8 +90,6 @@ impl Color {
}
/// Converts the [`Color`] into its linear values.
- ///
- /// [`Color`]: struct.Color.html
pub fn into_linear(self) -> [f32; 4] {
// As described in:
// https://en.wikipedia.org/wiki/SRGB#The_reverse_transformation
@@ -122,8 +110,6 @@ impl Color {
}
/// Inverts the [`Color`] in-place.
- ///
- /// [`Color`]: struct.Color.html
pub fn invert(&mut self) {
self.r = 1.0f32 - self.r;
self.b = 1.0f32 - self.g;
@@ -131,8 +117,6 @@ impl Color {
}
/// Returns the inverted [`Color`].
- ///
- /// [`Color`]: struct.Color.html
pub fn inverse(self) -> Color {
Color::new(1.0f32 - self.r, 1.0f32 - self.g, 1.0f32 - self.b, self.a)
}
@@ -152,8 +136,6 @@ impl From<[f32; 4]> for Color {
#[cfg(feature = "palette")]
/// Converts from palette's `Srgba` type to a [`Color`].
-///
-/// [`Color`]: struct.Color.html
impl From<Srgba> for Color {
fn from(srgba: Srgba) -> Self {
Color::new(srgba.red, srgba.green, srgba.blue, srgba.alpha)
@@ -162,8 +144,6 @@ impl From<Srgba> for Color {
#[cfg(feature = "palette")]
/// Converts from [`Color`] to palette's `Srgba` type.
-///
-/// [`Color`]: struct.Color.html
impl From<Color> for Srgba {
fn from(c: Color) -> Self {
Srgba::new(c.r, c.g, c.b, c.a)
@@ -172,8 +152,6 @@ impl From<Color> for Srgba {
#[cfg(feature = "palette")]
/// Converts from palette's `Srgb` type to a [`Color`].
-///
-/// [`Color`]: struct.Color.html
impl From<Srgb> for Color {
fn from(srgb: Srgb) -> Self {
Color::new(srgb.red, srgb.green, srgb.blue, 1.0)
@@ -182,9 +160,6 @@ impl From<Srgb> for Color {
#[cfg(feature = "palette")]
/// Converts from [`Color`] to palette's `Srgb` type.
-///
-/// [`Color`]: struct.Color.html
-/// [`Srgb`]: ../palette/rgb/type.Srgb.html
impl From<Color> for Srgb {
fn from(c: Color) -> Self {
Srgb::new(c.r, c.g, c.b)
diff --git a/core/src/keyboard.rs b/core/src/keyboard.rs
index b26bdb3d..61e017ad 100644
--- a/core/src/keyboard.rs
+++ b/core/src/keyboard.rs
@@ -1,8 +1,8 @@
//! Reuse basic keyboard types.
mod event;
mod key_code;
-mod modifiers_state;
+mod modifiers;
pub use event::Event;
pub use key_code::KeyCode;
-pub use modifiers_state::ModifiersState;
+pub use modifiers::Modifiers;
diff --git a/core/src/keyboard/event.rs b/core/src/keyboard/event.rs
index d142c3bc..0564c171 100644
--- a/core/src/keyboard/event.rs
+++ b/core/src/keyboard/event.rs
@@ -1,4 +1,4 @@
-use super::{KeyCode, ModifiersState};
+use super::{KeyCode, Modifiers};
/// A keyboard event.
///
@@ -14,7 +14,7 @@ pub enum Event {
key_code: KeyCode,
/// The state of the modifier keys
- modifiers: ModifiersState,
+ modifiers: Modifiers,
},
/// A keyboard key was released.
@@ -23,12 +23,12 @@ pub enum Event {
key_code: KeyCode,
/// The state of the modifier keys
- modifiers: ModifiersState,
+ modifiers: Modifiers,
},
/// A unicode character was received.
CharacterReceived(char),
/// The keyboard modifiers have changed.
- ModifiersChanged(ModifiersState),
+ ModifiersChanged(Modifiers),
}
diff --git a/core/src/keyboard/modifiers_state.rs b/core/src/keyboard/modifiers.rs
index 254013c3..d2a0500e 100644
--- a/core/src/keyboard/modifiers_state.rs
+++ b/core/src/keyboard/modifiers.rs
@@ -1,6 +1,6 @@
/// The current state of the keyboard modifiers.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
-pub struct ModifiersState {
+pub struct Modifiers {
/// Whether a shift key is pressed
pub shift: bool,
@@ -14,17 +14,14 @@ pub struct ModifiersState {
pub logo: bool,
}
-impl ModifiersState {
- /// Returns true if the current [`ModifiersState`] has a "command key"
- /// pressed.
+impl Modifiers {
+ /// Returns true if a "command key" is pressed in the [`Modifiers`].
///
/// The "command key" is the main modifier key used to issue commands in the
/// current platform. Specifically:
///
/// - It is the `logo` or command key (⌘) on macOS
/// - It is the `control` key on other platforms
- ///
- /// [`ModifiersState`]: struct.ModifiersState.html
pub fn is_command_pressed(self) -> bool {
#[cfg(target_os = "macos")]
let is_pressed = self.logo;
@@ -35,11 +32,9 @@ impl ModifiersState {
is_pressed
}
- /// Returns true if the current [`ModifiersState`] has at least the same
- /// modifiers enabled as the given value, and false otherwise.
- ///
- /// [`ModifiersState`]: struct.ModifiersState.html
- pub fn matches(&self, modifiers: ModifiersState) -> bool {
+ /// Returns true if the current [`Modifiers`] have at least the same
+ /// keys pressed as the provided ones, and false otherwise.
+ pub fn matches(&self, modifiers: Self) -> bool {
let shift = !modifiers.shift || self.shift;
let control = !modifiers.control || self.control;
let alt = !modifiers.alt || self.alt;
diff --git a/core/src/length.rs b/core/src/length.rs
index 06d8cf0a..186411a5 100644
--- a/core/src/length.rs
+++ b/core/src/length.rs
@@ -26,8 +26,6 @@ impl Length {
/// The _fill factor_ is a relative unit describing how much of the
/// remaining space should be filled when compared to other elements. It
/// is only meant to be used by layout engines.
- ///
- /// [`Length`]: enum.Length.html
pub fn fill_factor(&self) -> u16 {
match self {
Length::Fill => 1,
diff --git a/core/src/point.rs b/core/src/point.rs
index 7d93538f..9bf7726b 100644
--- a/core/src/point.rs
+++ b/core/src/point.rs
@@ -12,20 +12,14 @@ pub struct Point {
impl Point {
/// The origin (i.e. a [`Point`] at (0, 0)).
- ///
- /// [`Point`]: struct.Point.html
pub const ORIGIN: Point = Point::new(0.0, 0.0);
/// Creates a new [`Point`] with the given coordinates.
- ///
- /// [`Point`]: struct.Point.html
pub const fn new(x: f32, y: f32) -> Self {
Self { x, y }
}
/// Computes the distance to another [`Point`].
- ///
- /// [`Point`]: struct.Point.html
pub fn distance(&self, to: Point) -> f32 {
let a = self.x - to.x;
let b = self.y - to.y;
diff --git a/core/src/rectangle.rs b/core/src/rectangle.rs
index ce80c661..0a7f5fe2 100644
--- a/core/src/rectangle.rs
+++ b/core/src/rectangle.rs
@@ -19,10 +19,6 @@ pub struct Rectangle<T = f32> {
impl Rectangle<f32> {
/// Creates a new [`Rectangle`] with its top-left corner in the given
/// [`Point`] and with the provided [`Size`].
- ///
- /// [`Rectangle`]: struct.Rectangle.html
- /// [`Point`]: struct.Point.html
- /// [`Size`]: struct.Size.html
pub fn new(top_left: Point, size: Size) -> Self {
Self {
x: top_left.x,
@@ -34,9 +30,6 @@ impl Rectangle<f32> {
/// Creates a new [`Rectangle`] with its top-left corner at the origin
/// and with the provided [`Size`].
- ///
- /// [`Rectangle`]: struct.Rectangle.html
- /// [`Size`]: struct.Size.html
pub fn with_size(size: Size) -> Self {
Self {
x: 0.0,
@@ -47,50 +40,33 @@ impl Rectangle<f32> {
}
/// Returns the [`Point`] at the center of the [`Rectangle`].
- ///
- /// [`Point`]: struct.Point.html
- /// [`Rectangle`]: struct.Rectangle.html
pub fn center(&self) -> Point {
Point::new(self.center_x(), self.center_y())
}
/// Returns the X coordinate of the [`Point`] at the center of the
/// [`Rectangle`].
- ///
- /// [`Point`]: struct.Point.html
- /// [`Rectangle`]: struct.Rectangle.html
pub fn center_x(&self) -> f32 {
self.x + self.width / 2.0
}
/// Returns the Y coordinate of the [`Point`] at the center of the
/// [`Rectangle`].
- ///
- /// [`Point`]: struct.Point.html
- /// [`Rectangle`]: struct.Rectangle.html
pub fn center_y(&self) -> f32 {
self.y + self.height / 2.0
}
/// Returns the position of the top left corner of the [`Rectangle`].
- ///
- /// [`Rectangle`]: struct.Rectangle.html
pub fn position(&self) -> Point {
Point::new(self.x, self.y)
}
/// Returns the [`Size`] of the [`Rectangle`].
- ///
- /// [`Size`]: struct.Size.html
- /// [`Rectangle`]: struct.Rectangle.html
pub fn size(&self) -> Size {
Size::new(self.width, self.height)
}
/// Returns true if the given [`Point`] is contained in the [`Rectangle`].
- ///
- /// [`Point`]: struct.Point.html
- /// [`Rectangle`]: struct.Rectangle.html
pub fn contains(&self, point: Point) -> bool {
self.x <= point.x
&& point.x <= self.x + self.width
@@ -99,8 +75,6 @@ impl Rectangle<f32> {
}
/// Computes the intersection with the given [`Rectangle`].
- ///
- /// [`Rectangle`]: struct.Rectangle.html
pub fn intersection(
&self,
other: &Rectangle<f32>,
@@ -127,8 +101,6 @@ impl Rectangle<f32> {
}
/// Snaps the [`Rectangle`] to __unsigned__ integer coordinates.
- ///
- /// [`Rectangle`]: struct.Rectangle.html
pub fn snap(self) -> Rectangle<u32> {
Rectangle {
x: self.x as u32,
diff --git a/core/src/size.rs b/core/src/size.rs
index 5c130978..9ea9e686 100644
--- a/core/src/size.rs
+++ b/core/src/size.rs
@@ -12,8 +12,6 @@ pub struct Size<T = f32> {
impl<T> Size<T> {
/// Creates a new [`Size`] with the given width and height.
- ///
- /// [`Size`]: struct.Size.html
pub const fn new(width: T, height: T) -> Self {
Size { width, height }
}
@@ -21,23 +19,15 @@ impl<T> Size<T> {
impl Size {
/// A [`Size`] with zero width and height.
- ///
- /// [`Size`]: struct.Size.html
pub const ZERO: Size = Size::new(0., 0.);
/// A [`Size`] with a width and height of 1 unit.
- ///
- /// [`Size`]: struct.Size.html
pub const UNIT: Size = Size::new(1., 1.);
/// A [`Size`] with infinite width and height.
- ///
- /// [`Size`]: struct.Size.html
pub const INFINITY: Size = Size::new(f32::INFINITY, f32::INFINITY);
/// Increments the [`Size`] to account for the given padding.
- ///
- /// [`Size`]: struct.Size.html
pub fn pad(&self, padding: f32) -> Self {
Size {
width: self.width + padding * 2.0,
diff --git a/core/src/vector.rs b/core/src/vector.rs
index e31924e7..92bb7648 100644
--- a/core/src/vector.rs
+++ b/core/src/vector.rs
@@ -2,20 +2,14 @@
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Vector<T = f32> {
/// The X component of the [`Vector`]
- ///
- /// [`Vector`]: struct.Vector.html
pub x: T,
/// The Y component of the [`Vector`]
- ///
- /// [`Vector`]: struct.Vector.html
pub y: T,
}
impl<T> Vector<T> {
/// Creates a new [`Vector`] with the given components.
- ///
- /// [`Vector`]: struct.Vector.html
pub const fn new(x: T, y: T) -> Self {
Self { x, y }
}