Expand description
§Graphicility
A minimal, immediate-mode 2D drawing library designed for simplicity and ease of use.
Graphicility provides a higher-level interface around pixels and winit, offering a
logical pixel buffer that automatically handles scaling and DPI.
Allowing you to create simple graphical applications.
§Core Concepts
- FrameContext: The primary interface provided to your draw loop. It contains access to Graphics, Input, and timing data.
- Logical Resolution: You define a fixed “Virtual resolution” (e.g., 320x240). The library scales this to fit the physical window.
- Vec2: A flexible coordinate type. Most methods accept
impl Into<Vec2>, allowing you to pass(x, y)tuples directly. - Immediate Mode : You define the graphics and you see it immediately
§Some Examples
§Drawing
use graphicility::{Color };
fn main() {
/// Run is the main entry point of Graphicility.
/// It starts the Event loop and Initializes the Window.
graphicility::run(|ctx| {
let g = ctx.graphics(); // We are only gonna draw so lets get the graphics handle
g.clear(Color::WHITE) // Lets Clear our canvas at the start of the frame
g.pixel((5,5), Color::RED); // Draw a single pixel in cords x:5 y:5
// Draw a rectangle: (x, y), (width, height)
g.rect((20, 20), (50, 50), Color::BLUE);
// Draw some text too
g.text((20, 100), "drawing text", Color::WHITE);
});
}
§2 Dimensional Vectors
use graphicility::{Color, Vec2};
fn main() {
let point1 = Vec2::new(5,5); // Create a a new Vec2 using the `new` constructor.
let point2 = Vec2{x: 100, y: 100}; // We can also construct it manually.
graphicility::run(|ctx| {
let g = ctx.graphics(); // We are only gonna draw so lets get the graphics handle
g.line(point1, point2, Color::RED); // Let's draw a line between these 2 points
g.rect(point2, point2 + point1, Color::BLUE); // Let's draw a rectangle with the size of point1 + point2
});
}
§Getting Inputs
use graphicility::{Color, KeyCode};
fn main() {
graphicility::run(|ctx| {
let (g, input) = ctx.split(); // Split the context so we draw and read input without raging the barrow checker.
g.clear(Color::WHITE);
if input.key_pressed(KeyCode::Escape){ // Pressed only triggers once.
println!("Key Espace is pressed");
}
if input.key_down(KeyCode::KeyW){ // Down triggers continuesly
println!("Key w is down");
}
let mpos = input.mouse_pos(); // Returns the Mouse position
if let Some(pos) = mpos{ // Always check if the mouse position is None it returns None if the window is out of focus.
g.text(pos, format!("X:{}, Y:{}", pos.0,pos.1), Color::RED);
}
});
}
Check Out the Examples folder in the Github Repo for more!
Modules§
Structs§
- Color
- Simple rgb/rgba color structure
- Config
- Main Config of window
Contains logical and physical sizes
Logical size is your drawing canvas size Physical size is the actual window size on screen
Defaults to 1280x800 physical & 640&400 logical sizes - Frame
Context - Represents the data in the Frame
- Graphics
- This is the Main Drawing interface.
- Input
- This is the Main Window Input Interface.
- Rect
- A Typed Rectangle. Can be used for bounds checking
- Vec2
- Vec2 Represents a 2 Dimentional point.
(i32,i32) and (f32,f32) Tuples could be converted toVec2by usinginto.
Note : When usingintowith floating point numbers it gets casted into i32(using .floor) and loses precision
Enums§
- KeyCode
- Code representing the location of a physical key
- Mouse
Button - Describes a button of a mouse controller.