pub struct Screen { /* private fields */ }
Expand description

Screen structure

A standalone structure that provides every drawing function that ConsoleEngine provides.

You can get the full content of the screen via the draw method.

Implementations§

source§

impl Screen

Basic Usage :

use console_engine::pixel;
use console_engine::screen::Screen;
use console_engine::Color;

fn main() {
    // create a screen of 20x11 characters
    let mut scr = screen::Screen::new(20,11);

    // draw some shapes and prints some text
    scr.rect(0,0, 19,10,pixel::pxl('#'));
    scr.fill_circle(5,5, 3, pixel::pxl_fg('*', Color::Blue));
    scr.print(11,4, "Hello,");
    scr.print(11,5, "World!");

    // print the screen to the terminal
    scr.draw();
}
source

pub fn new(width: u32, height: u32) -> Screen

Creates a new Screen object with the provided width and height.

source

pub fn new_empty(width: u32, height: u32) -> Screen

Creates a new empty Screen object with the provided widht and height Makes sure to clear or fill it before drawing anything

source

pub fn new_fill(width: u32, height: u32, pixel: Pixel) -> Screen

Creates a new Screen object with the provided width and height filled with a specific Pixel

source

pub fn from_vec(vec: Vec<Pixel>, width: u32, height: u32) -> Screen

Creates a new Screen object with the provided Vec structure fitting the width and height parameters. The Vec length must correspond to width*height

source

pub fn from_string( string: String, fg: Color, bg: Color, width: u32, height: u32 ) -> Screen

Creates a new Screen object with the provided String and colors fitting the width and height parameters. The String length must correspond to width*height

source

pub fn get_width(&self) -> u32

Get the screen width

source

pub fn get_height(&self) -> u32

Get the screen height

source

pub fn clear(&mut self)

Reset the screen to a blank state

source

pub fn fill(&mut self, pixel: Pixel)

Fill the entire screen to the given pixel

source

pub fn check_empty(&mut self) -> bool

checks whenever the screen is full of “zero” characters refresh internal “empty” value

source

pub fn is_empty(&self) -> bool

Returns a cached result of check_empty

source

pub fn print(&mut self, x: i32, y: i32, string: &str)

prints a string at the specified coordinates.
The string will be cropped if it reach the right border

usage:

screen.print(0, 0, "Hello, world!");
screen.print(0, 4, format!("Score: {}", score).as_str());
source

pub fn print_fbg(&mut self, x: i32, y: i32, string: &str, fg: Color, bg: Color)

prints a string at the specified coordinates with the specified foreground and background color
The string will be cropped if it reach the right border

usage:

use console_engine::Color;

// print "Hello, world" in blue on white background
screen.print(0, 0, "Hello, world!", Color::Blue, Color::White);
source

pub fn print_screen(&mut self, x: i32, y: i32, source: &Screen)

Prints another screen on specified coordinates. Useful when you want to manage several “subscreen”

usage:

use console_engine::pixel;
use console_engine::screen::Screen;

// create a new Screen struct and draw a square inside it
let mut my_square = Screen::new(8,8);
my_square.rect(0,0,7,7,pixel::pxl('#'));
my_square.print(1,1,"square");

// prints the square in the main window at a specific location
screen.print_screen(5,2, &my_square);
source

pub fn print_screen_alpha( &mut self, x: i32, y: i32, source: &Screen, alpha_character: char )

Prints another screen on specified coordinates, ignoring a specific character while printing Ignoring a character will behave like transparency

see print_screen for usage

source

pub fn h_line( &mut self, start_x: i32, start_y: i32, end_x: i32, character: Pixel )

Optimized horizontal line drawing Automatically called by line if needed

source

pub fn v_line( &mut self, start_x: i32, start_y: i32, end_y: i32, character: Pixel )

Optimized vertical line drawing Automatically called by line if needed

source

pub fn line( &mut self, start_x: i32, start_y: i32, end_x: i32, end_y: i32, character: Pixel )

draws a line of the provided character between two sets of coordinates
see: Bresenham’s line algorithm

Note : Your line can start or end out of bounds. These pixels won’t be drawn

usage:

use console_engine::pixel;
// ...
screen.line(0, 0, 9, 9, pixel::pxl('#'));
source

pub fn rect( &mut self, start_x: i32, start_y: i32, end_x: i32, end_y: i32, character: Pixel )

Draws a rectangle of the provided character between two sets of coordinates

