pub trait Console: AsNative<TCOD_console_t> {
Show 28 methods
// Provided methods
fn get_alignment(&self) -> TextAlignment { ... }
fn set_alignment(&mut self, alignment: TextAlignment) { ... }
fn set_key_color(&mut self, color: Color) { ... }
fn width(&self) -> i32 { ... }
fn height(&self) -> i32 { ... }
fn get_default_background(&mut self) -> Color { ... }
fn set_default_background(&mut self, color: Color) { ... }
fn set_default_foreground(&mut self, color: Color) { ... }
fn get_char_background(&self, x: i32, y: i32) -> Color { ... }
fn get_char_foreground(&self, x: i32, y: i32) -> Color { ... }
fn get_background_flag(&self) -> BackgroundFlag { ... }
fn set_background_flag(&mut self, background_flag: BackgroundFlag) { ... }
fn get_char(&self, x: i32, y: i32) -> char { ... }
fn set_char(&mut self, x: i32, y: i32, c: char) { ... }
fn set_char_background(
&mut self,
x: i32,
y: i32,
color: Color,
background_flag: BackgroundFlag,
) { ... }
fn set_char_foreground(&mut self, x: i32, y: i32, color: Color) { ... }
fn put_char(
&mut self,
x: i32,
y: i32,
glyph: char,
background_flag: BackgroundFlag,
) { ... }
fn put_char_ex(
&mut self,
x: i32,
y: i32,
glyph: char,
foreground: Color,
background: Color,
) { ... }
fn clear(&mut self) { ... }
fn print<T>(&mut self, x: i32, y: i32, text: T)
where Self: Sized,
T: AsRef<[u8]> + TcodString { ... }
fn print_rect<T>(
&mut self,
x: i32,
y: i32,
width: i32,
height: i32,
text: T,
)
where Self: Sized,
T: AsRef<[u8]> + TcodString { ... }
fn print_ex<T>(
&mut self,
x: i32,
y: i32,
background_flag: BackgroundFlag,
alignment: TextAlignment,
text: T,
)
where Self: Sized,
T: AsRef<[u8]> + TcodString { ... }
fn print_rect_ex<T>(
&mut self,
x: i32,
y: i32,
width: i32,
height: i32,
background_flag: BackgroundFlag,
alignment: TextAlignment,
text: T,
)
where Self: Sized,
T: AsRef<[u8]> + TcodString { ... }
fn get_height_rect<T>(
&self,
x: i32,
y: i32,
width: i32,
height: i32,
text: T,
) -> i32
where Self: Sized,
T: AsRef<[u8]> + TcodString { ... }
fn rect(
&mut self,
x: i32,
y: i32,
width: i32,
height: i32,
clear: bool,
background_flag: BackgroundFlag,
) { ... }
fn horizontal_line(
&mut self,
x: i32,
y: i32,
length: i32,
background_flag: BackgroundFlag,
) { ... }
fn vertical_line(
&mut self,
x: i32,
y: i32,
length: i32,
background_flag: BackgroundFlag,
) { ... }
fn print_frame<T>(
&mut self,
x: i32,
y: i32,
width: i32,
height: i32,
clear: bool,
background_flag: BackgroundFlag,
title: Option<T>,
)
where Self: Sized,
T: AsRef<str> { ... }
}
Expand description
Defines the common functionality between Root
and Offscreen
consoles
§Examples
Printing text with explicit alignment:
use tcod::console::{Console, Root, BackgroundFlag, TextAlignment};
let mut root = Root::initializer().size(80, 50).init();
root.print_ex(1, 1, BackgroundFlag::None, TextAlignment::Left,
"Text aligned to left.");
root.print_ex(78, 1, BackgroundFlag::None, TextAlignment::Right,
"Text aligned to right.");
root.print_ex(40, 15, BackgroundFlag::None, TextAlignment::Center,
"And this bit of text is centered.");
root.print_ex(40, 19, BackgroundFlag::None, TextAlignment::Center,
"Press any key to quit.");
Provided Methods§
Sourcefn get_alignment(&self) -> TextAlignment
fn get_alignment(&self) -> TextAlignment
Returns the default text alignment for the Console
instance. For all the possible
text alignment options, see the documentation for
TextAlignment.
Sourcefn set_alignment(&mut self, alignment: TextAlignment)
fn set_alignment(&mut self, alignment: TextAlignment)
Sets the default text alignment for the console. For all the possible text alignment options, see the documentation for TextAlignment.
Sourcefn set_key_color(&mut self, color: Color)
fn set_key_color(&mut self, color: Color)
Sets a key color that will be ignored when blitting the contents of this console onto an other (essentially a transparent background color).
Sourcefn get_default_background(&mut self) -> Color
fn get_default_background(&mut self) -> Color
Return the console’s default background color. This is used in
several other methods, like: clear
, put_char
, etc.
Sourcefn set_default_background(&mut self, color: Color)
fn set_default_background(&mut self, color: Color)
Sets the console’s default background color. This is used in several other methods,
like: clear
, put_char
, etc.
Sourcefn set_default_foreground(&mut self, color: Color)
fn set_default_foreground(&mut self, color: Color)
Sets the console’s default foreground color. This is used in several printing functions.
Sourcefn get_char_background(&self, x: i32, y: i32) -> Color
fn get_char_background(&self, x: i32, y: i32) -> Color
Returns the background color of the cell at the specified coordinates.
Sourcefn get_char_foreground(&self, x: i32, y: i32) -> Color
fn get_char_foreground(&self, x: i32, y: i32) -> Color
Returns the foreground color of the cell at the specified coordinates.
Sourcefn get_background_flag(&self) -> BackgroundFlag
fn get_background_flag(&self) -> BackgroundFlag
Returns the console’s current background flag. For a detailed explanation of the possible values, see BackgroundFlag.
Sourcefn set_background_flag(&mut self, background_flag: BackgroundFlag)
fn set_background_flag(&mut self, background_flag: BackgroundFlag)
Sets the console’s current background flag. For a detailed explanation of the possible values, see BackgroundFlag.
Sourcefn set_char(&mut self, x: i32, y: i32, c: char)
fn set_char(&mut self, x: i32, y: i32, c: char)
Modifies the ASCII value of the cell located at x, y
.
Sourcefn set_char_background(
&mut self,
x: i32,
y: i32,
color: Color,
background_flag: BackgroundFlag,
)
fn set_char_background( &mut self, x: i32, y: i32, color: Color, background_flag: BackgroundFlag, )
Changes the background color of the specified cell
Sourcefn set_char_foreground(&mut self, x: i32, y: i32, color: Color)
fn set_char_foreground(&mut self, x: i32, y: i32, color: Color)
Changes the foreground color of the specified cell
Sourcefn put_char(
&mut self,
x: i32,
y: i32,
glyph: char,
background_flag: BackgroundFlag,
)
fn put_char( &mut self, x: i32, y: i32, glyph: char, background_flag: BackgroundFlag, )
This function modifies every property of the given cell:
- Updates its background color according to the console’s default and
background_flag
, see BackgroundFlag. - Updates its foreground color based on the default color set in the console
- Sets its ASCII value to
glyph
Sourcefn put_char_ex(
&mut self,
x: i32,
y: i32,
glyph: char,
foreground: Color,
background: Color,
)
fn put_char_ex( &mut self, x: i32, y: i32, glyph: char, foreground: Color, background: Color, )
Updates every propert of the given cell using explicit colors for the background and foreground.
Sourcefn print<T>(&mut self, x: i32, y: i32, text: T)
fn print<T>(&mut self, x: i32, y: i32, text: T)
Prints the text at the specified location. The position of the x
and y
coordinates depend on the TextAlignment set in the console:
TextAlignment::Left
: leftmost character of the stringTextAlignment::Center
: center character of the stingTextAlignment::Right
: rightmost character of the string
Sourcefn print_rect<T>(&mut self, x: i32, y: i32, width: i32, height: i32, text: T)
fn print_rect<T>(&mut self, x: i32, y: i32, width: i32, height: i32, text: T)
Prints the text at the specified location in a rectangular area with the dimensions: (width; height). If the text is longer than the width the newlines will be inserted.
Sourcefn print_ex<T>(
&mut self,
x: i32,
y: i32,
background_flag: BackgroundFlag,
alignment: TextAlignment,
text: T,
)
fn print_ex<T>( &mut self, x: i32, y: i32, background_flag: BackgroundFlag, alignment: TextAlignment, text: T, )
Prints the text at the specified location with an explicit BackgroundFlag and TextAlignment.
Sourcefn print_rect_ex<T>(
&mut self,
x: i32,
y: i32,
width: i32,
height: i32,
background_flag: BackgroundFlag,
alignment: TextAlignment,
text: T,
)
fn print_rect_ex<T>( &mut self, x: i32, y: i32, width: i32, height: i32, background_flag: BackgroundFlag, alignment: TextAlignment, text: T, )
Combines the functions of print_ex
and print_rect
Sourcefn get_height_rect<T>(
&self,
x: i32,
y: i32,
width: i32,
height: i32,
text: T,
) -> i32
fn get_height_rect<T>( &self, x: i32, y: i32, width: i32, height: i32, text: T, ) -> i32
Compute the height of a wrapped text printed using print_rect
or print_rect_ex
.
Sourcefn rect(
&mut self,
x: i32,
y: i32,
width: i32,
height: i32,
clear: bool,
background_flag: BackgroundFlag,
)
fn rect( &mut self, x: i32, y: i32, width: i32, height: i32, clear: bool, background_flag: BackgroundFlag, )
Fill a rectangle with the default background colour.
If clear
is true, set each cell’s character to space (ASCII 32).
Sourcefn horizontal_line(
&mut self,
x: i32,
y: i32,
length: i32,
background_flag: BackgroundFlag,
)
fn horizontal_line( &mut self, x: i32, y: i32, length: i32, background_flag: BackgroundFlag, )
Draw a horizontal line.
Uses tcod::chars::HLINE
(ASCII 196) as the line character and
console’s default background and foreground colours.
Sourcefn vertical_line(
&mut self,
x: i32,
y: i32,
length: i32,
background_flag: BackgroundFlag,
)
fn vertical_line( &mut self, x: i32, y: i32, length: i32, background_flag: BackgroundFlag, )
Draw a vertical line.
Uses tcod::chars::VLINE
(ASCII 179) as the line character and
console’s default background and foreground colours.
Sourcefn print_frame<T>(
&mut self,
x: i32,
y: i32,
width: i32,
height: i32,
clear: bool,
background_flag: BackgroundFlag,
title: Option<T>,
)
fn print_frame<T>( &mut self, x: i32, y: i32, width: i32, height: i32, clear: bool, background_flag: BackgroundFlag, title: Option<T>, )
Draw a window frame with an optional title.
Draws a rectangle (using the rect method) using the suplied background flag, then draws a rectangle with the console’s default foreground colour.
If the title
is specified, it will be printed on top of the rectangle
using inverted colours.