canrust 1.1.0

A Rust library drawing shapes onto a canvas
Documentation
//! This crate is a port of Tk's Canvas, written using SFML, aiming to provide simple and
//! tkinter-like syntax.
//!
//! # Example:
//!
//! ```no_run
//! use canrust::canvas::{Canvas, Color};
//! fn main() {
//!     // Create a canvas:
//!     // size, name, background color
//!     let mut canvas = Canvas::new((800, 600), "Canvas", Color::WHITE);
//!     
//!     // create shapes:
//!     // laser eyes go brrrrr
//!     canvas.create_circle((1., 1.), 20., Color::BLACK, None, None).unwrap();
//!     canvas.create_rectangle((20., 20.), (30., 80.), Color::BLACK, None, None).unwrap();
//!     canvas.create_line((18., 20.), (18., 80.), 2., Color::RED, None, None).unwrap();
//!     canvas.create_line((32., 20.), (32. 80.), 2., Color::RED, None, None).unwrap();
//!     
//!     // call the mainloop, objects will keep rendering as long as the program is running
//!     canvas.mainloop()
//! }
//! ```
//!
//! # Dependencies
//! - SFML 2.5
//! - CSFML 2.5
//!
//! # Installation
//!
//! Add this to your Cargo.toml file:
//!
//! ```toml
//! [dependencies]
//! canrust = "1.0.0"
//! ```
//! # Examples
//! Full examples can be found in the [`examples`] directory

pub mod canvas;
pub mod utils;

#[cfg(test)]
fn test_all() {
    use canvas::{Canvas, Color, Line, Text};
    use utils::{FontHandler, Image};

    let handler = FontHandler::find_fonts("SourceCodePro".to_string()).unwrap();
    let mut canvas = Canvas::new((800, 800), "ha".to_string(), Color::RED);
    let _ = canvas.create_from_text(&Text::new(
        Some("From Text"),
        20,
        Color::WHITE,
        (400., 500.),
    ));
    canvas
        .create_circle((15., 18.), 200., Color::BLUE, None, None)
        .unwrap();
    canvas
        .create_rectangle((1., 1.), (200., 200.), Color::CYAN, None, None)
        .unwrap();
    canvas
        .create_text((500., 500.), "Hello", 50, "Arial", Color::WHITE)
        .unwrap();

    let line = Line::new((200., 200.), (400., 400.), 12., Color::WHITE).unwrap();

    canvas.create_from_line(&line).unwrap();

    let image = Image::from_file(
        "~/programming/rust/canrust/1990_praisethesun.png",
        (80., 300.),
    )
    .unwrap();
    canvas.create_from_image(&image).unwrap();
    canvas.mainloop()
}

#[cfg(test)]
fn test_fonts() {
    use canvas::{Canvas, Color, Text};

    let mut canvas = Canvas::new((800, 600), "ha".to_string(), Color::WHITE);

    let mut text = Text::new(Some("This is a font test ha"), 50, Color::RED, (1., 1.));
    text.set_font("sourcecodepro".to_string()).unwrap();
    canvas.create_from_text(&text).unwrap();
    canvas.mainloop()
}
#[cfg(test)]
fn bind_test() {
    use canvas::{Canvas, Color};

    let mut canvas = Canvas::new((800, 800), "ha".to_string(), Color::WHITE);
    canvas
        .create_circle((1., 1.), 20., Color::BLACK, None, None)
        .unwrap();
    canvas
        .create_rectangle((20., 20.), (30., 80.), Color::BLACK, None, None)
        .unwrap();
    canvas
        .create_line((18., 20.), (18., 80.), 2., Color::RED, None, None)
        .unwrap();
    canvas
        .create_line((32., 20.), (32., 80.), 2., Color::RED, None, None)
        .unwrap();

    canvas.mainloop();
}
use canvas::Canvas;
#[cfg(test)]
fn hello(can: &mut Canvas) {
    use canvas::Color;
    println!("hello from hello");
    for i in 0..5 {
        let num = i as f32 * 10.;
        let ha = i as f32 * 20.;
        can.create_circle((56. + ha, 64. + ha), 10., Color::RED, None, None)
            .unwrap();
    }
}
#[cfg(test)]
#[test]
fn mouse_test() {
    use canvas::{Button, Canvas, Color};
    let mut canvas = Canvas::new((800, 800), "ha".to_string(), Color::BLACK);

    let mut button = Button::new("hello", (300., 300.), (200., 100.)).unwrap();
    button.bind(mouse).unwrap();
    button.set_fill_color(Color::RED).unwrap();
    button.set_style("circle").unwrap();

    canvas.create_from_button(&button).unwrap();
    let points = vec![(1., 1.), (200., 200.), (200., 300.)];
    canvas.create_polygon(points, Color::RED, None, None);
    canvas.mainloop()
}
#[cfg(test)]
fn mouse(_: &mut Canvas, _: (f32, f32)) {
    println!("hello from button")
}