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