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
impl EGUI
sourcepub fn new(event_loop: &EventLoop<()>, renderer: &mut Renderer) -> Self
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
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");
}
sourcepub fn ui<F: FnOnce(&Context)>(&mut self, callback: F, window: &Win)
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
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
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
)
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
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
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
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
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
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.