pub struct Image { /* private fields */ }Expand description
Local image component. Layout uses logical pixels; raster resolution uses DPI and enclosing visual scale. The default preserves aspect.
Screen readers announce an image by its Image::alt text. One that only decorates
is marked Image::decorative and skipped; an image with neither is reported as
DiagnosticKind::MissingAccessibleName while assistive
technology is connected.
use zaxis::{Image, ImageFit, ImageSource, TextureFilter, vec2};
ui.image("assets/photo.jpg");
ui.add(Image::new("assets/photo.jpg").alt("Harbour at dusk"));
ui.add(Image::new("assets/icon.svg").size(vec2(96.0, 96.0)).corner_radius(12.0).decorative());
let pixels = ImageSource::rgba([2, 2], vec![255; 16]);
ui.add(Image::new(&pixels).size(vec2(64.0,64.0)).filter(TextureFilter::Nearest).fit(ImageFit::Cover));Implementations§
Source§impl Image
impl Image
pub fn new(source: impl Into<ImageSource>) -> Self
Sourcepub fn alt(self, text: impl Into<String>) -> Self
pub fn alt(self, text: impl Into<String>) -> Self
What the image shows, in words: the name screen readers announce. An empty text
marks the image Self::decorative.
Sourcepub fn decorative(self) -> Self
pub fn decorative(self) -> Self
The image adds nothing the text around it does not say: assistive technology skips
it. An Self::interactive image is a control and stays in the tree, so it still
needs Self::alt.
pub fn id_source(self, id: impl Hash) -> Self
pub fn size(self, size: Vec2) -> Self
pub fn max_size(self, size: Vec2) -> Self
Sourcepub fn aspect_ratio(self, ratio: f32) -> Self
pub fn aspect_ratio(self, ratio: f32) -> Self
Reserves space before intrinsic metadata arrives (width / height).
pub fn fit(self, fit: ImageFit) -> Self
pub fn tint(self, tint: Color) -> Self
pub fn opacity(self, opacity: f32) -> Self
pub fn corner_radius(self, radius: impl Into<CornerRadius>) -> Self
Sourcepub fn uv(self, uv: Rect) -> Self
pub fn uv(self, uv: Rect) -> Self
Normalized source crop, clipped to [0, 1]. Cover applies a further centered crop.
pub fn filter(self, filter: TextureFilter) -> Self
pub fn interactive(self, interactive: bool) -> Self
Sourcepub fn placeholder(self, placeholder: bool) -> Self
pub fn placeholder(self, placeholder: bool) -> Self
Suppress the default placeholder to paint application-specific loading/errors.
pub fn show(self, ui: &mut Ui<'_>) -> ImageOutput
Trait Implementations§
Source§impl Widget for Image
impl Widget for Image
fn ui(self, ui: &mut Ui<'_>) -> Response
Source§fn tooltip(self, text: impl Into<String>) -> TooltipWidget<Self>where
Self: Sized,
fn tooltip(self, text: impl Into<String>) -> TooltipWidget<Self>where
Self: Sized,
ui.add(Button::new("Save").tooltip("Write the file")).Response::menu_selected on the pass it is picked.Source§fn accessible_label(self, label: impl Into<String>) -> Accessible<Self>where
Self: Sized,
fn accessible_label(self, label: impl Into<String>) -> Accessible<Self>where
Self: Sized,
Source§fn accessible_description(
self,
description: impl Into<String>,
) -> Accessible<Self>where
Self: Sized,
fn accessible_description(
self,
description: impl Into<String>,
) -> Accessible<Self>where
Self: Sized,
Source§fn accessible_role(self, role: AccessRole) -> Accessible<Self>where
Self: Sized,
fn accessible_role(self, role: AccessRole) -> Accessible<Self>where
Self: Sized,
role. A custom widget that does
not describe itself becomes a node of this role with the response’s bounds.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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.