use egui::{Context, Rect};
#[cfg(feature = "bus")]
use crate::TabDestination;
use crate::dock_area::drag_and_drop::TreeComponent;
use crate::dock_space::{Detach, detach};
use crate::{DockArea, SurfaceIndex, TabViewer};
impl<Tab> DockArea<'_, Tab> {
#[cfg(feature = "bus")]
pub(super) fn emit_moved(&self, destination: &TabDestination) {
let Some(bus) = self.space.as_ref().and_then(|space| space.bus) else {
return;
};
let dock = match *destination {
TabDestination::Node(path, _) => self.dock_name(path.surface),
TabDestination::EmptySurface(surface) => self.dock_name(surface),
TabDestination::Window(_) => None,
};
let mut change = crate::bus::LayoutChange::new(crate::bus::Change::TabMoved);
change.zone = self.drop_zone_of(dock);
change.dock = dock.map(str::to_owned);
bus.emit::<crate::bus::LayoutChanged>(change);
}
pub(super) fn floats_on(&self) -> bool {
self.space
.as_ref()
.is_some_and(|space| space.floating.enabled)
}
pub(super) fn is_float_dock(&self, surface: SurfaceIndex) -> bool {
self.space.as_ref().is_some_and(|space| {
space
.docks
.iter()
.any(|dock| dock.surface == surface && dock.floating)
})
}
pub(super) fn float_out(
&mut self,
ctx: &Context,
source: TreeComponent,
rect: Rect,
tab_viewer: &mut impl TabViewer<Tab = Tab>,
) {
let source = match source {
TreeComponent::Tab(path) => Detach::Tab(path),
TreeComponent::Node(path) => Detach::Group(path),
TreeComponent::Surface(_) => return,
};
let Some(space) = self.space.as_mut() else {
return;
};
let ppp = ctx.pixels_per_point();
let physical = ctx.input(|i| i.viewport().inner_rect).map(|inner| {
Rect::from_min_size(
((inner.min.to_vec2() + rect.min.to_vec2()) * ppp).to_pos2(),
rect.size() * ppp,
)
});
detach(
self.dock_state,
space.docks,
space.origins,
space.floating,
source,
rect,
physical,
&mut |tab| tab_viewer.id(tab),
);
ctx.request_repaint();
}
}