Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Usage Tips #29

Closed
gold-silver-copper opened this issue Jun 22, 2024 · 2 comments
Closed

Usage Tips #29

gold-silver-copper opened this issue Jun 22, 2024 · 2 comments

Comments

@gold-silver-copper
Copy link
Owner

If I find ways that make using the library better, I will document them here. Later I will make a better source but this is it for now.

@gold-silver-copper
Copy link
Owner Author

gold-silver-copper commented Jun 22, 2024

The reason for the following is: An egui window with a certain width and frame will cause the last character of the terminal to be cut off.

If you are creating an egui context with a fixed width and no frame, make it a multiple of the font size. So if you have a font size of 16, and you want a terminal 20 characters wide, you can set the width to 16*20=320.

If you want to add an egui frame to the context containing the ratatui terminal, I recommend adding a buffer to the preceding value to account for the Frame margin. So if you have a frame, font size 16, and a terminal 20 characters wide- then use a buffer value a bit lower than the font size, so we can use 14 (Might have to play around with it). Thus the size should be 16*20 + 14 = 334. For better effect, modify the Frame properties, see: https://docs.rs/egui/latest/egui/containers/struct.Frame.html

Sample Code:

let mut backend1 = RataguiBackend::new(20, 20);
backend1.set_font_size(16);
let mut ratatui_terminal_1 = Terminal::new(backend1).unwrap();
egui::SidePanel::right("my_left_panel")
        .frame(Frame::none())
        .min_width(320.0)
        .max_width(320.0)
        .show(contexts.ctx_mut(), |ui| {
            ui.add(ratatui_terminal_1.backend_mut());
        });

OR

egui::SidePanel::right("my_left_panel")
        .min_width(334.0)
        .max_width(334.0)
        .show(contexts.ctx_mut(), |ui| {
            ui.add(ratatui_terminal_1.backend_mut());
        });

@gold-silver-copper gold-silver-copper pinned this issue Jun 22, 2024
@gold-silver-copper
Copy link
Owner Author

gold-silver-copper commented Jun 22, 2024

If you need to have a ratatui terminal and another egui widget in the same window, you should wrap both into an egui container. This is because egui_ratatui works by always filling it's own context completely, nothing else can be added to the context directly containing a ratatui terminal.

     egui::SidePanel::right("container")
                .show_inside(ui, |ui| {

                    egui::TopBottomPanel::top("terminal_1")
                            .frame(Frame::none())
                            .min_height(320.)
                            .max_height(320.)
                         
                            .show_inside(ui, |ui| {
                                ui.add(ratatui_terminal_1.backend_mut());
                            });
                    

                    egui::TopBottomPanel::bottom("bottom_panel")
                        .frame(Frame::none())
                        .min_height(ui.available_height())
                        .max_height(ui.available_height())
                
                        .show_inside(ui, |ui| {
                           ui.label("Hello world !!!");
                        });
                });

Repository owner locked and limited conversation to collaborators Jun 22, 2024
@gold-silver-copper gold-silver-copper converted this issue into discussion #31 Jun 22, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant