summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-02-04 12:24:13 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-02-17 15:40:17 +0100
commit7b8b01f560569ae18d9337a31ba94f6c1c2ba0dd (patch)
treeac9aac5eb82f175990da17813985d2f864897080 /core
parentf75e0202575ca6e3ebf7d817eecbf51e198506fd (diff)
downloadiced-7b8b01f560569ae18d9337a31ba94f6c1c2ba0dd.tar.gz
iced-7b8b01f560569ae18d9337a31ba94f6c1c2ba0dd.tar.bz2
iced-7b8b01f560569ae18d9337a31ba94f6c1c2ba0dd.zip
Use `f32` in `Length::Units` and rename it to `Fixed`
Diffstat (limited to '')
-rw-r--r--core/src/length.rs14
-rw-r--r--core/src/lib.rs2
-rw-r--r--core/src/pixels.rs22
3 files changed, 34 insertions, 4 deletions
diff --git a/core/src/length.rs b/core/src/length.rs
index 95ea6e0e..bb925c4b 100644
--- a/core/src/length.rs
+++ b/core/src/length.rs
@@ -1,5 +1,5 @@
/// The strategy used to fill space in a specific dimension.
-#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
+#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Length {
/// Fill all the remaining space
Fill,
@@ -17,7 +17,7 @@ pub enum Length {
Shrink,
/// Fill a fixed amount of space
- Units(u16),
+ Fixed(f32),
}
impl Length {
@@ -31,13 +31,19 @@ impl Length {
Length::Fill => 1,
Length::FillPortion(factor) => *factor,
Length::Shrink => 0,
- Length::Units(_) => 0,
+ Length::Fixed(_) => 0,
}
}
}
+impl From<f32> for Length {
+ fn from(amount: f32) -> Self {
+ Length::Fixed(amount)
+ }
+}
+
impl From<u16> for Length {
fn from(units: u16) -> Self {
- Length::Units(units)
+ Length::Fixed(f32::from(units))
}
}
diff --git a/core/src/lib.rs b/core/src/lib.rs
index 3aa5defe..31280a05 100644
--- a/core/src/lib.rs
+++ b/core/src/lib.rs
@@ -35,6 +35,7 @@ mod content_fit;
mod font;
mod length;
mod padding;
+mod pixels;
mod point;
mod rectangle;
mod size;
@@ -47,6 +48,7 @@ pub use content_fit::ContentFit;
pub use font::Font;
pub use length::Length;
pub use padding::Padding;
+pub use pixels::Pixels;
pub use point::Point;
pub use rectangle::Rectangle;
pub use size::Size;
diff --git a/core/src/pixels.rs b/core/src/pixels.rs
new file mode 100644
index 00000000..e42cd9f9
--- /dev/null
+++ b/core/src/pixels.rs
@@ -0,0 +1,22 @@
+/// An amount of logical pixels.
+///
+/// Normally used to represent an amount of space, or the size of something.
+///
+/// This type is normally asked as an argument in a generic way
+/// (e.g. `impl Into<Pixels>`) and, since `Pixels` implements `From` both for
+/// `f32` and `u16`, you should be able to provide both integers and float
+/// literals as needed.
+#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
+pub struct Pixels(pub f32);
+
+impl From<f32> for Pixels {
+ fn from(amount: f32) -> Self {
+ Self(amount)
+ }
+}
+
+impl From<u16> for Pixels {
+ fn from(amount: u16) -> Self {
+ Self(f32::from(amount))
+ }
+}