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();