Compare commits
8 commits
main
...
fix-action
Author | SHA1 | Date | |
---|---|---|---|
![]() |
dbed047caa | ||
![]() |
d7d12b2510 | ||
![]() |
960395760b | ||
![]() |
cda2119ab5 | ||
![]() |
7d175936f6 | ||
![]() |
85119263c5 | ||
![]() |
2eedfc62d8 | ||
![]() |
281ef340db |
6 changed files with 38 additions and 4 deletions
|
@ -949,10 +949,12 @@ impl App {
|
||||||
.write()
|
.write()
|
||||||
.retain(|handle_id, count| {
|
.retain(|handle_id, count| {
|
||||||
if count.load(SeqCst) == 0 {
|
if count.load(SeqCst) == 0 {
|
||||||
|
println!("Dropping {handle_id}");
|
||||||
for window_handle in self.windows() {
|
for window_handle in self.windows() {
|
||||||
window_handle
|
window_handle
|
||||||
.update(self, |_, window, _| {
|
.update(self, |_, window, _| {
|
||||||
if window.focus == Some(handle_id) {
|
if window.focus == Some(handle_id) {
|
||||||
|
println!("released focus handle blur");
|
||||||
window.blur();
|
window.blur();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -570,6 +570,7 @@ impl DispatchTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn focus_path(&self, focus_id: FocusId) -> SmallVec<[FocusId; 8]> {
|
pub fn focus_path(&self, focus_id: FocusId) -> SmallVec<[FocusId; 8]> {
|
||||||
|
println!("focus path requested for focus id: {:?}", focus_id);
|
||||||
let mut focus_path: SmallVec<[FocusId; 8]> = SmallVec::new();
|
let mut focus_path: SmallVec<[FocusId; 8]> = SmallVec::new();
|
||||||
let mut current_node_id = self.focusable_node_ids.get(&focus_id).copied();
|
let mut current_node_id = self.focusable_node_ids.get(&focus_id).copied();
|
||||||
while let Some(node_id) = current_node_id {
|
while let Some(node_id) = current_node_id {
|
||||||
|
|
|
@ -227,7 +227,7 @@ pub(crate) type FocusMap = RwLock<SlotMap<FocusId, AtomicUsize>>;
|
||||||
impl FocusId {
|
impl FocusId {
|
||||||
/// Obtains whether the element associated with this handle is currently focused.
|
/// Obtains whether the element associated with this handle is currently focused.
|
||||||
pub fn is_focused(&self, window: &Window) -> bool {
|
pub fn is_focused(&self, window: &Window) -> bool {
|
||||||
window.focus == Some(*self)
|
dbg!(window.focus) == Some(*self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Obtains whether the element associated with this handle contains the focused
|
/// Obtains whether the element associated with this handle contains the focused
|
||||||
|
@ -705,6 +705,7 @@ impl Frame {
|
||||||
self.window_control_hitboxes.clear();
|
self.window_control_hitboxes.clear();
|
||||||
self.deferred_draws.clear();
|
self.deferred_draws.clear();
|
||||||
self.focus = None;
|
self.focus = None;
|
||||||
|
println!("clearing focus 1");
|
||||||
|
|
||||||
#[cfg(any(feature = "inspector", debug_assertions))]
|
#[cfg(any(feature = "inspector", debug_assertions))]
|
||||||
{
|
{
|
||||||
|
@ -751,6 +752,8 @@ impl Frame {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn focus_path(&self) -> SmallVec<[FocusId; 8]> {
|
pub(crate) fn focus_path(&self) -> SmallVec<[FocusId; 8]> {
|
||||||
|
dbg!("focus path");
|
||||||
|
dbg!(self.focus.is_some());
|
||||||
self.focus
|
self.focus
|
||||||
.map(|focus_id| self.dispatch_tree.focus_path(focus_id))
|
.map(|focus_id| self.dispatch_tree.focus_path(focus_id))
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
|
@ -1264,10 +1267,16 @@ impl Window {
|
||||||
|
|
||||||
/// Move focus to the element associated with the given [`FocusHandle`].
|
/// Move focus to the element associated with the given [`FocusHandle`].
|
||||||
pub fn focus(&mut self, handle: &FocusHandle) {
|
pub fn focus(&mut self, handle: &FocusHandle) {
|
||||||
|
println!(
|
||||||
|
"Setting focus to {:?} on platform {:?}",
|
||||||
|
handle.id,
|
||||||
|
std::env::consts::OS
|
||||||
|
);
|
||||||
|
|
||||||
if !self.focus_enabled || self.focus == Some(handle.id) {
|
if !self.focus_enabled || self.focus == Some(handle.id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
println!("actually setting focus");
|
||||||
self.focus = Some(handle.id);
|
self.focus = Some(handle.id);
|
||||||
self.clear_pending_keystrokes();
|
self.clear_pending_keystrokes();
|
||||||
self.refresh();
|
self.refresh();
|
||||||
|
@ -1280,11 +1289,13 @@ impl Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.focus = None;
|
self.focus = None;
|
||||||
|
println!("clearing focus 2");
|
||||||
self.refresh();
|
self.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Blur the window and don't allow anything in it to be focused again.
|
/// Blur the window and don't allow anything in it to be focused again.
|
||||||
pub fn disable_focus(&mut self) {
|
pub fn disable_focus(&mut self) {
|
||||||
|
println!("disable_focus");
|
||||||
self.blur();
|
self.blur();
|
||||||
self.focus_enabled = false;
|
self.focus_enabled = false;
|
||||||
}
|
}
|
||||||
|
@ -1333,12 +1344,13 @@ impl Window {
|
||||||
/// Dispatch the given action on the currently focused element.
|
/// Dispatch the given action on the currently focused element.
|
||||||
pub fn dispatch_action(&mut self, action: Box<dyn Action>, cx: &mut App) {
|
pub fn dispatch_action(&mut self, action: Box<dyn Action>, cx: &mut App) {
|
||||||
let focus_id = self.focused(cx).map(|handle| handle.id);
|
let focus_id = self.focused(cx).map(|handle| handle.id);
|
||||||
|
dbg!(&focus_id);
|
||||||
let window = self.handle;
|
let window = self.handle;
|
||||||
cx.defer(move |cx| {
|
cx.defer(move |cx| {
|
||||||
window
|
window
|
||||||
.update(cx, |_, window, cx| {
|
.update(cx, |_, window, cx| {
|
||||||
let node_id = window.focus_node_id_in_rendered_frame(focus_id);
|
let node_id = window.focus_node_id_in_rendered_frame(focus_id);
|
||||||
|
dbg!(&node_id);
|
||||||
window.dispatch_action_on_node(node_id, action.as_ref(), cx);
|
window.dispatch_action_on_node(node_id, action.as_ref(), cx);
|
||||||
})
|
})
|
||||||
.log_err();
|
.log_err();
|
||||||
|
@ -1797,8 +1809,16 @@ impl Window {
|
||||||
self.invalidator.set_phase(DrawPhase::Focus);
|
self.invalidator.set_phase(DrawPhase::Focus);
|
||||||
let previous_focus_path = self.rendered_frame.focus_path();
|
let previous_focus_path = self.rendered_frame.focus_path();
|
||||||
let previous_window_active = self.rendered_frame.window_active;
|
let previous_window_active = self.rendered_frame.window_active;
|
||||||
|
println!(
|
||||||
|
"dbg! Window::draw - pre-swap: rendered_frame.focus = {:?}, next_frame.focus = {:?}",
|
||||||
|
self.rendered_frame.focus, self.next_frame.focus
|
||||||
|
);
|
||||||
mem::swap(&mut self.rendered_frame, &mut self.next_frame);
|
mem::swap(&mut self.rendered_frame, &mut self.next_frame);
|
||||||
self.next_frame.clear();
|
self.next_frame.clear();
|
||||||
|
println!(
|
||||||
|
"dbg! Window::draw - post-swap: rendered_frame.focus = {:?}, next_frame.focus = {:?}",
|
||||||
|
self.rendered_frame.focus, self.next_frame.focus
|
||||||
|
);
|
||||||
let current_focus_path = self.rendered_frame.focus_path();
|
let current_focus_path = self.rendered_frame.focus_path();
|
||||||
let current_window_active = self.rendered_frame.window_active;
|
let current_window_active = self.rendered_frame.window_active;
|
||||||
|
|
||||||
|
@ -2115,6 +2135,7 @@ impl Window {
|
||||||
);
|
);
|
||||||
|
|
||||||
if reused_subtree.contains_focus() {
|
if reused_subtree.contains_focus() {
|
||||||
|
println!("setting focus for next frame");
|
||||||
self.next_frame.focus = self.focus;
|
self.next_frame.focus = self.focus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3113,7 +3134,9 @@ impl Window {
|
||||||
/// This method should only be called as part of the prepaint phase of element drawing.
|
/// This method should only be called as part of the prepaint phase of element drawing.
|
||||||
pub fn set_focus_handle(&mut self, focus_handle: &FocusHandle, _: &App) {
|
pub fn set_focus_handle(&mut self, focus_handle: &FocusHandle, _: &App) {
|
||||||
self.invalidator.debug_assert_prepaint();
|
self.invalidator.debug_assert_prepaint();
|
||||||
|
println!("set_focus_handle called");
|
||||||
if focus_handle.is_focused(self) {
|
if focus_handle.is_focused(self) {
|
||||||
|
println!("setting focus for next frame");
|
||||||
self.next_frame.focus = Some(focus_handle.id);
|
self.next_frame.focus = Some(focus_handle.id);
|
||||||
}
|
}
|
||||||
self.next_frame.dispatch_tree.set_focus_id(focus_handle.id);
|
self.next_frame.dispatch_tree.set_focus_id(focus_handle.id);
|
||||||
|
@ -3757,7 +3780,10 @@ impl Window {
|
||||||
.dispatch_tree
|
.dispatch_tree
|
||||||
.focusable_node_id(focus_id)
|
.focusable_node_id(focus_id)
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| self.rendered_frame.dispatch_tree.root_node_id())
|
.unwrap_or_else(|| {
|
||||||
|
println!("root node id");
|
||||||
|
self.rendered_frame.dispatch_tree.root_node_id()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_action_on_node(
|
fn dispatch_action_on_node(
|
||||||
|
|
|
@ -288,6 +288,7 @@ pub fn init(cx: &mut App) {
|
||||||
|
|
||||||
cx.observe_new(|workspace: &mut Workspace, _, _| {
|
cx.observe_new(|workspace: &mut Workspace, _, _| {
|
||||||
workspace.register_action(|workspace, _: &ToggleFocus, window, cx| {
|
workspace.register_action(|workspace, _: &ToggleFocus, window, cx| {
|
||||||
|
println!("this must run");
|
||||||
workspace.toggle_panel_focus::<ProjectPanel>(window, cx);
|
workspace.toggle_panel_focus::<ProjectPanel>(window, cx);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -909,6 +909,7 @@ impl Render for PanelButtons {
|
||||||
.on_click({
|
.on_click({
|
||||||
let action = action.boxed_clone();
|
let action = action.boxed_clone();
|
||||||
move |_, window, cx| {
|
move |_, window, cx| {
|
||||||
|
println!("panel button click");
|
||||||
window.dispatch_action(action.boxed_clone(), cx)
|
window.dispatch_action(action.boxed_clone(), cx)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -1219,6 +1219,7 @@ impl Workspace {
|
||||||
.detach();
|
.detach();
|
||||||
|
|
||||||
cx.on_focus_lost(window, |this, window, cx| {
|
cx.on_focus_lost(window, |this, window, cx| {
|
||||||
|
println!("workspace on_focus_lost");
|
||||||
let focus_handle = this.focus_handle(cx);
|
let focus_handle = this.focus_handle(cx);
|
||||||
window.focus(&focus_handle);
|
window.focus(&focus_handle);
|
||||||
})
|
})
|
||||||
|
@ -1245,6 +1246,8 @@ impl Workspace {
|
||||||
|
|
||||||
window.focus(¢er_pane.focus_handle(cx));
|
window.focus(¢er_pane.focus_handle(cx));
|
||||||
|
|
||||||
|
// center_pane.focus_handle(cx).is_focused(window);
|
||||||
|
|
||||||
cx.emit(Event::PaneAdded(center_pane.clone()));
|
cx.emit(Event::PaneAdded(center_pane.clone()));
|
||||||
|
|
||||||
let window_handle = window.window_handle().downcast::<Workspace>().unwrap();
|
let window_handle = window.window_handle().downcast::<Workspace>().unwrap();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue