Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax constraints on who can change focus #1651

Merged
merged 1 commit into from
Mar 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions druid/src/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,10 +576,13 @@ impl EventCtx<'_, '_> {
/// [`is_focused`]: struct.EventCtx.html#method.is_focused
pub fn focus_next(&mut self) {
trace!("focus_next");
if self.is_focused() {
if self.has_focus() {
self.widget_state.request_focus = Some(FocusChange::Next);
} else {
warn!("focus_next can only be called by the currently focused widget");
warn!(
"focus_next can only be called by the currently \
focused widget or one of its ancestors."
);
}
}

Expand All @@ -592,10 +595,13 @@ impl EventCtx<'_, '_> {
/// [`is_focused`]: struct.EventCtx.html#method.is_focused
pub fn focus_prev(&mut self) {
trace!("focus_prev");
if self.is_focused() {
if self.has_focus() {
self.widget_state.request_focus = Some(FocusChange::Previous);
} else {
warn!("focus_prev can only be called by the currently focused widget");
warn!(
"focus_prev can only be called by the currently \
focused widget or one of its ancestors."
);
}
}

Expand All @@ -608,11 +614,12 @@ impl EventCtx<'_, '_> {
/// [`is_focused`]: struct.EventCtx.html#method.is_focused
pub fn resign_focus(&mut self) {
trace!("resign_focus");
if self.is_focused() {
if self.has_focus() {
self.widget_state.request_focus = Some(FocusChange::Resign);
} else {
warn!(
"resign_focus can only be called by the currently focused widget ({:?})",
"resign_focus can only be called by the currently focused widget \
or one of its ancestors. ({:?})",
self.widget_id()
);
}
Expand Down