mirror of
https://github.com/encounter/egui_dock.git
synced 2026-03-30 11:08:47 -07:00
66d9dd5773
* WIP: update to latest egui * Update egui git hash * Update examples * Example style editor: make color pickers into popups * Nicer style editor * Simplify the tab painting, and make it look better * simplify code * Add hline_color * Add ability to control text color of active tabs * Document Node::Lead * Derive clone * Code cleanup * Bug fix: show grab cursor preview when hovering a tab * Add TabViewer::on_tab_button to let users listen for clicks etc * use same resize colors as egui * Update to egui 0.21.0 * Don't force default_fonts onto users of egui_dock * Update changelog
54 lines
1.4 KiB
Rust
54 lines
1.4 KiB
Rust
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
|
|
|
use eframe::{egui, NativeOptions};
|
|
|
|
use egui_dock::{DockArea, NodeIndex, Style, Tree};
|
|
|
|
fn main() -> eframe::Result<()> {
|
|
let options = NativeOptions::default();
|
|
eframe::run_native(
|
|
"My egui App",
|
|
options,
|
|
Box::new(|_cc| Box::<MyApp>::default()),
|
|
)
|
|
}
|
|
|
|
struct TabViewer {}
|
|
|
|
impl egui_dock::TabViewer for TabViewer {
|
|
type Tab = String;
|
|
|
|
fn ui(&mut self, ui: &mut egui::Ui, tab: &mut Self::Tab) {
|
|
ui.label(format!("Content of {tab}"));
|
|
}
|
|
|
|
fn title(&mut self, tab: &mut Self::Tab) -> egui::WidgetText {
|
|
(&*tab).into()
|
|
}
|
|
}
|
|
|
|
struct MyApp {
|
|
tree: Tree<String>,
|
|
}
|
|
|
|
impl Default for MyApp {
|
|
fn default() -> Self {
|
|
let mut tree = Tree::new(vec!["tab1".to_owned(), "tab2".to_owned()]);
|
|
|
|
// You can modify the tree before constructing the dock
|
|
let [a, b] = tree.split_left(NodeIndex::root(), 0.3, vec!["tab3".to_owned()]);
|
|
let [_, _] = tree.split_below(a, 0.7, vec!["tab4".to_owned()]);
|
|
let [_, _] = tree.split_below(b, 0.5, vec!["tab5".to_owned()]);
|
|
|
|
Self { tree }
|
|
}
|
|
}
|
|
|
|
impl eframe::App for MyApp {
|
|
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
|
DockArea::new(&mut self.tree)
|
|
.style(Style::from_egui(ctx.style().as_ref()))
|
|
.show(ctx, &mut TabViewer {});
|
|
}
|
|
}
|