pub struct Console { /* private fields */ }
Expand description
This contains the data for a console (including the one displayed on the screen) and methods to draw on it.
Implementations
sourceimpl Console
impl Console
sourcepub fn new(width: u32, height: u32) -> Self
pub fn new(width: u32, height: u32) -> Self
create a new offscreen console that you can blit on another console width and height are in cells (characters), not pixels.
sourcepub fn register_color(&mut self, name: &str, value: Color)
pub fn register_color(&mut self, name: &str, value: Color)
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<Color>
pub fn borrow_foreground(&self) -> &Vec<Color>
for fast reading of the characters colors
sourcepub fn borrow_background(&self) -> &Vec<Color>
pub fn borrow_background(&self) -> &Vec<Color>
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<Color>
pub fn borrow_mut_foreground(&mut self) -> &mut Vec<Color>
for fast writing of the characters colors
sourcepub fn borrow_mut_background(&mut self) -> &mut Vec<Color>
pub fn borrow_mut_background(&mut self) -> &mut Vec<Color>
for fast writing of the background colors
sourcepub fn get_back(&self, x: i32, y: i32) -> Option<Color>
pub fn get_back(&self, x: i32, y: i32) -> Option<Color>
get the background color of a cell (if x,y inside the console)
sourcepub fn get_fore(&self, x: i32, y: i32) -> Option<Color>
pub fn get_fore(&self, x: i32, y: i32) -> Option<Color>
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) -> Color
pub fn unsafe_get_back(&self, x: i32, y: i32) -> Color
get the background color of a cell (no boundary check)
sourcepub fn unsafe_get_fore(&self, x: i32, y: i32) -> Color
pub fn unsafe_get_fore(&self, x: i32, y: i32) -> Color
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: Color)
pub fn fore(&mut self, x: i32, y: i32, col: Color)
set the character color at a specific position
sourcepub fn back(&mut self, x: i32, y: i32, col: Color)
pub fn back(&mut self, x: i32, y: i32, col: Color)
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: Color)
pub fn unsafe_fore(&mut self, x: i32, y: i32, col: Color)
set the character color at a specific position (no boundary check)
sourcepub fn unsafe_back(&mut self, x: i32, y: i32, col: Color)
pub fn unsafe_back(&mut self, x: i32, y: i32, col: Color)
set the background color at a specific position (no boundary check)
sourcepub fn clear(
&mut self,
fore: Option<Color>,
back: Option<Color>,
fillchar: Option<u16>
)
pub fn clear(
&mut self,
fore: Option<Color>,
back: Option<Color>,
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<Color>
)
pub fn print_color(
&mut self,
x: i32,
y: i32,
text: &str,
align: TextAlign,
back: Option<Color>
)
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 text_color_len(text: &str) -> usize
pub fn text_color_len(text: &str) -> usize
compute the length of a string containing color codes. Example :
use doryen_rs::Console;
let len = Console::text_color_len("#[red]red text with a #[blue]blue#[] word");
assert_eq!(len, 25); // actual string : "red text with a blue word"
let len = Console::text_color_len("#[red]a\nb");
assert_eq!(len, 3); // actual string : "a\nb"
let len = Console::text_color_len("normal string");
assert_eq!(len, 13);
sourcepub fn print(
&mut self,
x: i32,
y: i32,
text: &str,
align: TextAlign,
fore: Option<Color>,
back: Option<Color>
)
pub fn print(
&mut self,
x: i32,
y: i32,
text: &str,
align: TextAlign,
fore: Option<Color>,
back: Option<Color>
)
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<Color>,
back: Option<Color>,
fill: Option<u16>
)
pub fn rectangle(
&mut self,
x: i32,
y: i32,
w: u32,
h: u32,
fore: Option<Color>,
back: Option<Color>,
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<Color>,
back: Option<Color>,
fillchar: Option<u16>
)
pub fn area(
&mut self,
x: i32,
y: i32,
w: u32,
h: u32,
fore: Option<Color>,
back: Option<Color>,
fillchar: Option<u16>
)
fill an area with values
sourcepub fn cell(
&mut self,
x: i32,
y: i32,
ascii: Option<u16>,
fore: Option<Color>,
back: Option<Color>
)
pub fn cell(
&mut self,
x: i32,
y: i32,
ascii: Option<u16>,
fore: Option<Color>,
back: Option<Color>
)
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<Color>
)
pub fn blit(
&self,
x: i32,
y: i32,
destination: &mut Console,
fore_alpha: f32,
back_alpha: f32,
key_color: Option<Color>
)
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.