| Crates.io | pixels-graphics-lib |
| lib.rs | pixels-graphics-lib |
| version | 0.20.2 |
| created_at | 2021-12-29 16:13:09.53992+00 |
| updated_at | 2024-10-01 07:42:17.324108+00 |
| description | Simple pixel graphics and GUI library |
| homepage | |
| repository | https://github.com/emmabritton/pixel-graphics-lib |
| max_upload_size | |
| id | 504906 |
| size | 453,587 |
Pixel buffer graphics and GUI library. It helps simplify window setup and creation, and event looping. It uses buffer graphics lib for drawing to the buffer.
In your Cargo.toml file add
pixels-graphics-lib = { version = "0.20.2", features = [] }
Inside features you MUST put one of these:
| Feature | Renderer | Window creation |
|---|---|---|
pixels |
Pixels | Winit v0.29 |
softbuffer |
Softbuffer | Winit v0.30 |
Both of these use rwh06
This will control how the window is created and managed and how the buffer is rendered to the screen. The main differences are when the window is scaled to a non integer value (1.2 opposed than 2.0) then pixels will draw your content in the middle of the window, whereas softbuffer will draw in the top left. Additionally, pixels uses hardware scaling and softbuffer uses software scaling.
You can use scenes using run_scenes (requires default feature scenes):
fn main() -> Result<()> {
// Window prefs allow the size and position of the window to be saved and restored
let window_prefs = WindowPreferences::new("com", "example", "app", 1)?;
// Options contains scaling, UPS, etc
let options = Options::default();
// The switcher is how new scenes are created
let switcher: SceneSwitcher<SceneResult, SceneName> =
|style, scene_stack, new_scene| match new_scene {
SceneName::Example => scene_stack.push(ExampleScene::new()),
};
let first_scene = ExampleScene::new();
run_scenes(
300,
300,
"Scenes Example",
Some(window_prefs),
switcher,
first_scene,
options,
empty_pre_post()
)?;
Ok(())
}
// The scene name is the id used so the switcher knows which one to create
#[derive(Clone, Debug, PartialEq)]
enum SceneName {
Example,
}
// After a scene is finished it can return values to it's parent using scene result
#[derive(Clone, Debug, PartialEq)]
enum SceneResult {}
struct ExampleScene {}
impl ExampleScene {
pub fn new() -> Box<Self> {
Box::new(Self {})
}
}
impl Scene<SceneResult, SceneName> for ExampleScene {
fn render(
&mut self,
graphics: &mut Graphics,
mouse_xy: Coord,
held_keys: &[KeyCode]) {
todo!()
}
fn update(
&mut self,
timing: &Timing,
mouse_xy: Coord,
held_keys: &[KeyCode],
) -> SceneUpdateResult<SceneResult, SceneName> {
todo!()
}
}
or a more low level with run
struct Example {}
fn main() -> Result<()> {
let system = Box::new(Example {});
run(240, 160, "Example", Box::new(system), Options::default())?;
Ok(())
}
//Check `src/scenes.rs` for examples of implementing held keys, etc
impl System for Example {
fn update(&mut self, timing: &Timing) {}
fn render(&mut self, graphics: &mut Graphics) {}
}
Default features:
window_prefs,sound,serde,scenes
window_prefsSave and restore window position and size
To use this the impl System must override System::window_prefs()
scenesEnables Scene and run_scenes
Includes window_prefs
controllerScene::update, Scene::rendercontroller_xinputAs above but using xinput, windows only
soundPlay music or sound effects
serdeAdds Serialize and Deserialize to most structs and enums
imagesLoading and displaying of PNGs, JPEGs, BMPs
file_dialogsBuilt in file selection dialogs, not recommended, use rfd
mintEnables buffer-graphics-lib/mint,
see Buffer graphics readme
notosanEnables buffer-graphics-lib/notosans,
see Buffer graphics readme
embeddedEnables buffer-graphics-lib/embedded,
see Buffer graphics readme
pixels_serde and softbuffer_serdeEnables serde for the winit crate being used by pixels or softbuffer
Each example must be run with a renderer (pixels or softbuffer), like this:
cargo run --example basic --features "pixels"
or
cargo run --example relative_test --features "softbuffer"
A few retro games
A wordle clone
Editor for IndexedImage, ICI files
GUI for USFX
Program used to create fonts for Buffer graphics