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

Tab rewrite #6

Merged
merged 8 commits into from
Aug 14, 2022
Merged

Tab rewrite #6

merged 8 commits into from
Aug 14, 2022

Conversation

Adanos020
Copy link
Owner

@Adanos020 Adanos020 commented Aug 13, 2022

Tab is no longer a trait which the user has to implement on their own custom widget. A context type is also no longer required.

This makes creating trees easier without limiting customizability.

Example:

// Initial tree setup
let tab1 = TabBuilder::default()
    .title("Tab 1")
    .content(|ui| {
        ui.label("Tab 1");
    })
    .build();
let tab2 = TabBuilder::default()
    .title("Tab 2")
    .inner_margin(Margin::same(4.0))
    .content(|ui| {
        ui.label("Tab 2");
    })
    .build();
let mut tree = Tree::new(vec![tab1, tab2]);

// Then, in your app's `update` function:
egui_dock::show(&mut ui, id, &style, &mut tree)

Part of this PR is closing #1 and #5

@Adanos020 Adanos020 self-assigned this Aug 13, 2022
@Jerrody
Copy link
Contributor

Jerrody commented Aug 13, 2022

Would be nice if it will be possible to get data from the tab.
As an example, for the window drag for too be easy to transfer data to the new window.

I don't use egui so many time, so I don't understand how to copy content from the window.

@Adanos020
Copy link
Owner Author

Would be nice if it will be possible to get data from the tab. As an example, for the window drag for too be easy to transfer data to the new window.

I don't use egui so many time, so I don't understand how to copy content from the window.

I think moving the add_content function out of Tab and putting it in a wrapper which internally creates an egui::Window could do the trick.

@Jerrody
Copy link
Contributor

Jerrody commented Aug 13, 2022

Would be nice if it will be possible to get data from the tab. As an example, for the window drag for too be easy to transfer data to the new window.
I don't use egui so many time, so I don't understand how to copy content from the window.

I think moving the add_content function out of Tab and putting it in a wrapper which internally creates an egui::Window could do the trick.

Yes, I made the same. I made a DockWindow that internally also creates an egui::Window, so I think we should just move ownership to the dock_windows and everything works very well.

@Adanos020
Copy link
Owner Author

I think the main goals of this PR have just been achieved 👍

@boonkerz
Copy link

currently the context is not required anymore but how should i use it?

as example i need to access something from the ui method.

fn ui(&mut self, ui: &mut egui::Ui, _ctx: &mut AppContext) that is what i used before.

@Adanos020
Copy link
Owner Author

currently the context is not required anymore but how should i use it?

as example i need to access something from the ui method.

fn ui(&mut self, ui: &mut egui::Ui, _ctx: &mut AppContext) that is what i used before.

Currently you can hold your data in an Rc/Arc, and have the closure of your tab own a copy of it, as demonstrated in this example: https://github.com/Adanos020/egui_dock/blob/main/examples/hello.rs#L57

The reason for this change is that in the previous version you could only have one type and only one instance of the context being passed to all tabs in one Tree, limiting your ability to control what data gets passed where. If you were dealing with many tabs accessing many different pieces of data, you'd have to store all of that data in a single struct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants