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

Switch from egui_dock to egui_tiles #2082

Merged
merged 4 commits into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
46 changes: 25 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ ctrlc = { version = "3.0", features = ["termination"] }
ecolor = "0.21.0"
eframe = { version = "0.21.3", default-features = false }
egui = { version = "0.21.0", features = ["extra_debug_asserts", "log"] }
egui_dock = "0.4"
egui_extras = { version = "0.21.0", features = ["log"] }
egui_tiles = { git = "https://github.com/rerun-io/egui_tiles", rev = "9a6ed5852a0d2f3b18db0c7b8fb1b1bf904b0a51" }
egui-wgpu = "0.21.0"
emath = "0.21.0"
enumset = "1.0.12"
Expand Down Expand Up @@ -125,13 +125,13 @@ debug = true
# ALWAYS document what PR the commit hash is part of, or when it was merged into the upstream trunk.

# TODO(andreas/emilk): Update to a stable egui version
# wgpu 0.16 support, device configuration dependent on adapter
ecolor = { git = "https://github.com/emilk/egui", rev = "f76eefb98d23cbf71989255aafe75a07d343f6ed" }
eframe = { git = "https://github.com/emilk/egui", rev = "f76eefb98d23cbf71989255aafe75a07d343f6ed" }
egui = { git = "https://github.com/emilk/egui", rev = "f76eefb98d23cbf71989255aafe75a07d343f6ed" }
egui-wgpu = { git = "https://github.com/emilk/egui", rev = "f76eefb98d23cbf71989255aafe75a07d343f6ed" }
egui_extras = { git = "https://github.com/emilk/egui", rev = "f76eefb98d23cbf71989255aafe75a07d343f6ed" }
emath = { git = "https://github.com/emilk/egui", rev = "f76eefb98d23cbf71989255aafe75a07d343f6ed" }
# wgpu 0.16 support, device configuration dependent on adapter, and some additions to help egui_tiles
ecolor = { git = "https://github.com/emilk/egui", rev = "e9fa6c8ff68a0257ce0f2801446ba701917b7ae9" }
eframe = { git = "https://github.com/emilk/egui", rev = "e9fa6c8ff68a0257ce0f2801446ba701917b7ae9" }
egui = { git = "https://github.com/emilk/egui", rev = "e9fa6c8ff68a0257ce0f2801446ba701917b7ae9" }
egui-wgpu = { git = "https://github.com/emilk/egui", rev = "e9fa6c8ff68a0257ce0f2801446ba701917b7ae9" }
egui_extras = { git = "https://github.com/emilk/egui", rev = "e9fa6c8ff68a0257ce0f2801446ba701917b7ae9" }
emath = { git = "https://github.com/emilk/egui", rev = "e9fa6c8ff68a0257ce0f2801446ba701917b7ae9" }

# TODO(andreas): Either work around this issue in wgpu-egui (never discard command buffers) or wait for wgpu patch release.
# Fix for command buffer dropping crash https://github.com/gfx-rs/wgpu/pull/3726
Expand Down
5 changes: 2 additions & 3 deletions crates/re_ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ all-features = true


[features]
default = ["eframe", "egui_dock"]
default = ["eframe"]

eframe = ["dep:eframe"]
egui_dock = ["dep:egui_dock"]


[dependencies]
Expand All @@ -42,8 +41,8 @@ sublime_fuzzy = "0.7"

## Optional dependencies:
eframe = { workspace = true, optional = true, default-features = false }
egui_dock = { workspace = true, optional = true, features = ["serde"] }

