fastframe-ui-dock
Dockable tabbed panels for fastframe-ui, as in an IDE: drag a tab onto another panel to move it there, onto a panel’s edge to split it, or out of the window to float it, and drag the lines between panels to resize them. egui_dock does the docking; this crate draws it in the fastframe-ui theme.
It is a crate of its own so only apps that dock pull egui_dock in.
[dependencies]
fastframe-ui-dock = { git = "https://github.com/crmne/fastframe", tag = "v0.19.0" }
Use
Keep a DockState in your app, implement TabViewer for what each tab is
called and shows, and show it with Dock in a sized area, such as a
central panel:
use fastframe_ui_dock::{Dock, DockState, NodeIndex, TabViewer};
struct Files;
impl TabViewer for Files {
type Tab = String;
fn id(&mut self, tab: &mut String) -> egui::Id {
egui::Id::unique(tab.as_str())
}
fn title(&mut self, tab: &mut String) -> egui::WidgetText {
tab.as_str().into()
}
fn ui(&mut self, ui: &mut egui::Ui, tab: &mut String) {
ui.label(format!("The contents of {tab}"));
}
}
fn new_state() -> DockState<String> {
let mut state = DockState::new(vec!["main.rs".to_owned(), "lib.rs".to_owned()]);
state
.main_surface_mut()
.split_right(NodeIndex::root(), 0.7, vec!["Outline".to_owned()]);
state
}
fn panels(ui: &mut egui::Ui, state: &mut DockState<String>) {
Dock::new(state).show(ui, &mut Files);
}
Styles
As everywhere in fastframe-ui, the dock says what it holds and a style
decides how it looks. dock_styles::Standard (the default) draws
fastframe-ui’s tab bar, the chosen tab lifted onto the page;
dock_styles::Pill draws round tabs with no lines under them. Set one for
a dock with .style(&dock_styles::Pill), or for every dock in a part of
the window with ui.dock_style(dock_styles::Pill, |ui| ...). The tab bars
are as tall as the control size around them (ui.control_size(...)).
A style of your own implements DockStyle, which builds egui_dock’s
Style from the theme: start from a built-in style’s and change what you
need. Any other egui_dock option is one call away with
Dock::area(|area| ...).
Every style pads a pane’s content by the look’s content inset, so text
lines up with the tab’s title. A pane that holds a list, a tree or a table
should drop the side padding, since its rows already sit in by that much:
return fastframe_ui_dock::flush_sides(style) from
TabViewer::tab_style_override for that tab.
Why egui_dock
egui_dock and egui_tiles both dock tabs in egui 0.37. egui_dock was chosen for the better experience and the simpler themed API:
- It behaves like an IDE out of the box: drop targets shown over the panel under the pointer, tabs floated into windows of their own and docked back, close buttons and middle-click to close, a context menu on each tab, and keyboard focus for tabs and the lines between panels. egui_tiles has no floating windows or drop overlay, and leaves closing and its buttons to the app.
- Its whole look is one data struct (
egui_dock::Style), so a fastframe style fills it from the theme once a frame and the app’sTabViewerstays about content. egui_tiles reads its look from methods on the sameBehaviortrait the app implements for content, so theming it would mean wrapping every app’s behaviour.
Licence
MIT. egui_dock is MIT too; see NOTICE.
Related crates
Draws the interface, like this one:
- egui components and widgets: Buttons, tables, dialogs, pickers and the rest, with four looks, 21 bundled theme files, light and dark.
- Diff viewer: Unified or side by side, with word highlights and folded lines, fast on long files.
- Code editor: Line numbers, syntax colours for common languages, the current line and find.
All 27 fastframe crates, by what they do for an app.