Finish removing all dangerous focus APIs
This commit is contained in:
parent
2cde1a2e15
commit
ca8e8d1065
4 changed files with 45 additions and 56 deletions
|
@ -1,14 +1,16 @@
|
|||
use gpui::{
|
||||
actions, div, prelude::*, Div, FocusHandle, Focusable, KeyBinding, Render, Stateful, View,
|
||||
WindowContext,
|
||||
actions, div, prelude::*, Div, FocusHandle, Focusable, KeyBinding, Render, Stateful,
|
||||
Subscription, View, WindowContext,
|
||||
};
|
||||
use ui::prelude::*;
|
||||
|
||||
actions!(focus, [ActionA, ActionB, ActionC]);
|
||||
|
||||
pub struct FocusStory {
|
||||
parent_focus: FocusHandle,
|
||||
child_1_focus: FocusHandle,
|
||||
child_2_focus: FocusHandle,
|
||||
_focus_subscriptions: Vec<Subscription>,
|
||||
}
|
||||
|
||||
impl FocusStory {
|
||||
|
@ -19,9 +21,37 @@ impl FocusStory {
|
|||
KeyBinding::new("cmd-c", ActionC, None),
|
||||
]);
|
||||
|
||||
cx.build_view(move |cx| Self {
|
||||
child_1_focus: cx.focus_handle(),
|
||||
child_2_focus: cx.focus_handle(),
|
||||
cx.build_view(move |cx| {
|
||||
let parent_focus = cx.focus_handle();
|
||||
let child_1_focus = cx.focus_handle();
|
||||
let child_2_focus = cx.focus_handle();
|
||||
let _focus_subscriptions = vec![
|
||||
cx.on_focus(&parent_focus, |_, _| {
|
||||
println!("Parent focused");
|
||||
}),
|
||||
cx.on_blur(&parent_focus, |_, _| {
|
||||
println!("Parent blurred");
|
||||
}),
|
||||
cx.on_focus(&child_1_focus, |_, _| {
|
||||
println!("Child 1 focused");
|
||||
}),
|
||||
cx.on_blur(&child_1_focus, |_, _| {
|
||||
println!("Child 1 blurred");
|
||||
}),
|
||||
cx.on_focus(&child_2_focus, |_, _| {
|
||||
println!("Child 2 focused");
|
||||
}),
|
||||
cx.on_blur(&child_2_focus, |_, _| {
|
||||
println!("Child 2 blurred");
|
||||
}),
|
||||
];
|
||||
|
||||
Self {
|
||||
parent_focus,
|
||||
child_1_focus,
|
||||
child_2_focus,
|
||||
_focus_subscriptions,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +69,7 @@ impl Render for FocusStory {
|
|||
|
||||
div()
|
||||
.id("parent")
|
||||
.focusable()
|
||||
.track_focus(&self.parent_focus)
|
||||
.key_context("parent")
|
||||
.on_action(cx.listener(|_, _action: &ActionA, _cx| {
|
||||
println!("Action A dispatched on parent");
|
||||
|
@ -47,11 +77,6 @@ impl Render for FocusStory {
|
|||
.on_action(cx.listener(|_, _action: &ActionB, _cx| {
|
||||
println!("Action B dispatched on parent");
|
||||
}))
|
||||
.on_focus(cx.listener(|_, _, _| println!("Parent focused")))
|
||||
.on_blur(cx.listener(|_, _, _| println!("Parent blurred")))
|
||||
// TODO kb todo!() remove?
|
||||
// .on_focus_in(cx.listener(|_, _, _| println!("Parent focus_in")))
|
||||
// .on_focus_out(cx.listener(|_, _, _| println!("Parent focus_out")))
|
||||
.on_key_down(cx.listener(|_, event, _| println!("Key down on parent {:?}", event)))
|
||||
.on_key_up(cx.listener(|_, event, _| println!("Key up on parent {:?}", event)))
|
||||
.size_full()
|
||||
|
@ -69,11 +94,6 @@ impl Render for FocusStory {
|
|||
.bg(color_4)
|
||||
.focus(|style| style.bg(color_5))
|
||||
.in_focus(|style| style.bg(color_6))
|
||||
.on_focus(cx.listener(|_, _, _| println!("Child 1 focused")))
|
||||
.on_blur(cx.listener(|_, _, _| println!("Child 1 blurred")))
|
||||
// TODO kb todo!() remove?
|
||||
// .on_focus_in(cx.listener(|_, _, _| println!("Child 1 focus_in")))
|
||||
// .on_focus_out(cx.listener(|_, _, _| println!("Child 1 focus_out")))
|
||||
.on_key_down(
|
||||
cx.listener(|_, event, _| println!("Key down on child 1 {:?}", event)),
|
||||
)
|
||||
|
@ -90,11 +110,6 @@ impl Render for FocusStory {
|
|||
.w_full()
|
||||
.h_6()
|
||||
.bg(color_4)
|
||||
.on_focus(cx.listener(|_, _, _| println!("Child 2 focused")))
|
||||
.on_blur(cx.listener(|_, _, _| println!("Child 2 blurred")))
|
||||
// TODO kb todo!() remove?
|
||||
// .on_focus_in(cx.listener(|_, _, _| println!("Child 2 focus_in")))
|
||||
// .on_focus_out(cx.listener(|_, _, _| println!("Child 2 focus_out")))
|
||||
.on_key_down(
|
||||
cx.listener(|_, event, _| println!("Key down on child 2 {:?}", event)),
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue