From cbaf632cc1e81157fcae8fcbde8bb1a525128d25 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Tue, 2 Mar 2021 17:13:56 -0800 Subject: [PATCH] Replace `From> for Rect` with `Rect::from_point` --- cursive-core/src/rect.rs | 20 ++++++++++---------- cursive-core/src/views/list_view.rs | 6 +++++- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/cursive-core/src/rect.rs b/cursive-core/src/rect.rs index fc1afaf..16d3205 100644 --- a/cursive-core/src/rect.rs +++ b/cursive-core/src/rect.rs @@ -14,16 +14,6 @@ pub struct Rect { bottom_right: Vec2, } -impl From for Rect -where - T: Into, -{ - fn from(other: T) -> Self { - // From a point, we can create a 1-by-1 rectangle. - Self::from_size(other, (1, 1)) - } -} - impl Add for Rect where T: Into, @@ -37,6 +27,16 @@ where } impl Rect { + /// Creates a new `Rect` around a single point. + /// + /// The size will be `(1, 1)`. + pub fn from_point(point: T) -> Self + where + T: Into, + { + Self::from_size(point, (1, 1)) + } + /// Creates a new `Rect` with the given position and size. /// /// The minimum size will `(1, 1)`. diff --git a/cursive-core/src/views/list_view.rs b/cursive-core/src/views/list_view.rs index 282d578..899f707 100644 --- a/cursive-core/src/views/list_view.rs +++ b/cursive-core/src/views/list_view.rs @@ -36,12 +36,16 @@ impl ListChild { /// Displays a list of elements. pub struct ListView { children: Vec, + // Height for each child. + // This should have the same size as the `children` list. children_heights: Vec, + // Which child is focused? Should index into the `children` list. focus: usize, // This callback is called when the selection is changed. on_select: Option>, } +// Implement `Default` around `ListView::new` new_default!(ListView); impl ListView { @@ -450,7 +454,7 @@ impl View for ListView { fn important_area(&self, size: Vec2) -> Rect { if self.children.is_empty() { - return Rect::from((0, 0)); + return Rect::from_size(Vec2::zero(), size); } let labels_width = self.labels_width();