Struct blue_engine_egui::EGUI

source ·
pub struct EGUI {
    pub context: Context,
    pub platform: State,
    pub renderer: Renderer,
    pub full_output: Option<FullOutput>,
}
Expand description

The egui plugin

Fields§

§context: Context§platform: State§renderer: Renderer§full_output: Option<FullOutput>

Implementations§

source§

impl EGUI

source

pub fn new(event_loop: &EventLoop<()>, renderer: &mut Renderer) -> Self

Creates the egui context and platform details

Examples found in repository?
examples/hello_gui.rs (line 32)
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
fn main() {
    // Initialize the engine with default settings
    let mut engine = Engine::new().expect("win");

    // Add a triangle to the screen
    triangle(
        "triangle",
        ObjectSettings::default(),
        &mut engine.renderer,
        &mut engine.objects,
    )
    .unwrap();

    // Start the egui context
    let gui_context = blue_engine_egui::EGUI::new(&engine.event_loop, &mut engine.renderer);

    // We add the gui as plugin, which runs once before everything else to fetch events, and once during render times for rendering and other stuff
    engine.plugins.push(Box::new(gui_context));

    let mut color = [1f32, 1f32, 1f32, 1f32];

    // Update loop
    engine
        .update_loop(move |_, window, objects, _, _, plugins| {
            // obtain the plugin
            let egui_plugin = plugins[0]
                // downcast it to obtain the plugin
                .downcast_mut::<blue_engine_egui::EGUI>()
                .expect("Plugin not found");

            // ui function will provide the context
            egui_plugin.ui(
                |ctx| {
                    gui::Window::new("title").show(ctx, |ui| {
                        ui.horizontal(|ui| {
                            ui.label("Pick a color");
                            ui.color_edit_button_rgba_unmultiplied(&mut color);
                        });
                    });

                    objects
                        .get_mut("triangle")
                        .unwrap()
                        .set_uniform_color(color[0], color[1], color[2], color[3])
                        .unwrap();
                },
                &window,
            );
        })
        .expect("Error during update loop");
}
More examples
Hide additional examples
examples/custom_3d.rs (line 23)
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
fn main() {
    // Initialize the engine with default settings
    let mut engine = Engine::new().expect("win");

    // the object to display
    cube("cube", &mut engine.renderer, &mut engine.objects).expect("Couldn't create the cube");

    // Start the egui context
    let mut gui_context = blue_engine_egui::EGUI::new(&engine.event_loop, &mut engine.renderer);

    // here we only need object temporarily
    let mut custom_rendering = {
        let mut object = engine.objects.get_mut("cube").unwrap();
        // this will not render the object in the background
        object.is_visible = false;
        // create our instance of graphics
        EmbeddedRender::new(&mut object, &mut engine.renderer, &mut gui_context.renderer).unwrap()
    };

    // We add the gui as plugin, which runs once before everything else to fetch events, and once during render times for rendering and other stuff
    engine.plugins.push(Box::new(gui_context));

    let mut color = [1f32, 1f32, 1f32, 1f32];
    let radius = 5f32;
    let start = std::time::SystemTime::now();

    // Update loop
    engine
        .update_loop(move |renderer, window, objects, _, camera, plugins| {
            // obtain the plugin
            let egui_plugin = plugins[0]
                // downcast it to obtain the plugin
                .downcast_mut::<blue_engine_egui::EGUI>()
                .expect("Plugin not found");

            // Get our object
            let cube = objects.get_mut("cube").unwrap();
            // and get current camera unifrom data
            let camera_data = camera.update_view_projection_and_return(renderer).unwrap();
            // and prepare the data for our graphics
            custom_rendering.prepare(cube, renderer, &mut egui_plugin.renderer, camera_data);
            // ui function will provide the context
            egui_plugin.ui(
                |ctx| {
                    // This window will contain our graphics
                    egui::Window::new("title").resizable(true).show(ctx, |ui| {
                        // We make a canvas to paint our graphics
                        egui::Frame::canvas(ui.style()).show(ui, |ui| {
                            // Paint our graphics
                            custom_rendering.paint(ui);
                        });

                        // to allocate space that is available after resize
                        ui.allocate_space(ui.available_size());
                    });

                    // We can also do our other GUI stuff as always,
                    egui::Window::new("Pick Color")
                        .resizable(true)
                        .show(ctx, |ui| {
                            ui.horizontal(|ui| {
                                ui.label("Pick a color");
                                ui.color_edit_button_rgba_unmultiplied(&mut color);
                            });
                        });
                },
                &window,
            );

            // we can normally apply changes to our graphics
            cube.set_uniform_color(color[0], color[1], color[2], color[3])
                .unwrap();

            // and even other settings
            let camx = start.elapsed().unwrap().as_secs_f32().sin() * radius;
            let camy = start.elapsed().unwrap().as_secs_f32().sin() * radius;
            let camz = start.elapsed().unwrap().as_secs_f32().cos() * radius;
            camera
                .set_position(camx, camy, camz)
                .expect("Couldn't update the camera eye");
        })
        .expect("Error during update loop");
}
source

pub fn ui<F: FnOnce(&Context)>(&mut self, callback: F, window: &Win)

