Fix key press event bubbling for nested layouts.

This commit is contained in:
casey langen 2020-10-10 17:25:06 -07:00
parent 9a0b828c51
commit 5490030447

View File

@ -493,6 +493,19 @@ bool LayoutBase::KeyPress(const std::string& key) {
this->FocusNext();
return true;
}
/* we find the focus recursively, then let the child deepest in the
hierarchy process the key event. if that fails we move up to its parent,
and so on until we reach ourself. */
auto focus = this->GetFocus().get();
while (focus != this) {
auto asKeyHandler = dynamic_cast<IKeyHandler*>(focus);
if (asKeyHandler) {
if (asKeyHandler->KeyPress(key)) {
return true;
}
}
focus = focus->GetParent();
}
return false;
}