Skip to content

Commit

Permalink
Add SeparatorStyle::extra_interact_width (Adanos020#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
lvaroqui committed May 20, 2023
1 parent 9c5154b commit 19c43dd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 1,10 @@
# egui_dock changelog

## Unreleased

### Added
- `SeparatorStyle::extra_interact_width` option that adds "logical" width to separators so that they are easier to grab ([#128](https://github.com/Adanos020/egui_dock/pull/128))

## 0.5.0 - 2023-04-22

### Fixed
Expand Down Expand Up @@ -174,7 179,6 @@
- Renamed `Node::None` to `Node::Empty`.

### Fixed

- Now selection color of the placing area for the tab isn't showing if the tab is targeted on its own node when the tab is the only member of this node.
- Dock vertical and horizontal separators are now displayed properly.
- Prevent Id clashes from multiple tabs being displayed at once.
Expand Down
7 changes: 7 additions & 0 deletions examples/hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 132,13 @@ impl MyContext {
ui.add(Slider::new(&mut style.separator.width, 1.0..=50.0));
ui.end_row();

ui.label("Extra Interact Width:");
ui.add(Slider::new(
&mut style.separator.extra_interact_width,
0.0..=50.0,
));
ui.end_row();

ui.label("Offset limit:");
ui.add(Slider::new(&mut style.separator.extra, 1.0..=300.0));
ui.end_row();
Expand Down
5 changes: 5 additions & 0 deletions src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 60,10 @@ pub struct SeparatorStyle {
/// Width of the rectangle separator between nodes. By `Default` it's `1.0`.
pub width: f32,

/// Extra width added to the "logical thickness" of the rectangle so it's
/// easier to grab. By `Default` it's `4.0`.
pub extra_interact_width: f32,

/// Limit for the allowed area for the separator offset. By `Default` it's `175.0`.
/// `bigger value > less allowed offset` for the current window size.
pub extra: f32,
Expand Down Expand Up @@ -158,6 162,7 @@ impl Default for SeparatorStyle {
fn default() -> Self {
Self {
width: 1.0,
extra_interact_width: 2.0,
extra: 175.0,
color_idle: Color32::BLACK,
color_hovered: Color32::GRAY,
Expand Down
21 changes: 13 additions & 8 deletions src/widgets/dock_area/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 176,16 @@ impl<'tree, Tab> DockArea<'tree, Tab> {
self.allocate_area_for_root(ui);

for node_index in (0..self.tree.len()).map(NodeIndex) {
if self.tree[node_index].is_parent() {
self.split_subtree(ui, node_index);
if self.tree[node_index].is_leaf() {
self.show_leaf(ui, &mut state, node_index, tab_viewer);
}
}

// Draw separator after node UI so that we can overlay the separator
// interaction zone according to `SeparatorStyle::extra_interact_width`.
for node_index in (0..self.tree.len()).map(NodeIndex) {
if self.tree[node_index].is_leaf() {
self.process_leaf(ui, &mut state, node_index, tab_viewer);
if self.tree[node_index].is_parent() {
self.show_separator(ui, node_index);
}
}

Expand Down Expand Up @@ -240,7 242,7 @@ impl<'tree, Tab> DockArea<'tree, Tab> {
self.tree[NodeIndex::root()].set_rect(rect);
}

fn split_subtree(&mut self, ui: &mut Ui, node_index: NodeIndex) {
fn show_separator(&mut self, ui: &mut Ui, node_index: NodeIndex) {
assert!(self.tree[node_index].is_parent());

let style = self.style.as_ref().unwrap();
Expand All @@ -261,8 263,11 @@ impl<'tree, Tab> DockArea<'tree, Tab> {
separator.min.dim_point = midpoint - style.separator.width * 0.5;
separator.max.dim_point = midpoint style.separator.width * 0.5;

let response = ui
.allocate_rect(separator, Sense::click_and_drag())
let mut expand = Vec2::ZERO;
expand.dim_point = style.separator.extra_interact_width / 2.0;
let interact_rect = separator.expand2(expand);

let response = ui.allocate_rect(interact_rect, Sense::click_and_drag())
.on_hover_and_drag_cursor(paste!{ CursorIcon::[<Resize orientation>]});

if let Some(pos) = response.interact_pointer_pos() {
Expand Down Expand Up @@ -313,7 318,7 @@ impl<'tree, Tab> DockArea<'tree, Tab> {
}
}

fn process_leaf(
fn show_leaf(
&mut self,
ui: &mut Ui,
state: &mut State,
Expand Down

0 comments on commit 19c43dd

Please sign in to comment.