mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 09:25:01 +00:00
Remove debug log and fix initial focus (again)
This commit is contained in:
parent
f2b1fac679
commit
9e5491bda2
@ -140,6 +140,21 @@ impl FixedLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn circular_mut<'a>(
|
||||||
|
start: usize,
|
||||||
|
children: &'a mut [Child],
|
||||||
|
) -> impl Iterator<Item = (usize, &mut Child)> + 'a {
|
||||||
|
let (head, tail) = children.split_at_mut(start);
|
||||||
|
|
||||||
|
let head = head.iter_mut().enumerate();
|
||||||
|
let tail = tail
|
||||||
|
.iter_mut()
|
||||||
|
.enumerate()
|
||||||
|
.map(move |(i, c)| (i + start, c));
|
||||||
|
|
||||||
|
tail.chain(head)
|
||||||
|
}
|
||||||
|
|
||||||
fn move_focus_rel(&mut self, target: Relative) -> EventResult {
|
fn move_focus_rel(&mut self, target: Relative) -> EventResult {
|
||||||
let source = Direction::Rel(target.swap());
|
let source = Direction::Rel(target.swap());
|
||||||
for (i, c) in
|
for (i, c) in
|
||||||
@ -229,7 +244,6 @@ impl View for FixedLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn on_event(&mut self, event: Event) -> EventResult {
|
fn on_event(&mut self, event: Event) -> EventResult {
|
||||||
eprintln!("Self focus: {:?}", self.focus);
|
|
||||||
if self.is_empty() {
|
if self.is_empty() {
|
||||||
return EventResult::Ignored;
|
return EventResult::Ignored;
|
||||||
}
|
}
|
||||||
@ -275,13 +289,17 @@ impl View for FixedLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn take_focus(&mut self, source: Direction) -> bool {
|
fn take_focus(&mut self, source: Direction) -> bool {
|
||||||
// TODO: what if source = None?
|
|
||||||
eprintln!("Self focus: {:?}", self.focus);
|
|
||||||
match source {
|
match source {
|
||||||
Direction::Abs(Absolute::None) => {
|
Direction::Abs(Absolute::None) => {
|
||||||
// For now, take focus if any view is focusable.
|
// We want to guarantee:
|
||||||
for child in &mut self.children {
|
// * If the current focus _is_ focusable, keep it
|
||||||
if child.view.take_focus(source) {
|
// * If it isn't, find _any_ focusable view, and focus it
|
||||||
|
// * Otherwise, we can't take focus.
|
||||||
|
for (i, c) in
|
||||||
|
Self::circular_mut(self.focus, &mut self.children)
|
||||||
|
{
|
||||||
|
if c.view.take_focus(source) {
|
||||||
|
self.focus = i;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -648,7 +648,7 @@ impl View for StackView {
|
|||||||
// The text view takes focus because it's scrolling, but it only
|
// The text view takes focus because it's scrolling, but it only
|
||||||
// knows that after a call to `layout()`.
|
// knows that after a call to `layout()`.
|
||||||
if layer.virgin {
|
if layer.virgin {
|
||||||
layer.view.take_focus(Direction::front());
|
layer.view.take_focus(Direction::none());
|
||||||
layer.virgin = false;
|
layer.virgin = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user