mod show;
mod allowed_splits;
mod drag_and_drop;
mod drop_zone;
mod labels;
mod state;
mod tab_removal;
pub use allowed_splits::AllowedSplits;
pub use drop_zone::DropZone;
use std::panic::AssertUnwindSafe;
use egui::{Context, Id, Modifiers, emath::*};
pub use labels::Labels;
use tab_removal::TabRemoval;
use crate::{
DockPainter, DockSpace, NodePath, Style, StylePainter, TabIndex, TabPath,
dock_space::{Dock, NoDrop},
dock_state::DockState,
};
pub struct DockArea<'tree, Tab> {
id: Id,
dock_state: &'tree mut DockState<Tab>,
style: Option<Style>,
painter: AssertUnwindSafe<&'tree (dyn DockPainter + Sync)>,
labels: Labels,
show_add_popup: bool,
show_add_buttons: bool,
show_close_buttons: bool,
tab_context_menus: bool,
show_builtin_tab_menu: bool,
draggable_tabs: bool,
tab_focus: TabFocus,
hidable_tab_bars: bool,
show_tab_name_on_hover: bool,
show_window_close_buttons: bool,
show_window_collapse_buttons: bool,
show_leaf_close_all_buttons: bool,
show_leaf_collapse_buttons: bool,
show_secondary_button_hint: bool,
secondary_button_modifiers: Modifiers,
secondary_button_on_modifier: bool,
secondary_button_context_menu: bool,
allowed_splits: AllowedSplits,
window_bounds: Option<Rect>,
space: Option<SpaceDock<'tree>>,
to_remove: Vec<TabRemoval>,
to_detach: Vec<TabPath>,
new_focused: Option<NodePath>,
tab_hover_rect: Option<(Rect, TabIndex)>,
}
struct SpaceDock<'a> {
docks: &'a mut Vec<Dock>,
no_drop: &'a mut NoDrop,
dock: Option<usize>,
shows_windows: bool,
}
#[derive(Clone, Copy, Debug, PartialEq)]
#[non_exhaustive]
pub struct DraggedTab {
pub path: TabPath,
pub pointer: Pos2,
}
#[derive(Clone, Copy, Debug, PartialEq)]
#[non_exhaustive]
pub struct DraggedNode {
pub path: NodePath,
pub pointer: Pos2,
}
impl DockArea<'_, ()> {
pub fn default_id() -> Id {
Id::unique("egui_stack::DockArea")
}
pub fn dragged_tab(ctx: &Context, id: Id) -> Option<DraggedTab> {
ctx.data(|d| d.get_temp::<state::State>(id))
.and_then(|state| state.dragged)
}
pub fn dragged_node(ctx: &Context, id: Id) -> Option<DraggedNode> {
ctx.data(|d| d.get_temp::<state::State>(id))
.and_then(|state| state.dragged_node)
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum TabFocus {
#[default]
Each,
Roving,
}
impl<'tree, Tab> DockArea<'tree, Tab> {
#[inline(always)]
pub fn new(tree: &'tree mut DockState<Tab>) -> DockArea<'tree, Tab> {
Self {
id: DockArea::default_id(),
dock_state: tree,
style: None,
painter: AssertUnwindSafe(&StylePainter),
labels: Labels::ENGLISH,
show_add_popup: false,
show_add_buttons: false,
show_close_buttons: true,
tab_context_menus: true,
show_builtin_tab_menu: true,
draggable_tabs: true,
tab_focus: TabFocus::Each,
hidable_tab_bars: false,
show_tab_name_on_hover: false,
allowed_splits: AllowedSplits::default(),
space: None,
to_remove: Vec::new(),
to_detach: Vec::new(),
new_focused: None,
tab_hover_rect: None,
window_bounds: None,
show_window_close_buttons: true,
show_window_collapse_buttons: true,
show_leaf_close_all_buttons: true,
show_leaf_collapse_buttons: true,
show_secondary_button_hint: true,
secondary_button_modifiers: Modifiers::SHIFT,
secondary_button_on_modifier: true,
secondary_button_context_menu: true,
}
}
pub fn dock(space: &'tree mut DockSpace<Tab>, dock: &str) -> DockArea<'tree, Tab> {
let (dock_state, docks, no_drop, dock, shows_windows, id) = space.split_for_area(dock);
let mut area = Self::new(dock_state).id(id);
area.space = Some(SpaceDock {
docks,
no_drop,
dock,
shows_windows,
});
area
}
#[inline(always)]
pub fn id(mut self, id: Id) -> Self {
self.id = id;
self
}
#[inline(always)]
pub fn style(mut self, style: Style) -> Self {
self.style = Some(style);
self
}
#[inline(always)]
pub fn painter(mut self, painter: &'tree (dyn DockPainter + Sync)) -> Self {
self.painter = AssertUnwindSafe(painter);
self
}
#[inline(always)]
pub fn labels(mut self, labels: Labels) -> Self {
self.labels = labels;
self
}
#[inline(always)]
pub fn tab_focus(mut self, tab_focus: TabFocus) -> Self {
self.tab_focus = tab_focus;
self
}
pub fn show_add_popup(mut self, show_add_popup: bool) -> Self {
self.show_add_popup = show_add_popup;
self
}
pub fn show_add_buttons(mut self, show_add_buttons: bool) -> Self {
self.show_add_buttons = show_add_buttons;
self
}
pub fn show_close_buttons(mut self, show_close_buttons: bool) -> Self {
self.show_close_buttons = show_close_buttons;
self
}
pub fn tab_context_menus(mut self, tab_context_menus: bool) -> Self {
self.tab_context_menus = tab_context_menus;
self
}
#[inline(always)]
pub fn show_builtin_tab_menu(mut self, show_builtin_tab_menu: bool) -> Self {
self.show_builtin_tab_menu = show_builtin_tab_menu;
self
}
pub fn draggable_tabs(mut self, draggable_tabs: bool) -> Self {
self.draggable_tabs = draggable_tabs;
self
}
pub fn hidable_tab_bars(mut self, hidable_tab_bars: bool) -> Self {
self.hidable_tab_bars = hidable_tab_bars;
self
}
pub fn show_tab_name_on_hover(mut self, show_tab_name_on_hover: bool) -> Self {
self.show_tab_name_on_hover = show_tab_name_on_hover;
self
}
pub fn allowed_splits(mut self, allowed_splits: AllowedSplits) -> Self {
self.allowed_splits = allowed_splits;
self
}
pub fn show_secondary_button_hint(mut self, show_secondary_button_hint: bool) -> Self {
self.show_secondary_button_hint = show_secondary_button_hint;
self
}
pub fn secondary_button_modifiers(mut self, secondary_button_modifiers: Modifiers) -> Self {
self.secondary_button_modifiers = secondary_button_modifiers;
self
}
pub fn secondary_button_on_modifier(mut self, secondary_button_on_modifier: bool) -> Self {
self.secondary_button_on_modifier = secondary_button_on_modifier;
self
}
pub fn secondary_button_context_menu(mut self, secondary_button_context_menu: bool) -> Self {
self.secondary_button_context_menu = secondary_button_context_menu;
self
}
#[inline(always)]
pub fn window_bounds(mut self, bounds: Rect) -> Self {
self.window_bounds = Some(bounds);
self
}
#[inline(always)]
#[deprecated = "consider using `show_leaf_close_buttons` instead."]
pub fn show_window_close_buttons(mut self, show_window_close_buttons: bool) -> Self {
self.show_window_close_buttons = show_window_close_buttons;
self
}
#[inline(always)]
#[deprecated = "consider using `show_leaf_collapse_buttons` instead."]
pub fn show_window_collapse_buttons(mut self, show_window_collapse_buttons: bool) -> Self {
self.show_window_collapse_buttons = show_window_collapse_buttons;
self
}
#[inline(always)]
pub fn show_leaf_close_all_buttons(mut self, show_leaf_close_all_buttons: bool) -> Self {
self.show_leaf_close_all_buttons = show_leaf_close_all_buttons;
self
}
#[inline(always)]
pub fn show_leaf_collapse_buttons(mut self, show_leaf_collapse_buttons: bool) -> Self {
self.show_leaf_collapse_buttons = show_leaf_collapse_buttons;
self
}
}
impl<Tab> std::fmt::Debug for DockArea<'_, Tab> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("DockArea").finish_non_exhaustive()
}
}