pub struct StatefulProtocol { /* private fields */ }Expand description
A stateful resizing image protocol for the crate::StatefulImage widget.
The [create::thread::ThreadImage] widget also uses this, and is the reason why resizing is split from rendering.
Implementations§
Source§impl StatefulProtocol
impl StatefulProtocol
pub fn new( source: ImageSource, font_size: FontSize, protocol_type: StatefulProtocolType, ) -> Self
pub fn protocol_type(&self) -> &StatefulProtocolType
pub fn protocol_type_owned(self) -> StatefulProtocolType
Sourcepub fn last_encoding_result(&mut self) -> Option<Result<(), Errors>>
pub fn last_encoding_result(&mut self) -> Option<Result<(), Errors>>
This returns the latest Result returned when encoding, and none if there was no encoding since the last result read. It is encouraged but not required to handle it
pub fn background_color(&self) -> Rgba<u8>
Sourcepub fn resize_encode_render(
&mut self,
resize: &Resize,
area: Rect,
buf: &mut Buffer,
)
pub fn resize_encode_render( &mut self, resize: &Resize, area: Rect, buf: &mut Buffer, )
Resize and encode if necessary, and render immediately.
This blocks the UI thread but requires neither threads nor async.
Sourcepub fn needs_resize(&mut self, resize: &Resize, area: Rect) -> Option<Rect>
pub fn needs_resize(&mut self, resize: &Resize, area: Rect) -> Option<Rect>
Check if the current image state would need resizing (grow or shrink) for the given area.
This can be called by the UI thread to check if this StatefulProtocol should be sent off to some background thread/task to do the resizing and encoding, instead of rendering. The thread should then return the StatefulProtocol so that it can be rendered.protoco
Sourcepub fn resize_encode(&mut self, resize: &Resize, area: Rect)
pub fn resize_encode(&mut self, resize: &Resize, area: Rect)
Resize the image and encode it for rendering. The result should be stored statefully so that next call for the given area does not need to redo the work.
This can be done in a background thread, and the result is stored in this StatefulProtocol.
Sourcepub fn render(&mut self, area: Rect, buf: &mut Buffer)
pub fn render(&mut self, area: Rect, buf: &mut Buffer)
Render the currently resized and encoded data to the buffer.
pub fn size_for(&self, resize: &Resize, area: Rect) -> Rect
Auto Trait Implementations§
impl Freeze for StatefulProtocol
impl !RefUnwindSafe for StatefulProtocol
impl Send for StatefulProtocol
impl Sync for StatefulProtocol
impl Unpin for StatefulProtocol
impl !UnwindSafe for StatefulProtocol
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
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>
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>
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