mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Invalidate cache on mutable child access
This commit is contained in:
parent
8f6b37db00
commit
760cf11d92
@ -182,6 +182,8 @@ impl LinearLayout {
|
|||||||
|
|
||||||
/// Returns a mutable reference to a child.
|
/// Returns a mutable reference to a child.
|
||||||
pub fn get_child_mut(&mut self, i: usize) -> Option<&mut View> {
|
pub fn get_child_mut(&mut self, i: usize) -> Option<&mut View> {
|
||||||
|
// Anything could happen to the child view, so bust the cache.
|
||||||
|
self.invalidate();
|
||||||
self.children.get_mut(i).map(|child| &mut *child.view)
|
self.children.get_mut(i).map(|child| &mut *child.view)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,13 +192,20 @@ impl LinearLayout {
|
|||||||
/// If `i` is within bounds, the removed child will be returned.
|
/// If `i` is within bounds, the removed child will be returned.
|
||||||
pub fn remove_child(&mut self, i: usize) -> Option<Box<View>> {
|
pub fn remove_child(&mut self, i: usize) -> Option<Box<View>> {
|
||||||
if i < self.children.len() {
|
if i < self.children.len() {
|
||||||
|
// Any alteration means we should invalidate the cache.
|
||||||
self.invalidate();
|
self.invalidate();
|
||||||
|
|
||||||
if self.focus > i || (self.focus != 0 && self.focus == self.children.len() - 1) {
|
// Keep the same view focused.
|
||||||
|
if self.focus > i
|
||||||
|
|| (self.focus != 0 && self.focus == self.children.len() - 1)
|
||||||
|
{
|
||||||
self.focus -= 1;
|
self.focus -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the wrapped view
|
||||||
Some(self.children.remove(i).view)
|
Some(self.children.remove(i).view)
|
||||||
} else {
|
} else {
|
||||||
|
// This includes empty list
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user