usage:

use console_engine::pixel;
// ...
screen.rect(0, 0, 9, 9, pixel::pxl('#'));
source

pub fn rect_border( &mut self, start_x: i32, start_y: i32, end_x: i32, end_y: i32, rect_style: BorderStyle )

Draws a rectangle with custom borders of the provided between two sets of coordinates. Check the BorderStyle struct to learn how to use built-in or custom styles

usage:

use console_engine::rect_style::BorderStyle;
// ...
screen.rect_border(0, 0, 9, 9, BorderStyle::new_simple());
source

pub fn fill_rect( &mut self, start_x: i32, start_y: i32, end_x: i32, end_y: i32, character: Pixel )

Fill a rectangle of the provided character between two sets of coordinates

usage:

use console_engine::pixel;
// ...
screen.fill_rect(0, 0, 9, 9, pixel::pxl('#'));
source

pub fn circle(&mut self, x: i32, y: i32, radius: u32, character: Pixel)

Draws a circle of the provided character at an x and y position with a radius see: olcPixelGameEngine Repository

usage:

use console_engine::pixel;
// ...
screen.circle(10, 10, 4, pixel::pxl('#'));
source

pub fn fill_circle(&mut self, x: i32, y: i32, radius: u32, character: Pixel)

Fill a circle of the provided character at an x and y position with a radius see: olcPixelGameEngine Repository

usage:

use console_engine::pixel;
// ...
screen.fill_circle(10, 10, 4, pixel::pxl('#'));
source

pub fn triangle( &mut self, x1: i32, y1: i32, x2: i32, y2: i32, x3: i32, y3: i32, character: Pixel )

Draws a triangle of the provided character using three sets of coordinates

usage:

use console_engine::pixel;
// ...
screen.triangle(8,8, 4,6, 9,2, pixel::pxl('#'));
source

pub fn fill_triangle( &mut self, x1: i32, y1: i32, x2: i32, y2: i32, x3: i32, y3: i32, character: Pixel )

Fill a triangle of the provided character using three sets of coordinates see: rustyPixelGameEngine Repository

usage:

use console_engine::pixel;
// ...
screen.fill_triangle(8,8, 4,6, 9,2, pixel::pxl('#'));
source

pub fn scroll(&mut self, h_scroll: i32, v_scroll: i32, background: Pixel)

Scrolls the screen for a certain amount of characters vertically or horizontally Scrolling is a destructive process, the outer border will be filled with the background pixel.

Scrolling a positive value will move the screen characters to the left / top, freeing space to the right / bottom

Scrolling a negative value will move the screen characters to the right / bottom, freeing space to the left / top

usage :

use console_engine::pixel;

// fill the screen with characters
screen.fill(pixel::pxl('#'));
// free one space to the bottom
screen.scroll(0,1,pixel::pxl(' '));
// print something at this place
screen.print(0, height-1, "Hello, world!");
source

pub fn set_pxl(&mut self, x: i32, y: i32, character: Pixel)

sets the provided character in the specified coordinates out of bounds pixels will be ignored

usage:

use console_engine::pixel;
// ...
screen.set_pxl(3,8,pixel::pixel('o'));
source

pub fn get_pxl(&self, x: i32, y: i32) -> Result<Pixel, String>

Get the character stored at provided coordinates

usage:

if screen.get_pxl(3,8).unwrap().chr == 'o' {
    screen.print(0,0,"Found a 'o'");
}
source

pub fn resize(&mut self, new_width: u32, new_height: u32)

Resizes the screen to match the given width and height truncates the bottom and right side of the screen

usage:

screen.resize()
source

pub fn extract( &self, start_x: i32, start_y: i32, end_x: i32, end_y: i32, default: Pixel ) -> Screen

Extracts part of the current screen as a separate Screen object The original screen is not altered If the coordinates are out of bounds, they’ll be replace by the default pixel

usage:

use console_engine::pixel;
// extract a 3x2 screen from the screen variable and print it
let scr_chunk = screen.extract(10, 4, 12, 5, pixel::pxl(' '));
scr_chunk.draw();
source

pub fn draw(&self)

Draws the screen into the terminal Uses stdout as target

You should not use this function while a ConsoleEngine is running. You may want to use ConsoleEngine’s print_screen, print_screen_alpha or set_screen instead

Trait Implementations§

source§

impl Clone for Screen

source§

fn clone(&self) -> Screen

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.