From 0a087cd28bbee5fcdffbb9d49b0ba9f413ad7f92 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 24 Jan 2020 16:23:57 +0100 Subject: =?UTF-8?q?Reorganize=20modules=20=F0=9F=A7=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/size.rs | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'src/size.rs') diff --git a/src/size.rs b/src/size.rs index a5bc5d7f..9dc74dd6 100644 --- a/src/size.rs +++ b/src/size.rs @@ -129,7 +129,7 @@ pub type PSize = ScaleSize; /// A value in two dimensions. #[derive(Default, Copy, Clone, PartialEq)] -pub struct Value2D { +pub struct Value2D { /// The horizontal component. pub x: T, /// The vertical component. @@ -226,13 +226,13 @@ impl Value2D { } } -impl Display for Value2D where T: Display { +impl Display for Value2D where T: Display { fn fmt(&self, f: &mut Formatter) -> fmt::Result { write!(f, "[{}, {}]", self.x, self.y) } } -impl Debug for Value2D where T: Debug { +impl Debug for Value2D where T: Debug { fn fmt(&self, f: &mut Formatter) -> fmt::Result { write!(f, "[{:?}, {:?}]", self.x, self.y) } @@ -293,7 +293,7 @@ impl Neg for Size2D { /// A value that is stretchable in an interval from a minimal through an optimal /// to a maximal value. -pub struct StretchValue { +pub struct StretchValue { /// The minimum this value can be stretched to. pub min: T, /// The optimum for this value. @@ -302,20 +302,20 @@ pub struct StretchValue { pub max: T, } -impl StretchValue { +impl StretchValue { /// Create a new stretch size from minimum, optimal and maximum values. pub fn new(min: T, opt: T, max: T) -> StretchValue { StretchValue { min, opt, max } } } -impl Display for StretchValue where T: Display { +impl Display for StretchValue where T: Display { fn fmt(&self, f: &mut Formatter) -> fmt::Result { write!(f, "({}, {}, {})", self.min, self.opt, self.max) } } -impl Debug for StretchValue where T: Debug { +impl Debug for StretchValue where T: Debug { fn fmt(&self, f: &mut Formatter) -> fmt::Result { write!(f, "({:?}, {:?}, {:?})", self.min, self.opt, self.max) } @@ -326,7 +326,7 @@ pub type StretchSize = StretchValue; /// A value in four dimensions. #[derive(Default, Copy, Clone, PartialEq)] -pub struct ValueBox { +pub struct ValueBox { /// The left extent. pub left: T, /// The top extent. @@ -337,7 +337,7 @@ pub struct ValueBox { pub bottom: T, } -impl ValueBox { +impl ValueBox { /// Create a new box from four sizes. pub fn new(left: T, top: T, right: T, bottom: T) -> ValueBox { ValueBox { left, top, right, bottom } @@ -345,7 +345,12 @@ impl ValueBox { /// Create a box with all four fields set to the same value `s`. pub fn with_all(value: T) -> ValueBox { - ValueBox { left: value, top: value, right: value, bottom: value } + ValueBox { + left: value.clone(), + top: value.clone(), + right: value.clone(), + bottom: value + } } /// Get a mutable reference to the value for the specified direction at the @@ -372,25 +377,25 @@ impl ValueBox { /// Set the `left` and `right` values. pub fn set_horizontal(&mut self, value: T) { - self.left = value; + self.left = value.clone(); self.right = value; } /// Set the `top` and `bottom` values. pub fn set_vertical(&mut self, value: T) { - self.top = value; + self.top = value.clone(); self.bottom = value; } } -impl Display for ValueBox where T: Display { +impl Display for ValueBox where T: Display { fn fmt(&self, f: &mut Formatter) -> fmt::Result { write!(f, "[left: {}, top: {}, right: {}, bottom: {}]", self.left, self.top, self.right, self.bottom) } } -impl Debug for ValueBox where T: Debug { +impl Debug for ValueBox where T: Debug { fn fmt(&self, f: &mut Formatter) -> fmt::Result { write!(f, "[left: {:?}, top: {:?}, right: {:?}, bottom: {:?}]", self.left, self.top, self.right, self.bottom) -- cgit v1.2.3