pub struct Border<V: View + ViewSize> {
pub child: V,
pub title: Option<String>,
pub padding: BorderPadding,
pub chars: BorderChars,
pub foreground_colour: Colour,
pub background_colour: Colour,
pub title_colour: Colour,
pub bold_title: bool,
pub underline_title: bool,
pub bold_border: bool,
}Expand description
Decorate another element with a border.
The child element must implement View and ViewSize,
and can be accessed via the child field.
It’s possible to give the border a title, in which case
the text appears in the top-left corner.
Fields§
§child: V§title: Option<String>§padding: BorderPadding§chars: BorderChars§foreground_colour: Colour§background_colour: Colour§title_colour: Colour§bold_title: bool§underline_title: bool§bold_border: boolImplementations§
Source§impl<V: View + ViewSize> Border<V>
impl<V: View + ViewSize> Border<V>
Sourcepub fn new(child: V) -> Self
pub fn new(child: V) -> Self
Examples found in repository?
examples/tetris.rs (line 379)
376 fn new(width: u16, height: u16) -> Self {
377 let context = Context::new().unwrap();
378 let mut model = Model {
379 game_canvas: Border::new(Canvas::new((width, height))),
380 piece_canvas: Border::new(Canvas::new((6, 4))),
381 };
382
383 model.piece_canvas.title = Some("next".to_string());
384 model.piece_canvas.foreground_colour = BORDER_COLOUR;
385 model.piece_canvas.background_colour = BORDER_BACKGROUND;
386 model.game_canvas.foreground_colour = BORDER_COLOUR;
387 model.game_canvas.background_colour = BORDER_BACKGROUND;
388
389 Self {
390 context,
391 model,
392 }
393 }
394 fn display_end_text(&mut self) {
395 self.context.render(&RichText::one_line(
396 vec![("YOU DIED", TextInfo::default().bold().foreground_colour(colours::RED))])).unwrap();
397 }
398 fn render(&mut self, game: &Game) {
399 game.render(&mut self.model.game_canvas.child);
400 game.render_next(&mut self.model.piece_canvas.child);
401 self.context.render(&self.model).unwrap();
402 }
403 fn main_menu(&mut self) -> MainMenuChoice {
404 let mut menu = Border::new(MenuInstance::new(Menu::smallest(vec![
405 ("Play", MainMenuChoice::Play),
406 ("Quit", MainMenuChoice::Quit),
407 ])).unwrap());
408
409 match self.context.run_menu(&mut menu, |b| &mut b.child).unwrap() {
410 MenuChoice::Finalise(x) => x,
411 _ => MainMenuChoice::Quit,
412 }
413 }More examples
examples/menu.rs (line 25)
13fn main() {
14 let mut ctx = Context::new().unwrap();
15
16 let mut menu = Menu::new(vec![
17 ("One", 1),
18 ("Two", 2),
19 ("Three", 3),
20 ("Four", 4),
21 ], (6, 4));
22
23 menu.selected_info.foreground_colour = colours::RED;
24
25 let mut menu_instance = Border::new(MenuInstance::new(menu).unwrap());
26
27 let choice = loop {
28 match ctx.run_menu(&mut menu_instance, |v| &mut v.child).unwrap() {
29 MenuChoice::Quit => return,
30 MenuChoice::Cancel => break None,
31 MenuChoice::Finalise(x) => break Some(x),
32 }
33 };
34
35 if let Some(x) = choice {
36 ctx.render(&Text::one_line(format!("You chose: {}", x))).unwrap();
37 } else {
38 ctx.render(&Text::one_line("You chose nothing!")).unwrap();
39 }
40
41 thread::sleep(Duration::from_millis(1000));
42}examples/border.rs (line 33)
29fn main() {
30 let mut context = Context::new().unwrap();
31
32 let mut app = App {
33 a: Border::new(Text::new("abcdefghijklmnopqrstuvwxyz", (5, 5))),
34 b: Border::with_title(Text::new("abcdefghijklmnopqrstuvwxyz", (5, 5)), "Foo"),
35 };
36
37 app.b.title_colour = colours::DARK_GREY;
38 app.b.foreground_colour = colours::RED;
39 app.b.background_colour = colours::BLUE;
40
41 app.a.bold_border = true;
42 app.b.bold_title = true;
43
44 app.a.chars.top_left = '#';
45 app.a.chars.bottom_left = '#';
46 app.a.chars.top_right = '#';
47 app.a.chars.bottom_right = '#';
48 app.a.chars.left = '#';
49 app.a.chars.right = '#';
50 app.a.chars.top = '#';
51 app.a.chars.bottom = '#';
52
53 app.a.padding.top = 1;
54 app.a.padding.left = 2;
55 app.a.padding.right = 2;
56 app.a.padding.bottom = 4;
57
58 let mut app = Border::with_title(app, "Hello, World!");
59 app.underline_title = true;
60
61 context.render(&app).unwrap();
62 context.wait_input().unwrap();
63}Sourcepub fn with_title<S: Into<String>>(child: V, title: S) -> Self
pub fn with_title<S: Into<String>>(child: V, title: S) -> Self
Examples found in repository?
examples/border.rs (line 34)
29fn main() {
30 let mut context = Context::new().unwrap();
31
32 let mut app = App {
33 a: Border::new(Text::new("abcdefghijklmnopqrstuvwxyz", (5, 5))),
34 b: Border::with_title(Text::new("abcdefghijklmnopqrstuvwxyz", (5, 5)), "Foo"),
35 };
36
37 app.b.title_colour = colours::DARK_GREY;
38 app.b.foreground_colour = colours::RED;
39 app.b.background_colour = colours::BLUE;
40
41 app.a.bold_border = true;
42 app.b.bold_title = true;
43
44 app.a.chars.top_left = '#';
45 app.a.chars.bottom_left = '#';
46 app.a.chars.top_right = '#';
47 app.a.chars.bottom_right = '#';
48 app.a.chars.left = '#';
49 app.a.chars.right = '#';
50 app.a.chars.top = '#';
51 app.a.chars.bottom = '#';
52
53 app.a.padding.top = 1;
54 app.a.padding.left = 2;
55 app.a.padding.right = 2;
56 app.a.padding.bottom = 4;
57
58 let mut app = Border::with_title(app, "Hello, World!");
59 app.underline_title = true;
60
61 context.render(&app).unwrap();
62 context.wait_input().unwrap();
63}Trait Implementations§
Source§impl<'de, V> Deserialize<'de> for Border<V>
impl<'de, V> Deserialize<'de> for Border<V>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<V: View + ViewSize> View for Border<V>
impl<V: View + ViewSize> View for Border<V>
Source§fn view<G: ViewGrid>(&self, offset: Vector2<i16>, depth: i16, grid: &mut G)
fn view<G: ViewGrid>(&self, offset: Vector2<i16>, depth: i16, grid: &mut G)
Update the cells in
grid to describe how a type should be rendered.
Implementations of view for low level ui components will typically
involve updating cells directly. Implementations for higer level
components, such as an entire application’s ui, will typically call
the view methed of lower level components which make up the ui.Auto Trait Implementations§
impl<V> Freeze for Border<V>where
V: Freeze,
impl<V> RefUnwindSafe for Border<V>where
V: RefUnwindSafe,
impl<V> Send for Border<V>where
V: Send,
impl<V> Sync for Border<V>where
V: Sync,
impl<V> Unpin for Border<V>where
V: Unpin,
impl<V> UnwindSafe for Border<V>where
V: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more