[dev-dependencies]
eframe = { workspace = true, default-features = false, features = ["wgpu"] }
egui_tiles.workspace = true
re_log.workspace = true
54 changes: 40 additions & 14 deletions crates/re_ui/examples/re_ui_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub struct ExampleApp {
/// Listens to the local text log stream
text_log_rx: std::sync::mpsc::Receiver<re_log::LogMsg>,

tree: egui_dock::Tree<Tab>,
tree: egui_tiles::Tree<Tab>,

left_panel: bool,
right_panel: bool,
Expand All @@ -56,7 +56,7 @@ impl ExampleApp {
let (logger, text_log_rx) = re_log::ChannelLogger::new(re_log::LevelFilter::Info);
re_log::add_boxed_logger(Box::new(logger)).unwrap();

let tree = egui_dock::Tree::new(vec![1, 2, 3]);
let tree = egui_tiles::Tree::new_tabs(vec![1, 2, 3]);

Self {
re_ui,
Expand Down Expand Up @@ -337,27 +337,53 @@ fn selection_buttons(ui: &mut egui::Ui) {
});
}

fn tabs_ui(ui: &mut egui::Ui, tree: &mut egui_dock::Tree<Tab>) {
let mut my_tab_viewer = MyTabViewer {};
egui_dock::DockArea::new(tree)
.style(re_ui::egui_dock_style(ui.style()))
.show_inside(ui, &mut my_tab_viewer);
fn tabs_ui(ui: &mut egui::Ui, tree: &mut egui_tiles::Tree<Tab>) {
tree.ui(&mut MyTileTreeBehavior {}, ui);
}

pub type Tab = i32;

struct MyTabViewer {}
struct MyTileTreeBehavior {}

impl egui_dock::TabViewer for MyTabViewer {
type Tab = Tab;

fn ui(&mut self, ui: &mut egui::Ui, _tab: &mut Self::Tab) {
impl egui_tiles::Behavior<Tab> for MyTileTreeBehavior {
fn pane_ui(
&mut self,
ui: &mut egui::Ui,
_tile_id: egui_tiles::TileId,
_pane: &mut Tab,
) -> egui_tiles::UiResponse {
egui::warn_if_debug_build(ui);
ui.label("Hover me for a tooltip")
.on_hover_text("This is a tooltip");

Default::default()
}

fn tab_title_for_pane(&mut self, pane: &Tab) -> egui::WidgetText {
format!("This is tab {pane}").into()
}

fn title(&mut self, tab: &mut Self::Tab) -> egui::WidgetText {
format!("This is tab {tab}").into()
// Styling:

fn tab_outline_stroke(
&self,
_visuals: &egui::Visuals,
_tile_id: egui_tiles::TileId,
_active: bool,
) -> egui::Stroke {
egui::Stroke::NONE
}

/// The height of the bar holding tab titles.
fn tab_bar_height(&self, _style: &egui::Style) -> f32 {
re_ui::ReUi::title_bar_height()
}

/// What are the rules for simplifying the tree?
fn simplification_options(&self) -> egui_tiles::SimplificationOptions {
egui_tiles::SimplificationOptions {
all_panes_must_have_tabs: true,
..Default::default()
}
}
}
35 changes: 0 additions & 35 deletions crates/re_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,41 +610,6 @@ impl ReUi {

// ----------------------------------------------------------------------------

#[cfg(feature = "egui_dock")]
pub fn egui_dock_style(style: &egui::Style) -> egui_dock::Style {
let mut dock_style = egui_dock::Style::from_egui(style);
dock_style.separator_width = 2.0;
dock_style.tab_bar_height = ReUi::title_bar_height();
dock_style.default_inner_margin = 0.0.into();
dock_style.show_close_buttons = false;
dock_style.tab_include_scrollarea = false;
dock_style.show_context_menu = false;
dock_style.expand_tabs = false; // expand_tabs looks good, but decreases readability

// Tabs can be "focused", meaning it was the last clicked (of any tab). We don't care about that.
// Tabs can also be "active", meaning it is the selected tab within its sibling tabs. We want to highlight that.
let inactive_text_color = style.visuals.widgets.noninteractive.text_color();
let active_text_color = style.visuals.widgets.active.text_color();

dock_style.tab_text_color_unfocused = inactive_text_color;
dock_style.tab_text_color_focused = inactive_text_color;
dock_style.tab_text_color_active_unfocused = active_text_color;
dock_style.tab_text_color_active_focused = active_text_color;

// Don't show tabs
dock_style.tab_bar_background_color = style.visuals.panel_fill;
dock_style.tab_background_color = style.visuals.panel_fill;

dock_style.hline_color = style.visuals.widgets.noninteractive.bg_stroke.color;

// The active tab has no special outline:
dock_style.tab_outline_color = Color32::TRANSPARENT;

dock_style
}

// ----------------------------------------------------------------------------

/// Show some close/maximize/minimize buttons for the native window.
///
/// Assumes it is in a right-to-left layout.
Expand Down
4 changes: 2 additions & 2 deletions crates/re_viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ re_renderer = { workspace = true, default-features = false, features = [
] }
re_smart_channel.workspace = true
re_tensor_ops.workspace = true
re_ui = { workspace = true, features = ["eframe", "egui_dock"] }
re_ui = { workspace = true, features = ["eframe"] }
re_viewer_context.workspace = true
re_ws_comms = { workspace = true, features = ["client"] }

Expand All @@ -77,8 +77,8 @@ eframe = { workspace = true, default-features = false, features = [
"wgpu",
] }
egui.workspace = true
egui_dock = { workspace = true, features = ["serde"] }
egui_extras.workspace = true
egui_tiles.workspace = true
egui-wgpu.workspace = true
enumset.workspace = true
glam = { workspace = true, features = [
Expand Down
Loading