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>
impl<'b> ConsoleExtender<'b>
Source§impl ConsoleExtender<'_>
impl ConsoleExtender<'_>
Sourcepub fn register_color<S: AsRef<str>>(&mut self, name: S, value: Color)
pub fn register_color<S: AsRef<str>>(&mut self, name: S, value: Color)
Associates a name with a color for this console.
Sourcepub fn back_unchecked(&self, position: Position) -> Color
pub fn back_unchecked(&self, position: Position) -> Color
Gets the background color of a cell with no boundary check.
Sourcepub fn fore_unchecked(&self, position: Position) -> Color
pub fn fore_unchecked(&self, position: Position) -> Color
Gets the foreground color of a cell with no boundary check.
Sourcepub fn ascii_unchecked(&self, position: Position) -> u16
pub fn ascii_unchecked(&self, position: Position) -> u16
Gets the ASCII code of a cell with no boundary check.
Sourcepub fn set_ascii(&mut self, position: Position, ascii: u16)
pub fn set_ascii(&mut self, position: Position, ascii: u16)
Sets the character at a specific position.
Sourcepub fn set_fore(&mut self, position: Position, color: Color)
pub fn set_fore(&mut self, position: Position, color: Color)
Sets the character color at a specific position.
Sourcepub fn set_back(&mut self, position: Position, color: Color)
pub fn set_back(&mut self, position: Position, color: Color)
Sets the background color at a specific position.
Sourcepub fn set_ascii_unchecked(&mut self, position: Position, ascii: u16)
pub fn set_ascii_unchecked(&mut self, position: Position, ascii: u16)
Sets the character at a specific position with no boundary check.
Sourcepub fn set_fore_unchecked(&mut self, position: Position, color: Color)
pub fn set_fore_unchecked(&mut self, position: Position, color: Color)
Sets the character color at a specific position with no boundary check.
Sourcepub fn set_back_unchecked(&mut self, position: Position, color: Color)
pub fn set_back_unchecked(&mut self, position: Position, color: Color)
Sets the background color at a specific position with no boundary check
Sourcepub fn clear(
&mut self,
fore: Option<Color>,
back: Option<Color>,
fill_char: Option<u16>,
)
pub fn clear( &mut self, fore: Option<Color>, back: Option<Color>, fill_char: Option<u16>, )
Fills the whole console with values
Sourcepub fn print_color<S: AsRef<str>>(
&mut self,
position: Position,
text: S,
align: TextAlign,
back: Option<Color>,
)
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.
Sourcepub fn text_color_len<S: AsRef<str>>(text: S) -> usize
pub fn text_color_len<S: AsRef<str>>(text: S) -> usize
Compute the length of a string containing color codes.
Sourcepub fn print<S: AsRef<str>>(
&mut self,
position: Position,
text: S,
align: TextAlign,
fore: Option<Color>,
back: Option<Color>,
)
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.
Sourcepub fn rectangle(
&mut self,
rectangle: Rectangle,
fore: Option<Color>,
back: Option<Color>,
fill_char: Option<u16>,
)
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.
Sourcepub fn area(
&mut self,
rectangle: Rectangle,
fore: Option<Color>,
back: Option<Color>,
fill_char: Option<u16>,
)
pub fn area( &mut self, rectangle: Rectangle, fore: Option<Color>, back: Option<Color>, fill_char: Option<u16>, )
Fills an area with values.
Sourcepub fn cell(
&mut self,
position: Position,
ascii: Option<u16>,
fore: Option<Color>,
back: Option<Color>,
)
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.
Methods from Deref<Target = Console>§
Sourcepub fn register_color(&mut self, name: &str, value: (u8, u8, u8, u8))
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);pub fn get_width(&self) -> u32
pub fn get_height(&self) -> u32
pub fn get_size(&self) -> (u32, u32)
pub fn get_pot_width(&self) -> u32
pub fn get_pot_height(&self) -> u32
Sourcepub fn borrow_ascii(&self) -> &Vec<u32>
pub fn borrow_ascii(&self) -> &Vec<u32>
for fast reading of the characters values
Sourcepub fn borrow_foreground(&self) -> &Vec<(u8, u8, u8, u8)>
pub fn borrow_foreground(&self) -> &Vec<(u8, u8, u8, u8)>
for fast reading of the characters colors
Sourcepub fn borrow_background(&self) -> &Vec<(u8, u8, u8, u8)>
pub fn borrow_background(&self) -> &Vec<(u8, u8, u8, u8)>
for fast reading of the background colors
Sourcepub fn borrow_mut_ascii(&mut self) -> &mut Vec<u32>
pub fn borrow_mut_ascii(&mut self) -> &mut Vec<u32>
for fast writing of the characters values
Sourcepub fn borrow_mut_foreground(&mut self) -> &mut Vec<(u8, u8, u8, u8)>
pub fn borrow_mut_foreground(&mut self) -> &mut Vec<(u8, u8, u8, u8)>
for fast writing of the characters colors
Sourcepub fn borrow_mut_background(&mut self) -> &mut Vec<(u8, u8, u8, u8)>
pub fn borrow_mut_background(&mut self) -> &mut Vec<(u8, u8, u8, u8)>
for fast writing of the background colors
Sourcepub fn get_back(&self, x: i32, y: i32) -> Option<(u8, u8, u8, u8)>
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)
Sourcepub fn get_fore(&self, x: i32, y: i32) -> Option<(u8, u8, u8, u8)>
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)
Sourcepub fn get_ascii(&self, x: i32, y: i32) -> Option<u16>
pub fn get_ascii(&self, x: i32, y: i32) -> Option<u16>
get the ascii code of a cell (if x,y inside the console)
Sourcepub fn unsafe_get_back(&self, x: i32, y: i32) -> (u8, u8, u8, u8)
pub fn unsafe_get_back(&self, x: i32, y: i32) -> (u8, u8, u8, u8)
get the background color of a cell (no boundary check)
Sourcepub fn unsafe_get_fore(&self, x: i32, y: i32) -> (u8, u8, u8, u8)
pub fn unsafe_get_fore(&self, x: i32, y: i32) -> (u8, u8, u8, u8)
get the foreground color of a cell (no boundary check)
Sourcepub fn unsafe_get_ascii(&self, x: i32, y: i32) -> u16
pub fn unsafe_get_ascii(&self, x: i32, y: i32) -> u16
get the ascii code of a cell (no boundary check)
Sourcepub fn ascii(&mut self, x: i32, y: i32, ascii: u16)
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.
Sourcepub fn fore(&mut self, x: i32, y: i32, col: (u8, u8, u8, u8))
pub fn fore(&mut self, x: i32, y: i32, col: (u8, u8, u8, u8))
set the character color at a specific position
Sourcepub fn back(&mut self, x: i32, y: i32, col: (u8, u8, u8, u8))
pub fn back(&mut self, x: i32, y: i32, col: (u8, u8, u8, u8))
set the background color at a specific position
Sourcepub fn unsafe_ascii(&mut self, x: i32, y: i32, ascii: u16)
pub fn unsafe_ascii(&mut self, x: i32, y: i32, ascii: u16)
set the character at a specific position (no boundary check)
Sourcepub fn unsafe_fore(&mut self, x: i32, y: i32, col: (u8, u8, u8, u8))
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)
Sourcepub fn unsafe_back(&mut self, x: i32, y: i32, col: (u8, u8, u8, u8))
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)
Sourcepub fn clear(
&mut self,
fore: Option<(u8, u8, u8, u8)>,
back: Option<(u8, u8, u8, u8)>,
fillchar: Option<u16>,
)
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
Sourcepub fn print_color(
&mut self,
x: i32,
y: i32,
text: &str,
align: TextAlign,
back: Option<(u8, u8, u8, u8)>,
)
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);Sourcepub fn print(
&mut self,
x: i32,
y: i32,
text: &str,
align: TextAlign,
fore: Option<(u8, u8, u8, u8)>,
back: Option<(u8, u8, u8, u8)>,
)
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.
Sourcepub 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>,
)
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.
Sourcepub 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>,
)
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
Sourcepub fn cell(
&mut self,
x: i32,
y: i32,
ascii: Option<u16>,
fore: Option<(u8, u8, u8, u8)>,
back: Option<(u8, u8, u8, u8)>,
)
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
Sourcepub fn blit(
&self,
x: i32,
y: i32,
destination: &mut Console,
fore_alpha: f32,
back_alpha: f32,
key_color: Option<(u8, u8, u8, u8)>,
)
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.