Replace From<T: Into<Vec2>> for Rect with Rect::from_point

This commit is contained in:
Alexandre Bury 2021-03-02 17:13:56 -08:00
parent db540452a4
commit cbaf632cc1
2 changed files with 15 additions and 11 deletions

View File

@ -14,16 +14,6 @@ pub struct Rect {
bottom_right: Vec2,
}
impl<T> From<T> for Rect
where
T: Into<Vec2>,
{
fn from(other: T) -> Self {
// From a point, we can create a 1-by-1 rectangle.
Self::from_size(other, (1, 1))
}
}
impl<T> Add<T> for Rect
where
T: Into<Vec2>,
@ -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<T>(point: T) -> Self
where
T: Into<Vec2>,
{
Self::from_size(point, (1, 1))
}
/// Creates a new `Rect` with the given position and size.
///
/// The minimum size will `(1, 1)`.

View File

@ -36,12 +36,16 @@ impl ListChild {
/// Displays a list of elements.
pub struct ListView {
children: Vec<ListChild>,
// Height for each child.
// This should have the same size as the `children` list.
children_heights: Vec<usize>,
// Which child is focused? Should index into the `children` list.
focus: usize,
// This callback is called when the selection is changed.
on_select: Option<Rc<dyn Fn(&mut Cursive, &String)>>,
}
// 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();