Struct widgetry::Image

source ·
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§

source§

impl<'a, 'c> Image<'a, 'c>

source

pub fn empty() -> Self

An Image with no renderable content. Useful for starting a template for creating several similar images using a builder pattern.

source

pub fn from_path(filename: &'a str) -> Self

Create an SVG Image, read from filename, which is colored to match Style.icon_fg

source

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 with [include_labeled_bytes!]
  • label: a label to describe the bytes for debugging purposes
  • bytes: UTF-8 encoded bytes of the SVG
source

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.

source

pub fn source(self, source: ImageSource<'a>) -> Self

Set a new source for the Image’s data.

This will replace any previously set source.

source

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.

source

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 with [include_labeled_bytes!]
  • label: a label to describe the bytes for debugging purposes
  • bytes: UTF-8 encoded bytes of the SVG
source

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.

source

pub fn tooltip(self, tooltip: impl Into<Text>) -> Self

Add a tooltip to appear when hovering over the image.

source

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.

source

pub fn color<RWC: Into<RewriteColor>>(self, value: RWC) -> Self

Rewrite the color of the image.

source

pub fn bg_color(self, value: Color) -> Self

Set a background color for the image. Has no effect unless custom dims are explicitly set.

source

pub fn untinted(self) -> Self

The image’s intrinsic colors will be used, it will not be tinted like Image::icon

source

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.

source

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

source

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.

source

pub fn padding<EI: Into<EdgeInsets>>(self, value: EI) -> Self

Set padding for the image. Has no effect unless custom dims are explicitly set.

source

pub fn padding_top(self, new_value: f64) -> Self

Padding above the image. Has no effect unless custom dims are explicitly set.

source

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.

source

pub fn padding_bottom(self, new_value: f64) -> Self

Padding below the image. Has no effect unless custom dims are explicitly set.

source

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.

source

pub fn build_batch(&self, ctx: &EventCtx<'_>) -> Option<(GeomBatch, Bounds)>

Render the Image and any styling (padding, background, etc.) to a GeomBatch.

source

pub fn into_widget(self, ctx: &EventCtx<'_>) -> Widget

Trait Implementations§

source§

impl<'a, 'c> Clone for Image<'a, 'c>

source§

fn clone(&self) -> Image<'a, 'c>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a, 'c> Debug for Image<'a, 'c>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a, 'c> Default for Image<'a, 'c>

source§

fn default() -> Image<'a, 'c>

Returns the “default value” for a type. Read more

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>

§

impl<'a, 'c> UnwindSafe for Image<'a, 'c>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

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.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

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.
§

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.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

§

fn is_within(&self, b: &G2) -> bool