[][src]Struct neutrino::widgets::image::Image

pub struct Image { /* fields omitted */ }

An element able to display images from icons and path

Fields

name: String
state: ImageState
listener: Option<Box<dyn ImageListener>>

Default values

The variable pixmap is built in both constructors from the given Icon or path.

name: name.to_string()
state:
    data: pixmap.data().to_string()
    extension: pixmap.extension().to_string()
    background: "black".to_string()
    keep_ratio_aspect: false
    stretched: false
    style: "".to_string()
listener: None

Style

div.image
    img

Example

use std::cell::RefCell;
use std::rc::Rc;

use neutrino::widgets::image::{Image, ImageListener, ImageState};
use neutrino::utils::theme::Theme;
use neutrino::utils::pixmap::Pixmap;
use neutrino::{App, Window};


struct Painting {
    path: String,
}

impl Painting {
    fn new(path: &str) -> Self {
        Self { path: path.to_string() }
    }

    fn path(&self) -> &str {
        &self.path
    }
}


struct MyImageListener {
    painting: Rc<RefCell<Painting>>,
}

impl MyImageListener {
   pub fn new(painting: Rc<RefCell<Painting>>) -> Self {
       Self { painting }
   }
}

impl ImageListener for MyImageListener {
    fn on_update(&self, state: &mut ImageState) {
        let pixmap = Pixmap::from_path(self.painting.borrow().path());
        state.set_data(pixmap.data());
        state.set_extension(pixmap.extension());
    }
}


fn main() {
    let painting = Rc::new(RefCell::new(Painting::new("/home/neutrino/le_radeau_de_la_meduse.jpg")));

    let my_listener = MyImageListener::new(Rc::clone(&painting));

    let mut my_image = Image::from_path("my_image", "/home/neutrino/le_radeau_de_la_meduse.jpg");
    my_image.set_listener(Box::new(my_listener));
}

Methods

impl Image[src]

pub fn from_path(name: &str, path: &str) -> Self[src]

Create an image from a path

pub fn from_icon(name: &str, icon: Box<dyn Icon>) -> Self[src]

Create an image from an icon

pub fn set_background(&mut self, background: &str)[src]

Set the background color

pub fn set_keep_ratio_aspect(&mut self)[src]

Set the keep_ratio_aspect flag to true

pub fn set_stretched(&mut self)[src]

Set the stretched flag to true

pub fn set_listener(&mut self, listener: Box<dyn ImageListener>)[src]

Set the listener

pub fn set_style(&mut self, style: &str)[src]

Set the style

Trait Implementations

impl Widget for Image[src]

Auto Trait Implementations

impl !Send for Image

impl Unpin for Image

impl !Sync for Image

impl !UnwindSafe for Image

impl !RefUnwindSafe for Image

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,