mirror of
https://github.com/danbulant/cushy
synced 2026-05-27 05:42:43 +00:00
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:
parent
294b1350c4
commit
70eecb7429
2 changed files with 23 additions and 11 deletions
|
|
@ -228,10 +228,14 @@ impl<'context, 'window> EventContext<'context, 'window> {
|
||||||
|
|
||||||
let mut focus_changes = 0;
|
let mut focus_changes = 0;
|
||||||
while focus_changes < MAX_ITERS {
|
while focus_changes < MAX_ITERS {
|
||||||
let focus = self
|
let focus = match self
|
||||||
.pending_state
|
.pending_state
|
||||||
.focus
|
.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) {
|
if self.current_node.tree.focused_widget() == focus.as_ref().map(|w| w.node_id) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -377,11 +381,11 @@ impl<'context, 'window> EventContext<'context, 'window> {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if child
|
let mut child_context = self.for_other(&child);
|
||||||
.lock()
|
let accept_focus = child_context.enabled()
|
||||||
.as_widget()
|
&& child.lock().as_widget().accept_focus(&mut child_context);
|
||||||
.accept_focus(&mut self.for_other(&child))
|
drop(child_context);
|
||||||
{
|
if accept_focus {
|
||||||
return Some(child.id());
|
return Some(child.id());
|
||||||
} else if let Some(next_focus) = self.widget().explicit_focus_target(advance) {
|
} else if let Some(next_focus) = self.widget().explicit_focus_target(advance) {
|
||||||
return Some(next_focus.id());
|
return Some(next_focus.id());
|
||||||
|
|
|
||||||
|
|
@ -284,7 +284,7 @@ struct GooeyWindow<T> {
|
||||||
initial_frame: bool,
|
initial_frame: bool,
|
||||||
occluded: Dynamic<bool>,
|
occluded: Dynamic<bool>,
|
||||||
focused: Dynamic<bool>,
|
focused: Dynamic<bool>,
|
||||||
keyboard_activated: Option<ManagedWidget>,
|
keyboard_activated: Option<WidgetId>,
|
||||||
min_inner_size: Option<Size<UPx>>,
|
min_inner_size: Option<Size<UPx>>,
|
||||||
max_inner_size: Option<Size<UPx>>,
|
max_inner_size: Option<Size<UPx>>,
|
||||||
theme: Option<DynamicReader<ThemePair>>,
|
theme: Option<DynamicReader<ThemePair>>,
|
||||||
|
|
@ -312,7 +312,11 @@ where
|
||||||
) {
|
) {
|
||||||
if is_pressed {
|
if is_pressed {
|
||||||
if let Some(default) = widget.and_then(|id| self.root.tree.widget_from_node(id)) {
|
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(
|
EventContext::new(
|
||||||
WidgetContext::new(
|
WidgetContext::new(
|
||||||
previously_active,
|
previously_active,
|
||||||
|
|
@ -338,9 +342,13 @@ where
|
||||||
kludgine,
|
kludgine,
|
||||||
)
|
)
|
||||||
.activate();
|
.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(
|
EventContext::new(
|
||||||
WidgetContext::new(
|
WidgetContext::new(
|
||||||
keyboard_activated,
|
keyboard_activated,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue