summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-02-14 05:35:42 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-02-14 05:35:42 +0100
commit945dfabd7135d1bd44a14e54d95b716642651ed3 (patch)
treed33e2e5eefcbd62c84f9e352574fb9ca52d07b19 /core
parentad3a0a184f877cbca3db4006e802231e201138ba (diff)
downloadiced-945dfabd7135d1bd44a14e54d95b716642651ed3.tar.gz
iced-945dfabd7135d1bd44a14e54d95b716642651ed3.tar.bz2
iced-945dfabd7135d1bd44a14e54d95b716642651ed3.zip
Move `Size` to `iced_core`
Diffstat (limited to 'core')
-rw-r--r--core/src/lib.rs2
-rw-r--r--core/src/size.rs51
2 files changed, 53 insertions, 0 deletions
diff --git a/core/src/lib.rs b/core/src/lib.rs
index 3cbce743..ea5e8b43 100644
--- a/core/src/lib.rs
+++ b/core/src/lib.rs
@@ -22,6 +22,7 @@ mod font;
mod length;
mod point;
mod rectangle;
+mod size;
mod vector;
pub use align::{Align, HorizontalAlignment, VerticalAlignment};
@@ -31,4 +32,5 @@ pub use font::Font;
pub use length::Length;
pub use point::Point;
pub use rectangle::Rectangle;
+pub use size::Size;
pub use vector::Vector;
diff --git a/core/src/size.rs b/core/src/size.rs
new file mode 100644
index 00000000..389b3247
--- /dev/null
+++ b/core/src/size.rs
@@ -0,0 +1,51 @@
+use std::f32;
+
+/// An amount of space in 2 dimensions.
+#[derive(Debug, Clone, Copy, PartialEq)]
+pub struct Size {
+ /// The width.
+ pub width: f32,
+ /// The height.
+ pub height: f32,
+}
+
+impl Size {
+ /// A [`Size`] with zero width and height.
+ ///
+ /// [`Size`]: struct.Size.html
+ pub const ZERO: Size = Size::new(0., 0.);
+
+ /// A [`Size`] with infinite width and height.
+ ///
+ /// [`Size`]: struct.Size.html
+ pub const INFINITY: Size = Size::new(f32::INFINITY, f32::INFINITY);
+
+ /// A [`Size`] of infinite width and height.
+ ///
+ /// [`Size`]: struct.Size.html
+ pub const fn new(width: f32, height: f32) -> Self {
+ Size { width, height }
+ }
+
+ /// 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,
+ height: self.height + padding * 2.0,
+ }
+ }
+}
+
+impl From<[f32; 2]> for Size {
+ fn from([width, height]: [f32; 2]) -> Self {
+ Size { width, height }
+ }
+}
+
+impl From<[u16; 2]> for Size {
+ fn from([width, height]: [u16; 2]) -> Self {
+ Size::new(width.into(), height.into())
+ }
+}