pub struct StatefulImage { /* private fields */ }Expand description
Resizeable image widget that uses a StatefulProtocol state.
This stateful widget reacts to area resizes and resizes its image data accordingly.
struct App {
image_state: StatefulProtocol,
}
fn ui(f: &mut Frame<'_>, app: &mut App) {
let image = StatefulImage::default().resize(Resize::Crop(None));
f.render_stateful_widget(
image,
f.area(),
&mut app.image_state,
);
}Implementations§
Source§impl StatefulImage
impl StatefulImage
Sourcepub const fn resize(self, resize: Resize) -> Self
pub const fn resize(self, resize: Resize) -> Self
Examples found in repository?
examples/demo/main.rs (line 211)
199 fn render_resized_image(&mut self, f: &mut Frame<'_>, resize: Resize, area: Rect) {
200 let (state, name, color) = match resize {
201 Resize::Fit(_) => (&mut self.image_fit_state, "Fit", Color::Magenta),
202 Resize::Crop(_) => (&mut self.image_crop_state, "Crop", Color::Green),
203 Resize::Scale(_) => (&mut self.image_scale_state, "Scale", Color::Blue),
204 };
205 let block = block(name);
206 let inner_area = block.inner(area);
207 f.render_widget(paragraph(self.background.as_str().bg(color)), inner_area);
208 match self.show_images {
209 ShowImages::Fixed => (),
210 _ => {
211 let image = StatefulImage::default().resize(resize);
212 f.render_stateful_widget(image, inner_area, state);
213 }
214 };
215 f.render_widget(block, area);
216 }pub const fn new() -> Self
Trait Implementations§
Source§impl Default for StatefulImage
impl Default for StatefulImage
Source§fn default() -> StatefulImage
fn default() -> StatefulImage
Returns the “default value” for a type. Read more
Source§impl StatefulWidget for StatefulImage
impl StatefulWidget for StatefulImage
Auto Trait Implementations§
impl Freeze for StatefulImage
impl RefUnwindSafe for StatefulImage
impl Send for StatefulImage
impl Sync for StatefulImage
impl Unpin for StatefulImage
impl UnwindSafe for StatefulImage
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().