Struct TextBox

Source
pub struct TextBox { /* private fields */ }
Expand description

TextBox struct definition.

Implementations§

Source§

impl TextBox

Source

pub fn new( x: u8, y: u8, width: u8, height: u8, border: u8, title: &str, text: &str, ) -> Option<TextBox>

Creates a new TextBox with the specified params.

§Example
let textbox = TextBox::new(
  1, 1,                                                 // (x, y) coordinates.
  15, 6,                                                // (width, height) box size.
  2,                                                    // border type.
  "DANGER",                                             // Box title.
  "Some children are playing with dangerous weapons."   // Box text.
).unwrap();

This will print out:

╔DANGER═════════╗
║Some children  ║
║are playing    ║
║with dangerous ║
║weapons.       ║
║               ║
║               ║
╚═══════════════╝

Note: Termion use one-based coordinates, this means that the first point is (1, 1) at upside left corner.

Examples found in repository?
examples/box_styles.rs (lines 9-15)
6fn main() {
7	clear_screen();
8
9	let box1 = TextBox::new(
10        30, 10,
11        15, 6,
12        2,
13        "Box 1",
14        "This box have a border type 2. A first level message, must be checked quickly."
15    ).unwrap();
16    let box2 = TextBox::new(
17        10, 10,
18        15, 6,
19        0,
20        "Box 2",
21        "This box have a border type 0. Normal boxed text for alingment."
22    ).unwrap();
23    let box3 = TextBox::new(
24        10, 2,
25        35, 6,
26        1,
27        "Box 3",
28        "This box have a border type 1. A second level message. \n You can create multiple boxes, just be careful with console window size."
29    ).unwrap();
30    let box4 = TextBox::new(
31        47, 2,
32        15, 14,
33        2,
34        "Box 4",
35        "If you want a new line inside a box you need to put it between spaces like \n this: ' \\n '. Formatter identifies this as a new line word, so it can be printed. \n \n Right?"
36    ).unwrap();
37
38	println!("{}{}{}{}", box1, box2, box3, box4);
39	
40	goto(1, 40);
41}

Trait Implementations§

Source§

impl Default for TextBox

Source§

fn default() -> TextBox

Returns the “default value” for a type. Read more
Source§

impl Display for TextBox

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Added easy fmt::Display to print a TextBox just with print! println!

Auto Trait Implementations§

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<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.