Replace usages of Rect::from

This commit is contained in:
Alexandre Bury 2021-03-02 18:25:32 -08:00
parent cbaf632cc1
commit 7cf597f9bb
7 changed files with 10 additions and 10 deletions

View File

@ -101,7 +101,7 @@ pub trait ViewWrapper: 'static {
/// Wraps the `important_area` method.
fn wrap_important_area(&self, size: Vec2) -> Rect {
self.with_view(|v| v.important_area(size))
.unwrap_or_else(|| Rect::from((0, 0)))
.unwrap_or_else(|| Rect::from_size(Vec2::zero(), size))
}
}

View File

@ -729,10 +729,10 @@ impl View for LinearLayout {
Err(ViewNotFound)
}
fn important_area(&self, _: Vec2) -> Rect {
fn important_area(&self, size: Vec2) -> Rect {
if self.is_empty() {
// Return dummy area if we are empty.
return Rect::from((0, 0));
return Rect::from_size(Vec2::zero(), size);
}
// Pick the focused item, with its offset

View File

@ -303,7 +303,7 @@ impl MenuPopup {
fn inner_important_area(&self, size: Vec2) -> Rect {
if self.menu.is_empty() {
return Rect::from((0, 0));
return Rect::from_size(Vec2::zero(), size);
}
Rect::from_size((0, self.focus), (size.x, 1))

View File

@ -414,9 +414,9 @@ impl View for Menubar {
Vec2::new(width, 1)
}
fn important_area(&self, _: Vec2) -> Rect {
fn important_area(&self, size: Vec2) -> Rect {
if self.root.is_empty() {
return Rect::from((0, 0));
return Rect::from_size(Vec2::zero(), size);
}
// X position is 1 (margin before the first item) + sum of widths

View File

@ -973,7 +973,7 @@ impl<T: 'static> View for SelectView<T> {
fn important_area(&self, size: Vec2) -> Rect {
self.selected_id()
.map(|i| Rect::from_size((0, i), (size.x, 1)))
.unwrap_or_else(|| Rect::from((0, 0)))
.unwrap_or_else(|| Rect::from_size(Vec2::zero(), size))
}
}

View File

@ -364,9 +364,9 @@ impl<'a> ObservedLine<'a> {
line_len: usize,
) -> Self {
ObservedLine {
parent,
line_start,
line_len,
parent,
}
}
@ -380,9 +380,9 @@ impl<'a> ObservedLine<'a> {
);
ObservedLine {
parent: self.parent,
line_start: Vec2::new(self.line_start.x - left, self.line_start.y),
line_len: self.line_len + left + right,
parent: self.parent,
}
}
}

View File

@ -63,7 +63,7 @@ impl BufferView {
fn new(size: usize, rx: mpsc::Receiver<String>) -> Self {
let mut buffer = VecDeque::new();
buffer.resize(size, String::new());
BufferView { rx, buffer }
BufferView { buffer, rx }
}
// Reads available data from the stream into the buffer