#egui #window #structs #applications #events #window-event #package

egui-multiwin

A crate that allows for multiple windows with egui

18 releases

0.3.1 Nov 2, 2023
0.2.2 Oct 19, 2023
0.1.7 Jul 10, 2023
0.1.3 Mar 19, 2023
0.1.1 Sep 1, 2022

#5 in #window-event

44 downloads per month
Used in bjj_scoreboard

MIT/Apache

130KB
685 lines

This is the egui-multiwin crate.

Rust Windows Rust MacOS Rust Linux

This crate is based on the work by vivlim (https://github.com/vivlim) and repository located (https://github.com/vivlim/egui-glow-multiwin). Vivlim's example repository combines the work at https://github.com/shivshank/mini_gl_fb/blob/master/examples/multi_window.rs and egui to form a nice package. This crate makes some modifications to make it useful as an external crate by defining a few traits for users to implement on their custom structs.

There is an example that shows how to use this crate in your project. It is named multiwin-demo and is in the examples folder.

Generally you will create a struct for data that is common to all windows, implement the egui_multiwin::multi_window::CommonEventHandler<T,U> trait on it. T is the name of your struct, and U and the name of the message you want to pass as a non-window specific event.

pub struct AppCommon {
    clicks: u32,
}
impl egui_multiwin::multi_window::CommonEventHandler<AppCommon, u32> for AppCommon {
    fn process_event(&mut self, event: u32) -> Vec<egui_multiwin::multi_window::NewWindowRequest<AppCommon>> {
        let mut windows_to_create = vec![];
        println!("Received an event {}", event);
        match event {
            42 => windows_to_create.push(windows::popup_window::PopupWindow::new("event popup".to_string())),
            _ => {}
        }
        windows_to_create
    }
}

Check github issues to see if wayland (linux) still has a problem with the clipboard. That issue should give a temporary solution to a segfault that occurs after closing a window in your program.

In your main event, create an event loop, create an event loop proxy (if desired). The event loop proxy can be cloned and sent to other threads, allowing custom logic to send events that can create windows and modify the common state of the application as required. Create a multiwindow instance, then create window requests to make initial windows, and add them to the multiwindow with the add function. Create an instance of your common data structure, and finally call run of your multiwindow instance.

Dependencies

~9–26MB
~377K SLoC