pub struct ImageEntry { /* private fields */ }Expand description
State of an ImageVar.
Implementations§
Source§impl ImageEntry
impl ImageEntry
Sourcepub fn new_loading() -> Self
pub fn new_loading() -> Self
Create a dummy image in the loading state.
This is the same as calling new_error with an empty error.
Sourcepub fn new_error(error: Txt) -> Self
pub fn new_error(error: Txt) -> Self
Create a dummy image in the error state.
If the error is empty the image is loading, not an error.
Sourcepub fn is_loading(&self) -> bool
pub fn is_loading(&self) -> bool
Returns true if the is still acquiring or decoding the image bytes.
Sourcepub fn is_loaded(&self) -> bool
pub fn is_loaded(&self) -> bool
If the image has finished loading ok or due to error.
The image variable may still update after
Sourcepub fn size(&self) -> PxSize
pub fn size(&self) -> PxSize
Pixel size of the image after it finishes loading.
Note that this value is set as soon as the header finishes decoding, but the pixels will
only be set after it the entire image decodes.
If the view-process implements progressive decoding you can use partial_size and partial_pixels
to use the partially decoded image top rows as it decodes.
Sourcepub fn partial_size(&self) -> Option<PxSize>
pub fn partial_size(&self) -> Option<PxSize>
Size of partial_pixels.
Can be different from size if the image is progressively decoding.
Sourcepub fn partial_kind(&self) -> Option<PartialImageKind>
pub fn partial_kind(&self) -> Option<PartialImageKind>
Kind of partial_pixels.
Sourcepub fn density(&self) -> Option<PxDensity2d>
pub fn density(&self) -> Option<PxDensity2d>
Returns the image pixel density metadata if the image is loaded and the metadata was retrieved.
Sourcepub fn original_color_type(&self) -> ColorType
pub fn original_color_type(&self) -> ColorType
Image color type before it was converted to BGRA8 or A8.
Sourcepub fn color_type(&self) -> ColorType
pub fn color_type(&self) -> ColorType
Gets A8 for masks and BGRA8 for others.
Sourcepub fn has_entries(&self) -> bool
pub fn has_entries(&self) -> bool
If entries is not empty.
Sourcepub fn entries(&self) -> Vec<ImageVar> ⓘ
pub fn entries(&self) -> Vec<ImageVar> ⓘ
Other images from the same container that are a child of this image.
Sourcepub fn flat_entries(&self) -> Var<Vec<(VarEq<ImageEntry>, usize)>>
pub fn flat_entries(&self) -> Var<Vec<(VarEq<ImageEntry>, usize)>>
All other images from the same container that are a descendant of this image.
The values are a tuple of each entry and the length of descendants entries that follow it.
The returned variable will update every time any entry descendant var updates.
Sourcepub fn entry_kind(&self) -> ImageEntryKind
pub fn entry_kind(&self) -> ImageEntryKind
Kind of image entry this image is in the source container.
Sourcepub fn entry_index(&self) -> usize
pub fn entry_index(&self) -> usize
Sort index of the image in the list of entries of the source container.
Sourcepub fn with_best_reduce<R>(
&self,
size: PxSize,
visit: impl FnOnce(&ImageEntry) -> R,
) -> Option<R>
pub fn with_best_reduce<R>( &self, size: PxSize, visit: impl FnOnce(&ImageEntry) -> R, ) -> Option<R>
Calls visit with the image or ImageEntryKind::Reduced entry that is nearest to size and greater or equal to it.
Does not call visit if none of the images are loaded, returns None in that case.
Sourcepub fn view_handle(&self) -> &ViewImageHandle
pub fn view_handle(&self) -> &ViewImageHandle
Connection to the image resource in the view-process.
Sourcepub fn layout_size(&self, ctx: &LayoutMetrics) -> PxSize
pub fn layout_size(&self, ctx: &LayoutMetrics) -> PxSize
Calculate an ideal layout size for the image.
The image is scaled considering the density and screen scale factor. If the
image has no density falls back to the screen_density in both dimensions.
Sourcepub fn calc_size(
&self,
ctx: &LayoutMetrics,
fallback_density: PxDensity2d,
ignore_image_density: bool,
) -> PxSize
pub fn calc_size( &self, ctx: &LayoutMetrics, fallback_density: PxDensity2d, ignore_image_density: bool, ) -> PxSize
Sourcepub fn pixels(&self) -> Option<IpcBytes>
pub fn pixels(&self) -> Option<IpcBytes>
Reference the decoded pre-multiplied BGRA8 pixel buffer or A8 if is_mask.
Sourcepub fn partial_pixels(&self) -> Option<IpcBytes>
pub fn partial_pixels(&self) -> Option<IpcBytes>
Reference the partially decoded pixels if the image is progressively decoding and has not finished decoding.
Format is BGRA8 for normal images or A8 if is_mask.
Sourcepub fn copy_pixels(&self, rect: PxRect) -> Option<(PxRect, IpcBytesMut)>
pub fn copy_pixels(&self, rect: PxRect) -> Option<(PxRect, IpcBytesMut)>
Copy the rect selection from pixels or partial_pixels.
The rect is in pixels, with the origin (0, 0) at the top-left of the image.
Returns the copied selection and the pixel buffer.
Note that the selection can change if rect is not fully contained by the image area.
Sourcepub async fn encode(&self, format: Txt) -> Result<IpcBytes, EncodeError>
pub async fn encode(&self, format: Txt) -> Result<IpcBytes, EncodeError>
Encode the image to the format.
Note that entries are ignored, only this image is encoded. Use encode_with_entries to encode
multiple images in the same container.
Sourcepub async fn encode_with_entries(
&self,
entries: &[(ImageEntry, ImageEntryKind)],
format: Txt,
) -> Result<IpcBytes, EncodeError>
pub async fn encode_with_entries( &self, entries: &[(ImageEntry, ImageEntryKind)], format: Txt, ) -> Result<IpcBytes, EncodeError>
Encode the images to the format.
This image is the first page followed by the entries in the given order.
Sourcepub async fn save(&self, path: impl Into<PathBuf>) -> Result<()>
pub async fn save(&self, path: impl Into<PathBuf>) -> Result<()>
Encode and write the image to path.
The image format is guessed from the file extension. Use save_with_format to specify the format.
Note that entries are ignored, only this image is encoded. Use save_with_entries to encode
multiple images in the same container.
Sourcepub async fn save_with_format(
&self,
format: impl Into<Txt>,
path: impl Into<PathBuf>,
) -> Result<()>
pub async fn save_with_format( &self, format: impl Into<Txt>, path: impl Into<PathBuf>, ) -> Result<()>
Encode and write the image to path.
The image is encoded to the format, the file extension can be anything.
Note that entries are ignored, only this image is encoded. Use save_with_entries to encode
multiple images in the same container.
Sourcepub async fn save_with_entries(
&self,
entries: &[(ImageEntry, ImageEntryKind)],
format: impl Into<Txt>,
path: impl Into<PathBuf>,
) -> Result<()>
pub async fn save_with_entries( &self, entries: &[(ImageEntry, ImageEntryKind)], format: impl Into<Txt>, path: impl Into<PathBuf>, ) -> Result<()>
Encode and write the image to path.
The image is encoded to the format, the file extension can be anything.
This image is the first page followed by the entries in the given order.
Sourcepub fn insert_entry(&mut self, entry: ImageVar)
pub fn insert_entry(&mut self, entry: ImageVar)
Trait Implementations§
Source§impl Clone for ImageEntry
impl Clone for ImageEntry
Source§fn clone(&self) -> ImageEntry
fn clone(&self) -> ImageEntry
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ImageEntry
impl Debug for ImageEntry
Source§impl Img for ImageEntry
impl Img for ImageEntry
Source§fn renderer_id(&self, renderer: &ViewRenderer) -> ImageTextureId
fn renderer_id(&self, renderer: &ViewRenderer) -> ImageTextureId
renderer namespace. Read moreSource§impl PartialEq for ImageEntry
impl PartialEq for ImageEntry
Auto Trait Implementations§
impl Freeze for ImageEntry
impl !RefUnwindSafe for ImageEntry
impl Send for ImageEntry
impl Sync for ImageEntry
impl !Unpin for ImageEntry
impl !UnwindSafe for ImageEntry
Blanket Implementations§
Source§impl<T> AnyVarValue for T
impl<T> AnyVarValue for T
Source§fn clone_boxed(&self) -> BoxAnyVarValue
fn clone_boxed(&self) -> BoxAnyVarValue
Source§fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
self and other are equal.Source§fn try_swap(&mut self, other: &mut (dyn AnyVarValue + 'static)) -> bool
fn try_swap(&mut self, other: &mut (dyn AnyVarValue + 'static)) -> bool
other if both are of the same type.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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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