Focus is now blurred when disabled

apply_pending_state now checks that the focused widget is still enabled.
If not, it transitions to no focus.
This commit is contained in:
Jonathan Johnson 2023-11-15 13:43:26 -08:00
parent 294b1350c4
commit 70eecb7429
No known key found for this signature in database
GPG key ID: A66D6A34D6620579
2 changed files with 23 additions and 11 deletions

View file

@ -228,10 +228,14 @@ impl<'context, 'window> EventContext<'context, 'window> {
let mut focus_changes = 0;
while focus_changes < MAX_ITERS {
let focus = self
let focus = match self
.pending_state
.focus
.and_then(|w| self.current_node.tree.widget(w));
.and_then(|w| self.current_node.tree.widget(w))
{
Some(focus) => self.for_other(&focus).enabled().then_some(focus),
None => None,
};
if self.current_node.tree.focused_widget() == focus.as_ref().map(|w| w.node_id) {
break;
}
@ -377,11 +381,11 @@ impl<'context, 'window> EventContext<'context, 'window> {
break;
}
if child
.lock()
.as_widget()
.accept_focus(&mut self.for_other(&child))
{
let mut child_context = self.for_other(&child);
let accept_focus = child_context.enabled()
&& child.lock().as_widget().accept_focus(&mut child_context);
drop(child_context);
if accept_focus {
return Some(child.id());
} else if let Some(next_focus) = self.widget().explicit_focus_target(advance) {
return Some(next_focus.id());

View file

@ -284,7 +284,7 @@ struct GooeyWindow<T> {
initial_frame: bool,
occluded: Dynamic<bool>,
focused: Dynamic<bool>,
keyboard_activated: Option<ManagedWidget>,
keyboard_activated: Option<WidgetId>,
min_inner_size: Option<Size<UPx>>,
max_inner_size: Option<Size<UPx>>,
theme: Option<DynamicReader<ThemePair>>,
@ -312,7 +312,11 @@ where
) {
if is_pressed {
if let Some(default) = widget.and_then(|id| self.root.tree.widget_from_node(id)) {
if let Some(previously_active) = self.keyboard_activated.take() {
if let Some(previously_active) = self
.keyboard_activated
.take()
.and_then(|id| self.root.tree.widget(id))
{
EventContext::new(
WidgetContext::new(
previously_active,
@ -338,9 +342,13 @@ where
kludgine,
)
.activate();
self.keyboard_activated = Some(default);
self.keyboard_activated = Some(default.id());
}
} else if let Some(keyboard_activated) = self.keyboard_activated.take() {
} else if let Some(keyboard_activated) = self
.keyboard_activated
.take()
.and_then(|id| self.root.tree.widget(id))
{
EventContext::new(
WidgetContext::new(
keyboard_activated,