Skip to content

Commit

Permalink
Release 0.9 (#201)
Browse files Browse the repository at this point in the history
* Added DockState::iter_nodes_mut and DockState::iter_main_surface_nodes_mut (#195)

* added iter_nodes_mut

* finished adding iter_nodes_mut

* added iter_main_surface_nodes_mut

* ran cargo fmt

* Bump crate version number to 0.9.0

* Iterators overhaul (#196)

* Remove the deprecated `DockState::iter`

* Rename `iter_nodes{,_mut}` to `iter_all_nodes{,_mut}` and deprecate `iter_nodes`

* Add iterators over surfaces

* Expand `iter_all_nodes{,_mut}` to include containing surface indices

* Deprecated `iter_main_surface_nodes{,_mut}`

* Add iterators for all tabs and containing surface and node indices

* Update changelog

* Add node and tab iterators to `Surface`

* Add tab iterators to `Node`

* Update changelog

* Update changelog

* Mapping over tab types (#199)

* Implement mapping over tab types

* Fix compile errors

* Fix formatting

---------

Co-authored-by: Adam Gąsior <[email protected]>

* Upgrade egui to 0.24.0

* Update changelog

* Update changelog

---------

Co-authored-by: Cassie‽ <[email protected]>
Co-authored-by: knoellle <[email protected]>
  • Loading branch information
3 people authored Nov 23, 2023
1 parent c126274 commit c360442
Show file tree
Hide file tree
Showing 10 changed files with 298 additions and 68 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# egui_dock changelog

## 0.9.0 - 2023-11-23

### Added
- `DockArea::surfaces_count`
- `DockArea::iter_surfaces[_mut]`
- `DockArea::iter_all_tabs[_mut]`
- `DockArea::iter_all_nodes[_mut]`
- `Node::iter_tabs[_mut]`
- `Surface::iter_nodes[_mut]`
- `Surface::iter_all_tabs[_mut]`

### Breaking changes
- Upgraded to egui 0.24.
- Removed the deprecated `DockState::iter`.

### Deprecated
- `DockState::iter_nodes` – use `iter_all_nodes` instead.
- `DockState::iter_main_surface_nodes[_mut]` – use `dock_state.main_surface().iter()` (and corresponding `mut` versions) instead.

## 0.8.2 - 2023-11-02

### Fixed
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
name = "egui_dock"
description = "Docking system for egui - an immediate-mode GUI library for Rust"
authors = ["lain-dono", "Adam Gąsior (Adanos020)"]
version = "0.8.2"
version = "0.9.0"
edition = "2021"
rust-version = "1.70"
rust-version = "1.72"
license = "MIT"
readme = "README.md"
repository = "https:/Adanos020/egui_dock"
Expand All @@ -18,14 +18,14 @@ default = []
serde = ["dep:serde", "egui/serde"]

[dependencies]
egui = { version = "0.23", default-features = false }
egui = { version = "0.24", default-features = false }
serde = { version = "1", optional = true, features = ["derive"] }

duplicate = "1.0"
paste = "1.0"

[dev-dependencies]
eframe = { version = "0.23", default-features = false, features = [
eframe = { version = "0.24", default-features = false, features = [
"default_fonts",
"glow",
] }
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# `egui_dock`: docking support for [egui](https:/emilk/egui)
# `egui_dock`: docking system for [egui](https:/emilk/egui)

[![github](https://img.shields.io/badge/github-Adanos020/egui_dock-8da0cb?logo=github)](https:/Adanos020/egui_dock)
[![Crates.io](https://img.shields.io/crates/v/egui_dock)](https://crates.io/crates/egui_dock)
[![docs.rs](https://img.shields.io/docsrs/egui_dock)](https://docs.rs/egui_dock/)
[![egui_version](https://img.shields.io/badge/egui-0.23-blue)](https:/emilk/egui)
[![egui_version](https://img.shields.io/badge/egui-0.24-blue)](https:/emilk/egui)

Originally created by [@lain-dono](https:/lain-dono), this library provides docking support for `egui`.
Originally created by [@lain-dono](https:/lain-dono), this library provides a docking system for `egui`.

## Contributing

Expand All @@ -32,8 +32,8 @@ Add `egui` and `egui_dock` to your project's dependencies.

```toml
[dependencies]
egui = "0.23"
egui_dock = "0.8"
egui = "0.24"
egui_dock = "0.9"
```

Then proceed by setting up `egui`, following its [quick start guide](https:/emilk/egui#quick-start).
Expand Down
5 changes: 3 additions & 2 deletions examples/hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use std::collections::HashSet;
use eframe::{egui, NativeOptions};
use egui::{
color_picker::{color_edit_button_srgba, Alpha},
CentralPanel, ComboBox, Frame, Rounding, Slider, TopBottomPanel, Ui, WidgetText,
vec2, CentralPanel, ComboBox, Frame, Rounding, Slider, TopBottomPanel, Ui, ViewportBuilder,
WidgetText,
};

use egui_dock::{
Expand Down Expand Up @@ -52,7 +53,7 @@ macro_rules! unit_slider {
fn main() -> eframe::Result<()> {
std::env::set_var("RUST_BACKTRACE", "1");
let options = NativeOptions {
initial_window_size: Some(egui::vec2(1024.0, 1024.0)),
viewport: ViewportBuilder::default().with_inner_size(vec2(1024.0, 1024.0)),
..Default::default()
};
eframe::run_native(
Expand Down
116 changes: 102 additions & 14 deletions src/dock_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@ impl<Tab> DockState<Tab> {
self
}

/// Get a mutable borrow to the tree at the main surface.
pub fn main_surface_mut(&mut self) -> &mut Tree<Tab> {
&mut self[SurfaceIndex::main()]
}

/// Get an immutable borrow to the tree at the main surface.
pub fn main_surface(&self) -> &Tree<Tab> {
&self[SurfaceIndex::main()]
}

/// Get a mutable borrow to the tree at the main surface.
pub fn main_surface_mut(&mut self) -> &mut Tree<Tab> {
&mut self[SurfaceIndex::main()]
}

/// Get the [`WindowState`] which corresponds to a [`SurfaceIndex`].
///
/// Returns `None` if the surface is [`Empty`](Surface::Empty), [`Main`](Surface::Main), or doesn't exist.
Expand Down Expand Up @@ -186,7 +186,7 @@ impl<Tab> DockState<Tab> {
&mut self,
(surface_index, node_index, tab_index): (SurfaceIndex, NodeIndex, TabIndex),
) {
if let Some(Node::Leaf { active, .. }) = self[surface_index].tree.get_mut(node_index.0) {
if let Some(Node::Leaf { active, .. }) = self[surface_index].nodes.get_mut(node_index.0) {
*active = tab_index;
}
}
Expand Down Expand Up @@ -368,24 +368,112 @@ impl<Tab> DockState<Tab> {
self[SurfaceIndex::main()].push_to_first_leaf(tab);
}

/// Returns an `Iterator` of the underlying collection of nodes on the **main surface**.
#[deprecated = "Use `iter_main_surface_nodes` or `iter_nodes` instead"]
pub fn iter(&self) -> std::slice::Iter<'_, Node<Tab>> {
self.iter_main_surface_nodes()
/// Returns the current number of surfaces.
pub fn surfaces_count(&self) -> usize {
self.surfaces.len()
}

/// Returns an [`Iterator`] over all surfaces.
pub fn iter_surfaces(&self) -> impl Iterator<Item = &Surface<Tab>> {
self.surfaces.iter()
}

/// Returns a mutable [`Iterator`] over all surfaces.
pub fn iter_surfaces_mut(&mut self) -> impl Iterator<Item = &mut Surface<Tab>> {
self.surfaces.iter_mut()
}

/// Returns an [`Iterator`] of **all** underlying nodes in the dock state,
/// and the indices of containing surfaces.
pub fn iter_all_nodes(&self) -> impl Iterator<Item = (SurfaceIndex, &Node<Tab>)> {
self.iter_surfaces()
.enumerate()
.flat_map(|(surface_index, surface)| {
surface
.iter_nodes()
.map(move |node| (SurfaceIndex(surface_index), node))
})
}

/// Returns an `Iterator` of the underlying collection of nodes on the main surface.
pub fn iter_main_surface_nodes(&self) -> std::slice::Iter<'_, Node<Tab>> {
/// Returns a mutable [`Iterator`] of **all** underlying nodes in the dock state,
/// and the indices of containing surfaces.
pub fn iter_all_nodes_mut(&mut self) -> impl Iterator<Item = (SurfaceIndex, &mut Node<Tab>)> {
self.iter_surfaces_mut()
.enumerate()
.flat_map(|(surface_index, surface)| {
surface
.iter_nodes_mut()
.map(move |node| (SurfaceIndex(surface_index), node))
})
}

/// Returns an [`Iterator`] of **all** tabs in the dock state,
/// and the indices of containing surfaces and nodes.
pub fn iter_all_tabs(&self) -> impl Iterator<Item = ((SurfaceIndex, NodeIndex), &Tab)> {
self.iter_surfaces()
.enumerate()
.flat_map(|(surface_index, surface)| {
surface
.iter_all_tabs()
.map(move |(node_index, tab)| ((SurfaceIndex(surface_index), node_index), tab))
})
}

/// Returns a mutable [`Iterator`] of **all** tabs in the dock state,
/// and the indices of containing surfaces and nodes.
pub fn iter_all_tabs_mut(
&mut self,
) -> impl Iterator<Item = ((SurfaceIndex, NodeIndex), &mut Tab)> {
self.iter_surfaces_mut()
.enumerate()
.flat_map(|(surface_index, surface)| {
surface
.iter_all_tabs_mut()
.map(move |(node_index, tab)| ((SurfaceIndex(surface_index), node_index), tab))
})
}

/// Returns an [`Iterator`] of the underlying collection of nodes on the main surface.
#[deprecated = "Use `dock_state.main_surface().iter()` instead"]
pub fn iter_main_surface_nodes(&self) -> impl Iterator<Item = &Node<Tab>> {
self[SurfaceIndex::main()].iter()
}

/// Returns an `Iterator` of **all** underlying nodes in the dock state and all subsequent trees.
/// Returns a mutable [`Iterator`] of the underlying collection of nodes on the main surface.
#[deprecated = "Use `dock_state.main_surface_mut().iter_mut()` instead"]
pub fn iter_main_surface_nodes_mut(&mut self) -> impl Iterator<Item = &mut Node<Tab>> {
self[SurfaceIndex::main()].iter_mut()
}

/// Returns an [`Iterator`] of **all** underlying nodes in the dock state and all subsequent trees.
#[deprecated = "Use `iter_all_nodes` instead"]
pub fn iter_nodes(&self) -> impl Iterator<Item = &Node<Tab>> {
self.surfaces
.iter()
.filter_map(|tree| tree.node_tree())
.filter_map(|surface| surface.node_tree())
.flat_map(|nodes| nodes.iter())
}

/// Returns a new DockState while mapping the tab type
pub fn map_tabs<F, NewTab>(&self, function: F) -> DockState<NewTab>
where
F: FnMut(&Tab) -> NewTab + Clone,
{
let DockState {
surfaces,
focused_surface,
translations,
} = self;
let surfaces = surfaces
.iter()
.map(|surface| surface.map_tabs(function.clone()))
.collect();
DockState {
surfaces,
focused_surface: *focused_surface,
translations: translations.clone(),
}
}
}

impl<Tab> DockState<Tab>
Expand Down
60 changes: 55 additions & 5 deletions src/dock_state/surface.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Tree, WindowState};
use crate::{Node, NodeIndex, Tree, WindowState};

/// A [`Surface`] is the highest level component in a [`DockState`](crate::DockState). [`Surface`]s represent an area
/// in which nodes are placed. Typically, you're only using one surface, which is the main surface. However, if you drag
Expand All @@ -22,21 +22,71 @@ impl<Tab> Surface<Tab> {
matches!(self, Self::Empty)
}

/// Get mutable access to the node tree of this surface.
pub fn node_tree_mut(&mut self) -> Option<&mut Tree<Tab>> {
/// Get access to the node tree of this surface.
pub fn node_tree(&self) -> Option<&Tree<Tab>> {
match self {
Surface::Empty => None,
Surface::Main(tree) => Some(tree),
Surface::Window(tree, _) => Some(tree),
}
}

/// Get access to the node tree of this surface.
pub fn node_tree(&self) -> Option<&Tree<Tab>> {
/// Get mutable access to the node tree of this surface.
pub fn node_tree_mut(&mut self) -> Option<&mut Tree<Tab>> {
match self {
Surface::Empty => None,
Surface::Main(tree) => Some(tree),
Surface::Window(tree, _) => Some(tree),
}
}

/// Returns an [`Iterator`] of nodes in this surface's tree.
///
/// If the surface is [`Empty`](Self::Empty), then the returned [`Iterator`] will be empty.
pub fn iter_nodes(&self) -> impl Iterator<Item = &Node<Tab>> {
match self.node_tree() {
Some(tree) => tree.iter(),
None => core::slice::Iter::default(),
}
}

/// Returns a mutable [`Iterator`] of nodes in this surface's tree.
///
/// If the surface is [`Empty`](Self::Empty), then the returned [`Iterator`] will be empty.
pub fn iter_nodes_mut(&mut self) -> impl Iterator<Item = &mut Node<Tab>> {
match self.node_tree_mut() {
Some(tree) => tree.iter_mut(),
None => core::slice::IterMut::default(),
}
}

/// Returns an [`Iterator`] of **all** tabs in this surface's tree,
/// and indices of containing nodes.
pub fn iter_all_tabs(&self) -> impl Iterator<Item = (NodeIndex, &Tab)> {
self.iter_nodes()
.enumerate()
.flat_map(|(index, node)| node.iter_tabs().map(move |tab| (NodeIndex(index), tab)))
}

/// Returns a mutable [`Iterator`] of **all** tabs in this surface's tree,
/// and indices of containing nodes.
pub fn iter_all_tabs_mut(&mut self) -> impl Iterator<Item = (NodeIndex, &mut Tab)> {
self.iter_nodes_mut()
.enumerate()
.flat_map(|(index, node)| node.iter_tabs_mut().map(move |tab| (NodeIndex(index), tab)))
}

/// Returns a new Surface while mapping the tab type
pub fn map_tabs<F, NewTab>(&self, function: F) -> Surface<NewTab>
where
F: FnMut(&Tab) -> NewTab + Clone,
{
match self {
Surface::Empty => Surface::Empty,
Surface::Main(tree) => Surface::Main(tree.map_tabs(function)),
Surface::Window(tree, window_state) => {
Surface::Window(tree.map_tabs(function), window_state.clone())
}
}
}
}
Loading

0 comments on commit c360442

Please sign in to comment.