Trait Console

Source
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§

Source

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.

Source

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.

Source

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).

Source

fn width(&self) -> i32

Returns the width of the console in characters.

Source

fn height(&self) -> i32

Returns the height of the console in characters.

Source

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.

Source

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.

Source

fn set_default_foreground(&mut self, color: Color)

Sets the console’s default foreground color. This is used in several printing functions.

Source

fn get_char_background(&self, x: i32, y: i32) -> Color

Returns the background color of the cell at the specified coordinates.

Source

fn get_char_foreground(&self, x: i32, y: i32) -> Color

Returns the foreground color of the cell at the specified coordinates.

Source

fn get_background_flag(&self) -> BackgroundFlag

Returns the console’s current background flag. For a detailed explanation of the possible values, see BackgroundFlag.

Source

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.

Source

fn get_char(&self, x: i32, y: i32) -> char

Returns the ASCII value of the cell located at x, y

Source

fn set_char(&mut self, x: i32, y: i32, c: char)

Modifies the ASCII value of the cell located at x, y.

Source

fn set_char_background( &mut self, x: i32, y: i32, color: Color, background_flag: BackgroundFlag, )

Changes the background color of the specified cell

Source

fn set_char_foreground(&mut self, x: i32, y: i32, color: Color)

Changes the foreground color of the specified cell

Source

fn put_char( &mut self, x: i32, y: i32, glyph: char, background_flag: BackgroundFlag, )

This function modifies every property of the given cell:

  1. Updates its background color according to the console’s default and background_flag, see BackgroundFlag.
  2. Updates its foreground color based on the default color set in the console
  3. Sets its ASCII value to glyph
Source

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.

Source

fn clear(&mut self)

Clears the console with its default background color

Source

fn print<T>(&mut self, x: i32, y: i32, text: T)
where Self: Sized, T: AsRef<[u8]> + TcodString,

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 string
  • TextAlignment::Center: center character of the sting
  • TextAlignment::Right: rightmost character of the string
Source

fn print_rect<T>(&mut self, x: i32, y: i32, width: i32, height: i32, text: T)
where Self: Sized, T: AsRef<[u8]> + TcodString,

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.

Source

fn print_ex<T>( &mut self, x: i32, y: i32, background_flag: BackgroundFlag, alignment: TextAlignment, text: T, )
where Self: Sized, T: AsRef<[u8]> + TcodString,

Prints the text at the specified location with an explicit BackgroundFlag and TextAlignment.

Source

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,

Combines the functions of print_ex and print_rect

Source

fn get_height_rect<T>( &self, x: i32, y: i32, width: i32, height: i32, text: T, ) -> i32
where Self: Sized, T: AsRef<[u8]> + TcodString,

Compute the height of a wrapped text printed using print_rect or print_rect_ex.

Source

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).

Source

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.

Source

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.

Source

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>,

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.

Implementations on Foreign Types§

Source§

impl<'a, T: Console + ?Sized> Console for &'a T

Source§

impl<T: Console + ?Sized> Console for Box<T>

Implementors§