Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow disabling vertical/horizontal splits #145

Merged
merged 6 commits into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ pub struct Style {
pub separator: SeparatorStyle,
pub tab_bar: TabBarStyle,
pub tabs: TabStyle,

pub allowed_splits: SplitTypes,
}

/// What directions can this dock split in?
#[derive(Clone, Debug, Default)]
pub enum SplitTypes {
#[default]
/// Allow splits in any direction (horizontal and vertical).
All,
/// Only allow split in a horizontal direction.
HorizontalOnly,
/// Only allow splits in a vertical direction.
VertialOnly,
/// Don't allow splits at all.
None,
}

/// Specifies the look and feel of buttons.
Expand Down Expand Up @@ -145,6 +161,7 @@ impl Default for Style {
separator: SeparatorStyle::default(),
tab_bar: TabBarStyle::default(),
tabs: TabStyle::default(),
allowed_splits: SplitTypes::default(),
}
}
}
Expand Down
91 changes: 62 additions & 29 deletions src/widgets/dock_area/hover_data.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{NodeIndex, Split, TabDestination, TabIndex};
use crate::{NodeIndex, Split, SplitTypes, TabDestination, TabIndex};
use egui::{Pos2, Rect};

#[derive(Debug)]
Expand All @@ -11,7 +11,7 @@ pub(super) struct HoverData {
}

impl HoverData {
pub(super) fn resolve(&self) -> (Rect, TabDestination) {
pub(super) fn resolve(&self, allowed_splits: &SplitTypes) -> (Rect, TabDestination) {
if let Some(tab) = self.tab {
return (tab.0, TabDestination::Insert(tab.1));
}
Expand All @@ -22,33 +22,66 @@ impl HoverData {
let (rect, pointer) = (self.rect, self.pointer);

let center = rect.center();
let pts = [
(
center.distance(pointer),
TabDestination::Append,
Rect::EVERYTHING,
),
(
rect.left_center().distance(pointer),
TabDestination::Split(Split::Left),
Rect::everything_left_of(center.x),
),
(
rect.right_center().distance(pointer),
TabDestination::Split(Split::Right),
Rect::everything_right_of(center.x),
),
(
rect.center_top().distance(pointer),
TabDestination::Split(Split::Above),
Rect::everything_above(center.y),
),
(
rect.center_bottom().distance(pointer),
TabDestination::Split(Split::Below),
Rect::everything_below(center.y),
),
];

let pts = match allowed_splits {
SplitTypes::All => vec![
(
center.distance(pointer),
TabDestination::Append,
Rect::EVERYTHING,
),
(
rect.left_center().distance(pointer),
TabDestination::Split(Split::Left),
Rect::everything_left_of(center.x),
),
(
rect.right_center().distance(pointer),
TabDestination::Split(Split::Right),
Rect::everything_right_of(center.x),
),
(
rect.center_top().distance(pointer),
TabDestination::Split(Split::Above),
Rect::everything_above(center.y),
),
(
rect.center_bottom().distance(pointer),
TabDestination::Split(Split::Below),
Rect::everything_below(center.y),
),
],
SplitTypes::HorizontalOnly => vec![
(
center.distance(pointer),
TabDestination::Append,
Rect::EVERYTHING,
),
(
rect.left_center().distance(pointer),
TabDestination::Split(Split::Left),
Rect::everything_left_of(center.x),
),
(
rect.right_center().distance(pointer),
TabDestination::Split(Split::Right),
Rect::everything_right_of(center.x),
),
],
SplitTypes::VertialOnly => vec![
(
rect.center_top().distance(pointer),
TabDestination::Split(Split::Above),
Rect::everything_above(center.y),
),
(
rect.center_bottom().distance(pointer),
TabDestination::Split(Split::Below),
Rect::everything_below(center.y),
),
],
SplitTypes::None => vec![],
};

let (_, tab_dst, overlay) = pts
.into_iter()
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/dock_area/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl<'tree, Tab> DockArea<'tree, Tab> {
&& self.tree[dst].is_leaf()
&& (src != dst || self.tree[dst].tabs_count() > 1)
{
let (overlay, tab_dst) = hover.resolve();
let (overlay, tab_dst) = hover.resolve(&style.allowed_splits);
let id = Id::new("overlay");
let layer_id = LayerId::new(Order::Foreground, id);
let painter = ui.ctx().layer_painter(layer_id);
Expand Down
Loading