Skip to content

Commit

Permalink
Fixes to small bugs (#177)
Browse files Browse the repository at this point in the history
fixes the bugs discussed in the discord egui_dock channel
  • Loading branch information
Vickerinox authored Sep 4, 2023
1 parent 1de3979 commit 9ace31a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
19 changes: 9 additions & 10 deletions src/dock_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ impl<Tab> DockState<Tab> {
match dst_tab.into() {
TabDestination::Window(position) => {
self.detach_tab((src_surface, src_node, src_tab), position);
return;
}
TabDestination::Node(dst_surface, dst_node, dst_tab) => {
// Moving a single tab inside its own node is a no-op
Expand All @@ -222,25 +223,23 @@ impl<Tab> DockState<Tab> {
TabInsert::Split(split) => {
self[dst_surface].split(dst_node, split, 0.5, Node::leaf(tab));
}

TabInsert::Insert(index) => self[dst_surface][dst_node].insert_tab(index, tab),
TabInsert::Append => self[dst_surface][dst_node].append_tab(tab),
}

if self[src_surface][src_node].is_leaf()
&& self[src_surface][src_node].tabs_count() == 0
{
self[src_surface].remove_leaf(src_node);
}
if self[src_surface].is_empty() && !src_surface.is_main() {
self.remove_surface(src_surface);
}
}
TabDestination::EmptySurface(dst_surface) => {
assert!(self[dst_surface].is_empty());
let tab = self[src_surface][src_node].remove_tab(src_tab).unwrap();
self[dst_surface] = Tree::new(vec![tab])
}
};
}
if self[src_surface][src_node].is_leaf() && self[src_surface][src_node].tabs_count() == 0 {
self[src_surface].remove_leaf(src_node);
}
if self[src_surface].is_empty() && !src_surface.is_main() {
self.remove_surface(src_surface);
}
}

/// Takes a tab out of its current surface and puts it in a new window.
Expand Down
11 changes: 6 additions & 5 deletions src/widgets/dock_area/show/leaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::ops::RangeInclusive;

use egui::{
epaint::TextShape, lerp, pos2, vec2, Align, Align2, CursorIcon, Frame, Id, LayerId, Layout,
NumExt, Order, Rect, Response, Rounding, ScrollArea, Sense, Stroke, TextStyle, Ui, Vec2,
WidgetText,
NumExt, Order, PointerButton, Rect, Response, Rounding, ScrollArea, Sense, Stroke, TextStyle,
Ui, Vec2, WidgetText,
};

use crate::{
Expand Down Expand Up @@ -205,8 +205,9 @@ impl<'tree, Tab> DockArea<'tree, Tab> {
.with((node_index, "node"))
.with((tab_index, "tab"));
let tab_index = TabIndex(tab_index);
let is_being_dragged =
tabs_ui.memory(|mem| mem.is_being_dragged(id)) && self.draggable_tabs;
let is_being_dragged = tabs_ui.memory(|mem| mem.is_being_dragged(id))
&& tabs_ui.input(|i| i.pointer.primary_down() || i.pointer.primary_released())
&& self.draggable_tabs;

if is_being_dragged {
tabs_ui.output_mut(|o| o.cursor_icon = CursorIcon::Grabbing);
Expand Down Expand Up @@ -338,7 +339,7 @@ impl<'tree, Tab> DockArea<'tree, Tab> {
}
}
let response = tabs_ui.interact(response.rect, id, sense);
if response.drag_started() {
if response.drag_started_by(PointerButton::Primary) {
state.drag_start = response.hover_pos();
}

Expand Down
2 changes: 1 addition & 1 deletion src/widgets/dock_area/show/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl<'tree, Tab> DockArea<'tree, Tab> {
})
.inner
};
if ui.input(|i| i.pointer.any_released()) {
if ui.input(|i| i.pointer.primary_released()) {
let source = {
match state.dnd.as_ref().unwrap().drag.src {
TreeComponent::Tab(src_surf, src_node, src_tab) => {
Expand Down

0 comments on commit 9ace31a

Please sign in to comment.