Module pix_engine::appstate
source · [−]Expand description
Trait for allowing PixEngine to drive your application.
Example
use pix_engine::prelude::*;
struct MyApp;
impl AppState for MyApp {
fn on_start(&mut self, s: &mut PixState) -> PixResult<()> {
// Setup App state. `PixState` contains engine specific state and
// utility functions for things like getting mouse coordinates,
// drawing shapes, etc.
s.background(220);
s.font_family(Font::NOTO)?;
s.font_size(16);
Ok(())
}
fn on_update(&mut self, s: &mut PixState) -> PixResult<()> {
// Main render loop. Called as often as possible, or based on `target frame rate`.
if s.mouse_pressed() {
s.fill(color!(0));
} else {
s.fill(color!(255));
}
let m = s.mouse_pos();
s.circle([m.x(), m.y(), 80])?;
Ok(())
}
fn on_stop(&mut self, s: &mut PixState) -> PixResult<()> {
// Teardown any state or resources before exiting.
Ok(())
}
}
fn main() -> PixResult<()> {
let mut engine = PixEngine::builder()
.with_dimensions(800, 600)
.with_title("MyApp")
.build()?;
let mut app = MyApp;
engine.run(&mut app)
}Traits
Trait for allowing the PixEngine to drive your application and send notification of events,
passing along a &mut PixState to allow interacting with the PixEngine.