This repository has been archived by the owner on Aug 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!(widgets/canvas): use spans for text of labels
- Loading branch information
Showing
4 changed files
with
71 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use tui::{ | ||
backend::TestBackend, | ||
buffer::Buffer, | ||
style::{Color, Style}, | ||
text::Span, | ||
widgets::canvas::Canvas, | ||
Terminal, | ||
}; | ||
|
||
#[test] | ||
fn widgets_canvas_draw_labels() { | ||
let backend = TestBackend::new(5, 5); | ||
let mut terminal = Terminal::new(backend).unwrap(); | ||
terminal | ||
.draw(|f| { | ||
let label = String::from("test"); | ||
let canvas = Canvas::default() | ||
.background_color(Color::Yellow) | ||
.x_bounds([0.0, 5.0]) | ||
.y_bounds([0.0, 5.0]) | ||
.paint(|ctx| { | ||
ctx.print( | ||
0.0, | ||
0.0, | ||
Span::styled(label.clone(), Style::default().fg(Color::Blue)), | ||
); | ||
}); | ||
f.render_widget(canvas, f.size()); | ||
}) | ||
.unwrap(); | ||
|
||
let mut expected = Buffer::with_lines(vec![" ", " ", " ", " ", "test "]); | ||
for row in 0..5 { | ||
for col in 0..5 { | ||
expected.get_mut(col, row).set_bg(Color::Yellow); | ||
} | ||
} | ||
for col in 0..4 { | ||
expected.get_mut(col, 4).set_fg(Color::Blue); | ||
} | ||
terminal.backend().assert_buffer(&expected) | ||
} |