summaryrefslogtreecommitdiffstats
path: root/core/src
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2020-04-10 23:16:21 +0200
committerLibravatar GitHub <noreply@github.com>2020-04-10 23:16:21 +0200
commite941eab4ab58da4473dd4473215bc4f36684dafb (patch)
treeeae9d2bd0880e46c9f7c5fe93282951c8ecd36d3 /core/src
parent19f6a5e2fd685c76a06576e45c64e7c9e3b3a57f (diff)
parent47d44af348db79735233e408b1560661b9f96960 (diff)
downloadiced-e941eab4ab58da4473dd4473215bc4f36684dafb.tar.gz
iced-e941eab4ab58da4473dd4473215bc4f36684dafb.tar.bz2
iced-e941eab4ab58da4473dd4473215bc4f36684dafb.zip
Merge pull request #281 from hecrj/fix/canvas-text-alignment
Align text in `iced_wgpu` on a case-by-case basis
Diffstat (limited to 'core/src')
-rw-r--r--core/src/rectangle.rs26
1 files changed, 26 insertions, 0 deletions
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