pub struct Image { /* private fields */ }Expand description
Shows an image. Without a size it takes the image’s own size in logical
pixels; with only a width (or height) it keeps the aspect ratio. With
crossfade, a new image dissolves over the one before it.
use ravenrs_core::ImageData;
use ravenrs_widgets::{Image, Ui};
let pixel = ImageData::from_rgba8(1, 1, vec![200, 80, 40, 255]).expect("one pixel");
let photo = Image::new(pixel).size(160.0, 90.0).crossfade(0.2).alt("A photo");
let mut ui = Ui::new(photo, ravenrs_style::Theme::raven_dark());
ui.update();Implementations§
Source§impl Image
impl Image
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, DecodeError>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, DecodeError>
Decodes PNG or JPEG bytes (e.g. from include_bytes!).
Sourcepub fn content_mode(self, mode: ContentMode) -> Self
pub fn content_mode(self, mode: ContentMode) -> Self
How the image fills its frame (Cover by default).
Sourcepub fn corner_radius(self, radius: f32) -> Self
pub fn corner_radius(self, radius: f32) -> Self
Corner radius in logical pixels (default 0).
Sourcepub fn stretch(self) -> Self
pub fn stretch(self) -> Self
Stretches across the parent stack (height follows the aspect ratio unless set).
Sourcepub fn alt(self, text: impl Into<String>) -> Self
pub fn alt(self, text: impl Into<String>) -> Self
Describes the image for screen readers. Images without it are treated as decoration and hidden from them.
Sourcepub fn opacity(self, opacity: f32) -> Self
pub fn opacity(self, opacity: f32) -> Self
Opacity, 0.0 (invisible) to 1.0 (opaque, the default).
Sourcepub fn crossfade(self, seconds: f64) -> Self
pub fn crossfade(self, seconds: f64) -> Self
When the image changes, dissolves from the old one to the new one over this many
seconds. It asks for frames only while that lasts, and with reduced motion the new
one simply appears. Pass a clone of the same ImageData while the picture is the
same: new data counts as a new image, even with the same pixels.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Image
impl RefUnwindSafe for Image
impl Send for Image
impl Sync for Image
impl Unpin for Image
impl UnsafeUnpin for Image
impl UnwindSafe for Image
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<V> ViewExt for Vwhere
V: View,
impl<V> ViewExt for Vwhere
V: View,
Source§fn padding(self, padding: impl Into<Insets>) -> Styled<Self>
fn padding(self, padding: impl Into<Insets>) -> Styled<Self>
Source§fn background(self, fill: impl Into<Fill>) -> Styled<Self>
fn background(self, fill: impl Into<Fill>) -> Styled<Self>
Source§fn frame(self, width: Option<f32>, height: Option<f32>) -> Styled<Self>
fn frame(self, width: Option<f32>, height: Option<f32>) -> Styled<Self>
None keeps the content size.