pub struct Image<'a, 'c> {
source: Option<Cow<'c, ImageSource<'a>>>,
tooltip: Option<Text>,
color: Option<RewriteColor>,
content_mode: Option<ContentMode>,
corner_rounding: Option<CornerRounding>,
padding: Option<EdgeInsets>,
bg_color: Option<Color>,
dims: Option<ScreenDims>,
}
Expand description
A stylable UI component builder which presents vector graphics from an ImageSource
.
Fields
source: Option<Cow<'c, ImageSource<'a>>>
tooltip: Option<Text>
color: Option<RewriteColor>
content_mode: Option<ContentMode>
corner_rounding: Option<CornerRounding>
padding: Option<EdgeInsets>
bg_color: Option<Color>
dims: Option<ScreenDims>
Implementations
sourceimpl<'a, 'c> Image<'a, 'c>
impl<'a, 'c> Image<'a, 'c>
sourcepub fn empty() -> Self
pub fn empty() -> Self
An Image
with no renderable content. Useful for starting a template for creating
several similar images using a builder pattern.
sourcepub fn from_path(filename: &'a str) -> Self
pub fn from_path(filename: &'a str) -> Self
Create an SVG Image
, read from filename
, which is colored to match Style.icon_fg
sourcepub fn from_bytes(labeled_bytes: (&'a str, &'a [u8])) -> Self
pub fn from_bytes(labeled_bytes: (&'a str, &'a [u8])) -> Self
Create a new SVG Image
from bytes.
labeled_bytes
: is a (label
,bytes
) tuple you can generate withinclude_labeled_bytes!
label
: a label to describe the bytes for debugging purposesbytes
: UTF-8 encoded bytes of the SVG
sourcepub fn from_batch(batch: GeomBatch, bounds: Bounds) -> Self
pub fn from_batch(batch: GeomBatch, bounds: Bounds) -> Self
Create a new Image
from a GeomBatch
.
By default, the given bounds
will be used for padding, background, etc.
sourcepub fn source(self, source: ImageSource<'a>) -> Self
pub fn source(self, source: ImageSource<'a>) -> Self
Set a new source for the Image
’s data.
This will replace any previously set source.
sourcepub fn source_path(self, path: &'a str) -> Self
pub fn source_path(self, path: &'a str) -> Self
Set the path to an SVG file for the image.
This will replace any image source previously set.
sourcepub fn source_bytes(self, labeled_bytes: (&'a str, &'a [u8])) -> Self
pub fn source_bytes(self, labeled_bytes: (&'a str, &'a [u8])) -> Self
Set the bytes for the image.
This will replace any image source previously set.
labeled_bytes
: is a (label
,bytes
) tuple you can generate withinclude_labeled_bytes!
label
: a label to describe the bytes for debugging purposesbytes
: UTF-8 encoded bytes of the SVG
sourcepub fn source_batch(self, batch: GeomBatch, bounds: Bounds) -> Self
pub fn source_batch(self, batch: GeomBatch, bounds: Bounds) -> Self
Set the GeomBatch for the button.
This will replace any image source previously set.
This method is useful when doing more complex transforms. For example, to re-write more than one color for your image, do so externally and pass in the resultant GeomBatch here.
sourcepub fn tooltip(self, tooltip: impl Into<Text>) -> Self
pub fn tooltip(self, tooltip: impl Into<Text>) -> Self
Add a tooltip to appear when hovering over the image.
sourcepub fn merged_image_style(&'c self, other: &'c Self) -> Self
pub fn merged_image_style(&'c self, other: &'c Self) -> Self
Create a new Image
based on self
, but overriding with any values set on other
.
sourcepub fn color<RWC: Into<RewriteColor>>(self, value: RWC) -> Self
pub fn color<RWC: Into<RewriteColor>>(self, value: RWC) -> Self
Rewrite the color of the image.
sourcepub fn bg_color(self, value: Color) -> Self
pub fn bg_color(self, value: Color) -> Self
Set a background color for the image. Has no effect unless custom dims
are explicitly set.
sourcepub fn untinted(self) -> Self
pub fn untinted(self) -> Self
The image’s intrinsic colors will be used, it will not be tinted like Image::icon
sourcepub fn dims<D: Into<ScreenDims>>(self, dims: D) -> Self
pub fn dims<D: Into<ScreenDims>>(self, dims: D) -> Self
Scale the bounds containing the image. If dims
are not specified, the image’s intrinsic
size will be used, but padding and background settings will be ignored.
See Self::content_mode
to control how the image scales to fit its custom bounds.
sourcepub fn content_mode(self, value: ContentMode) -> Self
pub fn content_mode(self, value: ContentMode) -> Self
If a custom dims
was set, control how the image should be scaled to its new bounds.
If dims
were not specified, the image will not be scaled, so content_mode has no
affect.
The default, ContentMode::ScaleAspectFit
will only grow as much as it can while
maintaining its aspect ratio and not exceeding its bounds
sourcepub fn corner_rounding<R: Into<CornerRounding>>(self, value: R) -> Self
pub fn corner_rounding<R: Into<CornerRounding>>(self, value: R) -> Self
Set independent rounding for each of the image’s corners. Has no effect unless custom
dims
are explicitly set.
sourcepub fn padding<EI: Into<EdgeInsets>>(self, value: EI) -> Self
pub fn padding<EI: Into<EdgeInsets>>(self, value: EI) -> Self
Set padding for the image. Has no effect unless custom dims
are explicitly set.
sourcepub fn padding_top(self, new_value: f64) -> Self
pub fn padding_top(self, new_value: f64) -> Self
Padding above the image. Has no effect unless custom dims
are explicitly set.
sourcepub fn padding_left(self, new_value: f64) -> Self
pub fn padding_left(self, new_value: f64) -> Self
Padding to the left of the image. Has no effect unless custom dims
are explicitly set.
sourcepub fn padding_bottom(self, new_value: f64) -> Self
pub fn padding_bottom(self, new_value: f64) -> Self
Padding below the image. Has no effect unless custom dims
are explicitly set.
sourcepub fn padding_right(self, new_value: f64) -> Self
pub fn padding_right(self, new_value: f64) -> Self
Padding to the right of the image. Has no effect unless custom dims
are explicitly set.
sourcepub fn build_batch(&self, ctx: &EventCtx<'_>) -> Option<(GeomBatch, Bounds)>
pub fn build_batch(&self, ctx: &EventCtx<'_>) -> Option<(GeomBatch, Bounds)>
Render the Image
and any styling (padding, background, etc.) to a GeomBatch
.
pub fn into_widget(self, ctx: &EventCtx<'_>) -> Widget
Trait Implementations
Auto Trait Implementations
impl<'a, 'c> RefUnwindSafe for Image<'a, 'c>
impl<'a, 'c> Send for Image<'a, 'c>
impl<'a, 'c> Sync for Image<'a, 'c>
impl<'a, 'c> Unpin for Image<'a, 'c> where
'a: 'c,
impl<'a, 'c> UnwindSafe for Image<'a, 'c>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Convert 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
. Read more
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
pub fn as_any(&self) -> &(dyn Any + 'static)
pub fn as_any(&self) -> &(dyn Any + 'static)
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
type Output = T
Should always be Self
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more