pub struct Image<'a> { /* private fields */ }Expand description
Fixed size image widget that uses Protocol.
The widget does not react to area resizes, and is not even guaranteed to not overdraw. Its advantage lies in that the Protocol needs only one initial resize.
struct App {
image_static: Protocol,
}
fn ui(f: &mut Frame<'_>, app: &mut App) {
let image = Image::new(&mut app.image_static);
f.render_widget(image, f.size());
}Implementations§
Source§impl<'a> Image<'a>
impl<'a> Image<'a>
Sourcepub fn new(image: &'a mut Protocol) -> Image<'a>
pub fn new(image: &'a mut Protocol) -> Image<'a>
Examples found in repository?
examples/screenshot.rs (line 93)
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
fn ui(f: &mut Frame<'_>, app: &mut App) {
let area = Rect::new(0, 0, SCREEN_SIZE.0, SCREEN_SIZE.1);
let block = Block::default()
.borders(Borders::ALL)
.title("Screenshot test");
f.render_widget(
Paragraph::new("PartiallyHiddenScreenshotParagraphBackground\n".repeat(10)),
block.inner(area),
);
let image = Image::new(&mut app.image);
f.render_widget(image, block.inner(area));
f.render_widget(block, area);
}More examples
examples/demo/main.rs (line 249)
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
fn ui(f: &mut Frame<'_>, app: &mut App) {
let outer_block = Block::default()
.borders(Borders::TOP)
.title(app.title.as_str());
let chunks = Layout::default()
.direction(Direction::Horizontal)
.constraints(
[
Constraint::Percentage(app.split_percent),
Constraint::Percentage(100 - app.split_percent),
]
.as_ref(),
)
.split(outer_block.inner(f.area()));
f.render_widget(outer_block, f.area());
let left_chunks = vertical_layout().split(chunks[0]);
let right_chunks = vertical_layout().split(chunks[1]);
let block_left_top = block("Fixed");
let area = block_left_top.inner(left_chunks[0]);
f.render_widget(
paragraph(app.background.as_str()).style(Color::Yellow),
area,
);
f.render_widget(block_left_top, left_chunks[0]);
match app.show_images {
ShowImages::Resized => {}
_ => {
let image = Image::new(&mut app.image_static);
// Let it be surrounded by styled text.
let offset_area = Rect {
x: area.x + 1,
y: area.y + 1,
width: area.width.saturating_sub(2),
height: area.height.saturating_sub(2),
};
f.render_widget(image, offset_area);
}
}
let chunks_left_bottom = Layout::default()
.direction(Direction::Horizontal)
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
.split(left_chunks[1]);
app.render_resized_image(f, Resize::Crop(None), chunks_left_bottom[0]);
app.render_resized_image(f, Resize::Scale(None), chunks_left_bottom[1]);
app.render_resized_image(f, Resize::Fit(None), right_chunks[0]);
let block_right_bottom = block("Help");
let area = block_right_bottom.inner(right_chunks[1]);
f.render_widget(
paragraph(vec![
Line::from("Key bindings:"),
Line::from("H/L: resize"),
Line::from(format!(
"i: cycle image protocols (current: {:?})",
app.picker.protocol_type()
)),
Line::from("o: cycle image"),
Line::from(format!("t: toggle ({:?})", app.show_images)),
Line::from(format!("Font size: {:?}", app.picker.font_size())),
]),
area,
);
f.render_widget(block_right_bottom, right_chunks[1]);
}Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Image<'a>
impl<'a> RefUnwindSafe for Image<'a>
impl<'a> Send for Image<'a>
impl<'a> Sync for Image<'a>
impl<'a> Unpin for Image<'a>
impl<'a> !UnwindSafe for Image<'a>
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