mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Replace From<T: Into<Vec2>> for Rect
with Rect::from_point
This commit is contained in:
parent
db540452a4
commit
cbaf632cc1
@ -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)`.
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user