dock: Fix panel zoom when it split and added to other StackPanel. (#245)
This commit is contained in:
parent
55585f9699
commit
d33b4b2ea0
3 changed files with 42 additions and 37 deletions
|
|
@ -202,36 +202,6 @@ impl DockArea {
|
||||||
/// Subscribe event on the panels
|
/// Subscribe event on the panels
|
||||||
#[allow(clippy::only_used_in_recursion)]
|
#[allow(clippy::only_used_in_recursion)]
|
||||||
fn subscribe_item(&self, item: &DockItem, cx: &mut ViewContext<Self>) {
|
fn subscribe_item(&self, item: &DockItem, cx: &mut ViewContext<Self>) {
|
||||||
/// Subscribe zoom event on the panel
|
|
||||||
fn subscribe_zoom<P: Panel>(view: &View<P>, cx: &mut ViewContext<DockArea>) {
|
|
||||||
cx.subscribe(view, move |_, panel, event, cx| match event {
|
|
||||||
PanelEvent::ZoomIn => {
|
|
||||||
let dock_area = cx.view().clone();
|
|
||||||
let panel = panel.clone();
|
|
||||||
cx.spawn(|_, mut cx| async move {
|
|
||||||
let _ = cx.update(|cx| {
|
|
||||||
let _ = dock_area.update(cx, |dock, cx| {
|
|
||||||
dock.set_zoomed_in(panel, cx);
|
|
||||||
cx.notify();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.detach();
|
|
||||||
}
|
|
||||||
PanelEvent::ZoomOut => {
|
|
||||||
let dock_area = cx.view().clone();
|
|
||||||
cx.spawn(|_, mut cx| async move {
|
|
||||||
let _ = cx.update(|cx| {
|
|
||||||
let _ = dock_area.update(cx, |view, cx| view.set_zoomed_out(cx));
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.detach()
|
|
||||||
}
|
|
||||||
PanelEvent::LayoutChanged => cx.emit(DockEvent::LayoutChanged),
|
|
||||||
})
|
|
||||||
.detach();
|
|
||||||
}
|
|
||||||
|
|
||||||
match item {
|
match item {
|
||||||
DockItem::Split { items, view, .. } => {
|
DockItem::Split { items, view, .. } => {
|
||||||
for item in items {
|
for item in items {
|
||||||
|
|
@ -244,14 +214,42 @@ impl DockArea {
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
}
|
}
|
||||||
DockItem::Tabs { view, .. } => {
|
DockItem::Tabs { .. } => {
|
||||||
// We need, only subscribe to the zoom events on the TabPanel
|
// We subscribe the tab panel event is in StackPanel insert_panel
|
||||||
// Because we always wrap the DockItem::Panel in a DockItem::Tabs
|
|
||||||
subscribe_zoom(view, cx);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Subscribe zoom event on the panel
|
||||||
|
pub(crate) fn subscribe_panel<P: Panel>(view: &View<P>, cx: &mut ViewContext<DockArea>) {
|
||||||
|
cx.subscribe(view, move |_, panel, event, cx| match event {
|
||||||
|
PanelEvent::ZoomIn => {
|
||||||
|
let dock_area = cx.view().clone();
|
||||||
|
let panel = panel.clone();
|
||||||
|
cx.spawn(|_, mut cx| async move {
|
||||||
|
let _ = cx.update(|cx| {
|
||||||
|
let _ = dock_area.update(cx, |dock, cx| {
|
||||||
|
dock.set_zoomed_in(panel, cx);
|
||||||
|
cx.notify();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
}
|
||||||
|
PanelEvent::ZoomOut => {
|
||||||
|
let dock_area = cx.view().clone();
|
||||||
|
cx.spawn(|_, mut cx| async move {
|
||||||
|
let _ = cx.update(|cx| {
|
||||||
|
let _ = dock_area.update(cx, |view, cx| view.set_zoomed_out(cx));
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.detach()
|
||||||
|
}
|
||||||
|
PanelEvent::LayoutChanged => cx.emit(DockEvent::LayoutChanged),
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the ID of the dock area.
|
/// Returns the ID of the dock area.
|
||||||
pub fn id(&self) -> SharedString {
|
pub fn id(&self) -> SharedString {
|
||||||
self.id.clone()
|
self.id.clone()
|
||||||
|
|
|
||||||
|
|
@ -163,7 +163,7 @@ impl StackPanel {
|
||||||
panel: Arc<dyn PanelView>,
|
panel: Arc<dyn PanelView>,
|
||||||
ix: usize,
|
ix: usize,
|
||||||
size: Option<Pixels>,
|
size: Option<Pixels>,
|
||||||
_dock_area: WeakView<DockArea>,
|
dock_area: WeakView<DockArea>,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) {
|
) {
|
||||||
// If the panel is already in the stack, return.
|
// If the panel is already in the stack, return.
|
||||||
|
|
@ -185,6 +185,13 @@ impl StackPanel {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Subscribe to the panel's layout change event.
|
||||||
|
_ = dock_area.update(cx, |_, cx| {
|
||||||
|
if let Ok(tab_panel) = panel.view().downcast::<TabPanel>() {
|
||||||
|
DockArea::subscribe_panel(&tab_panel, cx);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
let ix = if ix > self.panels.len() {
|
let ix = if ix > self.panels.len() {
|
||||||
self.panels.len()
|
self.panels.len()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -581,12 +581,12 @@ impl TabPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_action_toggle_zoom(&mut self, _: &ToggleZoom, cx: &mut ViewContext<Self>) {
|
fn on_action_toggle_zoom(&mut self, _: &ToggleZoom, cx: &mut ViewContext<Self>) {
|
||||||
self.is_zoomed = !self.is_zoomed;
|
if !self.is_zoomed {
|
||||||
if self.is_zoomed {
|
|
||||||
cx.emit(PanelEvent::ZoomIn)
|
cx.emit(PanelEvent::ZoomIn)
|
||||||
} else {
|
} else {
|
||||||
cx.emit(PanelEvent::ZoomOut)
|
cx.emit(PanelEvent::ZoomOut)
|
||||||
}
|
}
|
||||||
|
self.is_zoomed = !self.is_zoomed;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_action_close_panel(&mut self, _: &ClosePanel, cx: &mut ViewContext<Self>) {
|
fn on_action_close_panel(&mut self, _: &ClosePanel, cx: &mut ViewContext<Self>) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue