summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/Cargo.toml2
-rw-r--r--core/src/rectangle.rs26
2 files changed, 27 insertions, 1 deletions
diff --git a/core/Cargo.toml b/core/Cargo.toml
index 24e9513a..837f6aae 100644
--- a/core/Cargo.toml
+++ b/core/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "iced_core"
-version = "0.2.0"
+version = "0.2.1"
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
edition = "2018"
description = "The essential concepts of Iced"
diff --git a/core/src/rectangle.rs b/core/src/rectangle.rs
index 7ed3d2df..aead6e9a 100644
--- a/core/src/rectangle.rs
+++ b/core/src/rectangle.rs
@@ -17,6 +17,32 @@ pub struct Rectangle<T = f32> {
}
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 true if the given [`Point`] is contained in the [`Rectangle`].
///
/// [`Point`]: struct.Point.html