ConsoleExtender

Struct ConsoleExtender 

Source
pub struct ConsoleExtender<'b> { /* private fields */ }
Expand description

Extends the Console from doryen-rs.

Replaces most instances of x/y and w/h with Position and USize respectively, and makes use of doryen-extra‘s Color type rather than doryen-rs’. Since the ConsoleExtender derefs to Console, it lets you both use the replaced/extended methods and the underlying methods that were not replaced with ease.

Implementations§

Source§

impl<'b> ConsoleExtender<'b>

Source

pub fn extend(console: &'b mut Console) -> Self

Wraps the mutably borrowed console.

Source

pub fn new(size: USize) -> Self

Creates a new offscreen console that you can blit on another console. Size is in cells (characters), not pixels.

Source

pub fn wrap(console: Console) -> Self

Wraps the owned console.

Source§

impl ConsoleExtender<'_>

Source

pub fn resize(&mut self, size: USize)

Resizes the console.

Source

pub fn register_color<S: AsRef<str>>(&mut self, name: S, value: Color)

Associates a name with a color for this console.

Source

pub fn back(&self, position: Position) -> Option<Color>

Gets the background color of a cell.

Source

pub fn fore(&self, position: Position) -> Option<Color>

Gets the foreground color of a cell.

Source

pub fn ascii(&self, position: Position) -> Option<u16>

Gets the ASCII code of a cell.

Source

pub fn back_unchecked(&self, position: Position) -> Color

Gets the background color of a cell with no boundary check.

Source

pub fn fore_unchecked(&self, position: Position) -> Color

Gets the foreground color of a cell with no boundary check.

Source

pub fn ascii_unchecked(&self, position: Position) -> u16

Gets the ASCII code of a cell with no boundary check.

Source

pub fn set_ascii(&mut self, position: Position, ascii: u16)

Sets the character at a specific position.

Source

pub fn set_fore(&mut self, position: Position, color: Color)

Sets the character color at a specific position.

Source

pub fn set_back(&mut self, position: Position, color: Color)

Sets the background color at a specific position.

Source

pub fn set_ascii_unchecked(&mut self, position: Position, ascii: u16)

Sets the character at a specific position with no boundary check.

Source

pub fn set_fore_unchecked(&mut self, position: Position, color: Color)

Sets the character color at a specific position with no boundary check.

Source

pub fn set_back_unchecked(&mut self, position: Position, color: Color)

Sets the background color at a specific position with no boundary check

Source

pub fn clear( &mut self, fore: Option<Color>, back: Option<Color>, fill_char: Option<u16>, )

Fills the whole console with values

Source

pub fn print_color<S: AsRef<str>>( &mut self, position: Position, text: S, align: TextAlign, back: Option<Color>, )

Writes a multi-color string. Foreground color is defined by #[color_name] patterns inside the string.

Source

pub fn text_color_len<S: AsRef<str>>(text: S) -> usize

Compute the length of a string containing color codes.

Source

pub fn print<S: AsRef<str>>( &mut self, position: Position, text: S, align: TextAlign, fore: Option<Color>, back: Option<Color>, )

Writes a string. If the string reaches the border of the console, it’s truncated. If the string contains carriage return "\n", multiple lines are printed.

Source

pub fn rectangle( &mut self, rectangle: Rectangle, fore: Option<Color>, back: Option<Color>, fill_char: Option<u16>, )

Draws a rectangle, possibly filling it with a character.

Source

pub fn area( &mut self, rectangle: Rectangle, fore: Option<Color>, back: Option<Color>, fill_char: Option<u16>, )

Fills an area with values.

Source

pub fn cell( &mut self, position: Position, ascii: Option<u16>, fore: Option<Color>, back: Option<Color>, )

Changes all the properties of a console cell at once.

Source

pub fn blit( &self, position: Position, destination: &mut Console, fore_alpha: f32, back_alpha: f32, key_color: Option<Color>, )

Blits (draw) a console onto another one.

Source

pub fn blit_ex( &self, source_rectangle: Rectangle, destination: &mut Console, destination_position: Position, fore_alpha: f32, back_alpha: f32, key_color: Option<Color>, )

Blits a region of this console onto another one.

Source§

impl ConsoleExtender<'_>

Source

pub fn get_size(&self) -> USize

Returns the size of the console.

Source

pub fn print_frame<S: AsRef<str>>( &mut self, rectangle: Rectangle, fore: Option<Color>, back: Option<Color>, fill: Option<u16>, title: Option<S>, )

Draws a rectangle, possibly filling it with a character, possibly with a title centered at the top.

Source

pub fn print_char( &mut self, position: Position, character: char, fore: Option<Color>, back: Option<Color>, )

Prints the provided character to the give position.

Methods from Deref<Target = Console>§

Source

pub fn resize(&mut self, width: u32, height: u32)

resizes the console

Source

pub fn register_color(&mut self, name: &str, value: (u8, u8, u8, u8))

associate a name with a color for this console. The color name can then be used in Console::print_color Example

use doryen_rs::{Console, TextAlign};
let mut con=Console::new(80,25);
con.register_color("pink", (255, 0, 255, 255));
con.print_color(5, 5, "This text contains a #[pink]pink#[] word", TextAlign::Left, None);
Source

pub fn get_width(&self) -> u32

Source

pub fn get_height(&self) -> u32

Source

pub fn get_size(&self) -> (u32, u32)

Source

pub fn get_pot_width(&self) -> u32

Source

pub fn get_pot_height(&self) -> u32

Source

pub fn borrow_ascii(&self) -> &Vec<u32>

for fast reading of the characters values

Source

pub fn borrow_foreground(&self) -> &Vec<(u8, u8, u8, u8)>

for fast reading of the characters colors

Source

pub fn borrow_background(&self) -> &Vec<(u8, u8, u8, u8)>

for fast reading of the background colors

Source

pub fn borrow_mut_ascii(&mut self) -> &mut Vec<u32>

for fast writing of the characters values

Source

pub fn borrow_mut_foreground(&mut self) -> &mut Vec<(u8, u8, u8, u8)>

for fast writing of the characters colors

Source

pub fn borrow_mut_background(&mut self) -> &mut Vec<(u8, u8, u8, u8)>

for fast writing of the background colors

Source

pub fn get_back(&self, x: i32, y: i32) -> Option<(u8, u8, u8, u8)>

get the background color of a cell (if x,y inside the console)

Source

pub fn get_fore(&self, x: i32, y: i32) -> Option<(u8, u8, u8, u8)>

get the foreground color of a cell (if x,y inside the console)

Source

pub fn get_ascii(&self, x: i32, y: i32) -> Option<u16>

get the ascii code of a cell (if x,y inside the console)

Source

pub fn unsafe_get_back(&self, x: i32, y: i32) -> (u8, u8, u8, u8)

get the background color of a cell (no boundary check)

Source

pub fn unsafe_get_fore(&self, x: i32, y: i32) -> (u8, u8, u8, u8)

get the foreground color of a cell (no boundary check)

Source

pub fn unsafe_get_ascii(&self, x: i32, y: i32) -> u16

get the ascii code of a cell (no boundary check)

Source

pub fn ascii(&mut self, x: i32, y: i32, ascii: u16)

set the character at a specific position (doesn’t change the color).

Since the glyph associated with an ascii code depends on the font you’re using, doryen-rs can’t provide constants for specific characters except for a few ones used internally.

More information about this here.

You can find some constants that work with most fonts in this file provided by Alex Mooney.

Source

pub fn fore(&mut self, x: i32, y: i32, col: (u8, u8, u8, u8))

set the character color at a specific position

Source

pub fn back(&mut self, x: i32, y: i32, col: (u8, u8, u8, u8))

set the background color at a specific position

Source

pub fn unsafe_ascii(&mut self, x: i32, y: i32, ascii: u16)

set the character at a specific position (no boundary check)

Source

pub fn unsafe_fore(&mut self, x: i32, y: i32, col: (u8, u8, u8, u8))

set the character color at a specific position (no boundary check)

Source

pub fn unsafe_back(&mut self, x: i32, y: i32, col: (u8, u8, u8, u8))

set the background color at a specific position (no boundary check)

Source

pub fn clear( &mut self, fore: Option<(u8, u8, u8, u8)>, back: Option<(u8, u8, u8, u8)>, fillchar: Option<u16>, )

fill the whole console with values

Source

pub fn print_color( &mut self, x: i32, y: i32, text: &str, align: TextAlign, back: Option<(u8, u8, u8, u8)>, )

write a multi-color string. Foreground color is defined by #[color_name] patterns inside the string. color_name must have been registered with Console::register_color before. Default foreground color is white, at the start of the string. When an unknown color name is used, the color goes back to its previous value. You can then use an empty name to end a color span. Example

use doryen_rs::{Console, TextAlign};
let mut con=Console::new(80,25);
con.register_color("pink", (255, 0, 255, 255));
con.register_color("blue", (0, 0, 255, 255));
con.print_color(5, 5, "#[blue]This blue text contains a #[pink]pink#[] word", TextAlign::Left, None);
Source

pub fn print( &mut self, x: i32, y: i32, text: &str, align: TextAlign, fore: Option<(u8, u8, u8, u8)>, back: Option<(u8, u8, u8, u8)>, )

write a string. If the string reaches the border of the console, it’s truncated. If the string contains carriage return "\n", multiple lines are printed.

Source

pub fn rectangle( &mut self, x: i32, y: i32, w: u32, h: u32, fore: Option<(u8, u8, u8, u8)>, back: Option<(u8, u8, u8, u8)>, fill: Option<u16>, )

draw a rectangle, possibly filling it with a character.

Source

pub fn area( &mut self, x: i32, y: i32, w: u32, h: u32, fore: Option<(u8, u8, u8, u8)>, back: Option<(u8, u8, u8, u8)>, fillchar: Option<u16>, )

fill an area with values

Source

pub fn cell( &mut self, x: i32, y: i32, ascii: Option<u16>, fore: Option<(u8, u8, u8, u8)>, back: Option<(u8, u8, u8, u8)>, )

can change all properties of a console cell at once

Source

pub fn blit( &self, x: i32, y: i32, destination: &mut Console, fore_alpha: f32, back_alpha: f32, key_color: Option<(u8, u8, u8, u8)>, )

blit (draw) a console onto another one You can use fore_alpha and back_alpha to blend this console with existing background on the destination. If you define a key color, the cells using this color as background will be ignored. This makes it possible to blit non rectangular zones.

Source

pub fn blit_ex( &self, xsrc: i32, ysrc: i32, wsrc: i32, hsrc: i32, destination: &mut Console, xdst: i32, ydst: i32, fore_alpha: f32, back_alpha: f32, key_color: Option<(u8, u8, u8, u8)>, )

blit a region of this console onto another one. see Console::blit

Trait Implementations§

Source§

impl AsMut<Console> for ConsoleExtender<'_>

Source§

fn as_mut(&mut self) -> &mut Console

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsRef<Console> for ConsoleExtender<'_>

Source§

fn as_ref(&self) -> &Console

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Borrow<Console> for ConsoleExtender<'_>

Source§

fn borrow(&self) -> &Console

Immutably borrows from an owned value. Read more
Source§

impl BorrowMut<Console> for ConsoleExtender<'_>

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl Deref for ConsoleExtender<'_>

Source§

type Target = Console

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for ConsoleExtender<'_>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

impl<'b> Freeze for ConsoleExtender<'b>

§

impl<'b> RefUnwindSafe for ConsoleExtender<'b>

§

impl<'b> Send for ConsoleExtender<'b>

§

impl<'b> Sync for ConsoleExtender<'b>

§

impl<'b> Unpin for ConsoleExtender<'b>

§

impl<'b> !UnwindSafe for ConsoleExtender<'b>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.