Examples found in repository?
examples/hello_gui.rs (lines 49-65)
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
fn main() {
    // Initialize the engine with default settings
    let mut engine = Engine::new().expect("win");

    // Add a triangle to the screen
    triangle(
        "triangle",
        ObjectSettings::default(),
        &mut engine.renderer,
        &mut engine.objects,
    )
    .unwrap();

    // Start the egui context
    let gui_context = blue_engine_egui::EGUI::new(&engine.event_loop, &mut engine.renderer);

    // We add the gui as plugin, which runs once before everything else to fetch events, and once during render times for rendering and other stuff
    engine.plugins.push(Box::new(gui_context));

    let mut color = [1f32, 1f32, 1f32, 1f32];

    // Update loop
    engine
        .update_loop(move |_, window, objects, _, _, plugins| {
            // obtain the plugin
            let egui_plugin = plugins[0]
                // downcast it to obtain the plugin
                .downcast_mut::<blue_engine_egui::EGUI>()
                .expect("Plugin not found");

            // ui function will provide the context
            egui_plugin.ui(
                |ctx| {
                    gui::Window::new("title").show(ctx, |ui| {
                        ui.horizontal(|ui| {
                            ui.label("Pick a color");
                            ui.color_edit_button_rgba_unmultiplied(&mut color);
                        });
                    });

                    objects
                        .get_mut("triangle")
                        .unwrap()
                        .set_uniform_color(color[0], color[1], color[2], color[3])
                        .unwrap();
                },
                &window,
            );
        })
        .expect("Error during update loop");
}
More examples
Hide additional examples
examples/custom_3d.rs (lines 57-82)
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
fn main() {
    // Initialize the engine with default settings
    let mut engine = Engine::new().expect("win");

    // the object to display
    cube("cube", &mut engine.renderer, &mut engine.objects).expect("Couldn't create the cube");

    // Start the egui context
    let mut gui_context = blue_engine_egui::EGUI::new(&engine.event_loop, &mut engine.renderer);

    // here we only need object temporarily
    let mut custom_rendering = {
        let mut object = engine.objects.get_mut("cube").unwrap();
        // this will not render the object in the background
        object.is_visible = false;
        // create our instance of graphics
        EmbeddedRender::new(&mut object, &mut engine.renderer, &mut gui_context.renderer).unwrap()
    };

    // We add the gui as plugin, which runs once before everything else to fetch events, and once during render times for rendering and other stuff
    engine.plugins.push(Box::new(gui_context));

    let mut color = [1f32, 1f32, 1f32, 1f32];
    let radius = 5f32;
    let start = std::time::SystemTime::now();

    // Update loop
    engine
        .update_loop(move |renderer, window, objects, _, camera, plugins| {
            // obtain the plugin
            let egui_plugin = plugins[0]
                // downcast it to obtain the plugin
                .downcast_mut::<blue_engine_egui::EGUI>()
                .expect("Plugin not found");

            // Get our object
            let cube = objects.get_mut("cube").unwrap();
            // and get current camera unifrom data
            let camera_data = camera.update_view_projection_and_return(renderer).unwrap();
            // and prepare the data for our graphics
            custom_rendering.prepare(cube, renderer, &mut egui_plugin.renderer, camera_data);
            // ui function will provide the context
            egui_plugin.ui(
                |ctx| {
                    // This window will contain our graphics
                    egui::Window::new("title").resizable(true).show(ctx, |ui| {
                        // We make a canvas to paint our graphics
                        egui::Frame::canvas(ui.style()).show(ui, |ui| {
                            // Paint our graphics
                            custom_rendering.paint(ui);
                        });

                        // to allocate space that is available after resize
                        ui.allocate_space(ui.available_size());
                    });

                    // We can also do our other GUI stuff as always,
                    egui::Window::new("Pick Color")
                        .resizable(true)
                        .show(ctx, |ui| {
                            ui.horizontal(|ui| {
                                ui.label("Pick a color");
                                ui.color_edit_button_rgba_unmultiplied(&mut color);
                            });
                        });
                },
                &window,
            );

            // we can normally apply changes to our graphics
            cube.set_uniform_color(color[0], color[1], color[2], color[3])
                .unwrap();

            // and even other settings
            let camx = start.elapsed().unwrap().as_secs_f32().sin() * radius;
            let camy = start.elapsed().unwrap().as_secs_f32().sin() * radius;
            let camz = start.elapsed().unwrap().as_secs_f32().cos() * radius;
            camera
                .set_position(camx, camy, camz)
                .expect("Couldn't update the camera eye");
        })
        .expect("Error during update loop");
}

Trait Implementations§

source§

impl EnginePlugin for EGUI

source§

fn update_events( &mut self, _renderer: &mut Renderer, _window: &Win, _objects: &mut ObjectStorage, _events: &Event<'_, ()>, _input: &InputHelper, _camera: &mut Camera )

updates the inputs and events

source§

fn update( &mut self, renderer: &mut Renderer, window: &Window, _objects: &mut ObjectStorage, _camera: &mut Camera, _input: &InputHelper, encoder: &mut CommandEncoder, view: &TextureView )

ran after an update loop code is done on each frame

Auto Trait Implementations§

§

impl !RefUnwindSafe for EGUI

§

impl Send for EGUI

§

impl !Sync for EGUI

§

impl Unpin for EGUI

§

impl !UnwindSafe for EGUI

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Any for Twhere T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

§

fn type_name(&self) -> &'static str

source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WasmNotSend for Twhere T: Send,