mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Fix important_size for SelectView and ListView
This commit is contained in:
parent
861b5fbd1d
commit
9b3b16f64d
13
src/rect.rs
13
src/rect.rs
@ -3,8 +3,6 @@ use std::ops::Add;
|
||||
use vec::Vec2;
|
||||
|
||||
/// A non-empty rectangle on the 2D grid.
|
||||
///
|
||||
///
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct Rect {
|
||||
/// Top-left corner, inclusive
|
||||
@ -38,7 +36,7 @@ where
|
||||
impl Rect {
|
||||
/// Creates a new `Rect` with the given position and size.
|
||||
///
|
||||
/// `size` must be non-zero in each axis.
|
||||
/// The minimum size will `(1, 1)`.
|
||||
pub fn from_size<U, V>(top_left: U, size: V) -> Self
|
||||
where
|
||||
U: Into<Vec2>,
|
||||
@ -46,7 +44,6 @@ impl Rect {
|
||||
{
|
||||
let size = size.into();
|
||||
let top_left = top_left.into();
|
||||
assert!(size > Vec2::zero());
|
||||
|
||||
let bottom_right = top_left + size.saturating_sub((1, 1));
|
||||
|
||||
@ -119,21 +116,29 @@ impl Rect {
|
||||
}
|
||||
|
||||
/// Returns the top-left corner.
|
||||
///
|
||||
/// This is inclusive.
|
||||
pub fn top_left(self) -> Vec2 {
|
||||
self.top_left
|
||||
}
|
||||
|
||||
/// Returns the bottom-right corner.
|
||||
///
|
||||
/// This is inclusive.
|
||||
pub fn bottom_right(self) -> Vec2 {
|
||||
self.bottom_right
|
||||
}
|
||||
|
||||
/// Returns the top-right corner.
|
||||
///
|
||||
/// This is inclusive.
|
||||
pub fn top_right(self) -> Vec2 {
|
||||
Vec2::new(self.right(), self.top())
|
||||
}
|
||||
|
||||
/// Returns the bottom-left corner.
|
||||
///
|
||||
/// This is inclusive.
|
||||
pub fn bottom_left(self) -> Vec2 {
|
||||
Vec2::new(self.left(), self.bottom())
|
||||
}
|
||||
|
@ -106,6 +106,6 @@ pub trait View: Any + AnyView {
|
||||
///
|
||||
/// Default implementation return the entire view.
|
||||
fn important_area(&self, view_size: Vec2) -> Rect {
|
||||
Rect::from_corners((0, 0), view_size)
|
||||
Rect::from_size((0, 0), view_size)
|
||||
}
|
||||
}
|
||||
|
@ -239,11 +239,13 @@ fn try_focus(
|
||||
) -> Option<usize> {
|
||||
match *child {
|
||||
ListChild::Delimiter => None,
|
||||
ListChild::Row(_, ref mut view) => if view.take_focus(source) {
|
||||
Some(i)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
ListChild::Row(_, ref mut view) => {
|
||||
if view.take_focus(source) {
|
||||
Some(i)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -409,7 +411,8 @@ impl View for ListView {
|
||||
|
||||
let area = match self.children[self.focus] {
|
||||
ListChild::Row(_, ref view) => {
|
||||
let available = Vec2::new(size.x - labels_width - 1, 1);
|
||||
let available =
|
||||
Vec2::new(size.x.saturating_sub(labels_width + 1), 1);
|
||||
view.important_area(available) + (labels_width, 0)
|
||||
}
|
||||
ListChild::Delimiter => Rect::from_size((0, 0), (size.x, 1)),
|
||||
|
@ -510,7 +510,8 @@ impl<T: 'static> SelectView<T> {
|
||||
.checked_sub(offset)
|
||||
.map(|position| {
|
||||
position < self.last_size && position.y < self.len()
|
||||
}).unwrap_or(false) =>
|
||||
})
|
||||
.unwrap_or(false) =>
|
||||
{
|
||||
self.focus.set(position.y - offset.y)
|
||||
}
|
||||
@ -523,7 +524,8 @@ impl<T: 'static> SelectView<T> {
|
||||
.checked_sub(offset)
|
||||
.map(|position| {
|
||||
position < self.last_size && position.y == self.focus()
|
||||
}).unwrap_or(false) =>
|
||||
})
|
||||
.unwrap_or(false) =>
|
||||
{
|
||||
return self.submit();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user