[−][src]Struct pushrod::core::main::Pushrod
This structure is returned when instantiating a new Pushrod main object.
It stores the OpenGL configuration that is desired for drawing, a list of references
to a managed set of PushrodWindow
objects, registered EventListener
s, and
PushrodEvent
objects that are pending dispatch.
The objects contained within this structure are used by the Pushrod
run loop, and
are not intended to be modified except through methods in the Pushrod
impl.
Methods
impl Pushrod
[src]
Pushrod implementation. Create a Pushrod::new( OpenGL )
object to create a new
main loop. Only one of these should be set for the entire application runtime.
Example usage:
// Define the version of OpenGL to use with the application let opengl = OpenGL::V3_2; // Create a new Pushrod object with the OpenGL version let prod: Pushrod = Pushrod::new(opengl); // Create a PushrodWindow container to store the PistonWindow let mut pushrod_window: PushrodWindow = PushrodWindow::new( WindowSettings::new("Pushrod Window", [640, 480]) .opengl(opengl) .build() .unwrap_or_else(|error| panic!("Failed to build PistonWindow: {}", error)), ); // Add the window to the managed stack. prod.add_window(pushrod_window); // Initiate the run loop. prod.run();
pub fn new(config: OpenGL) -> Self
[src]
Pushrod Object Constructor. Takes in a single OpenGL configuration type.
pub fn add_window(&self, window: PushrodWindow)
[src]
Adds a managed window to the stack. Changes the swap_buffers
flag to false
, as if
this were set to true
, the main draw loop would be extremely expensive.
pub fn add_event_listener_for_window(&self, listener: Box<dyn EventListener>)
[src]
Adds an event listener to the stack. This should be an implementation of the
PushrodEventListener
trait.
Example:
struct ExampleListener {} impl ExampleListener { fn new() -> Self { Self {} } fn handle_mouse_move(&self, point: &Point) { eprintln!("[Listener] X={} Y={}", point.x, point.y); } fn handle_mouse_down(&self, button: &MouseButton) { match button { MouseButton::Left => eprintln!("[Listener] Left mouse button pressed."), _ => eprintln!("[Listener] Other mouse button pressed."), } } fn handle_mouse_up(&self, button: &MouseButton) { match button { MouseButton::Left => eprintln!("[Listener] Left mouse button released."), _ => eprintln!("[Listener] Other mouse button released."), } } fn handle_mouse_scroll(&self, point: &Point) { eprintln!("[Listener] Scroll: X={} Y={}", point.x, point.y); } } impl EventListener for ExampleListener { fn handle_event(&self, event: &PushrodEvent) { match event { PushrodEvent::MouseEvent { point } => self.handle_mouse_move(&point), PushrodEvent::MouseDownEvent { button } => self.handle_mouse_down(&button), PushrodEvent::MouseUpEvent { button } => self.handle_mouse_up(&button), PushrodEvent::MouseScrollEvent { point } => self.handle_mouse_scroll(&point), } } } fn main() { // Create a new Pushrod object with the OpenGL version let prod: Pushrod = Pushrod::new(opengl); // Add the event listener to the run loop. prod.add_event_listener_for_window(Box::new(ExampleListener::new())); // Initiate the run loop. prod.run(); }
pub fn run(&self)
[src]
This is the main run loop that is called to process all UI events. This loop is responsible for handling events from the OS, converting them to workable objects, and passing them off to quick callback dispatchers.
The run loop handles events in the following order:
- Mouse events
- Movement events
- Button events
- Scroll button events
- Custom events are then dispatched to any registered event listeners
- Draw loop
- Draw only widgets whose states have become invalidated
- Swap display buffers if required
This event is handled window-by-window. Once a window has processed all of its pending events, the next window is then processed. No particular window takes precidence - any window that has events to process gets handled in order.
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> SetParameter for T
fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
T: Parameter<Self>,
T: Parameter<Self>,
Sets value
as a parameter of self
.