pub struct TextBox { /* private fields */ }
Expand description
TextBox struct definition.
Implementations§
Source§impl TextBox
impl TextBox
Sourcepub fn new(
x: u8,
y: u8,
width: u8,
height: u8,
border: u8,
title: &str,
text: &str,
) -> Option<TextBox>
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§
Auto Trait Implementations§
impl Freeze for TextBox
impl RefUnwindSafe for TextBox
impl Send for TextBox
impl Sync for TextBox
impl Unpin for TextBox
impl UnwindSafe for TextBox
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more