mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 09:25:01 +00:00
Add LinearLayout::set_focus_index
This commit is contained in:
parent
de0d76f796
commit
aa74e691e1
@ -207,6 +207,24 @@ impl LinearLayout {
|
||||
self.focus
|
||||
}
|
||||
|
||||
/// Attemps to set the focus on the given child.
|
||||
///
|
||||
/// Returns `Err(())` if `index >= self.len()`, or if the view at the
|
||||
/// given index does not accept focus.
|
||||
pub fn set_focus_index(&mut self, index: usize) -> Result<(), ()> {
|
||||
if self
|
||||
.children
|
||||
.get_mut(index)
|
||||
.map(|child| child.view.take_focus(direction::Direction::none()))
|
||||
.unwrap_or(false)
|
||||
{
|
||||
self.focus = index;
|
||||
Ok(())
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
||||
// Invalidate the view, to request a layout next time
|
||||
fn invalidate(&mut self) {
|
||||
self.cache = None;
|
||||
|
Loading…
Reference in New Issue
Block a user