Skip to main content

Sizing

Enum Sizing 

Source
pub enum Sizing {
    Shrink,
    Fit,
    Scale(f64),
}
Expand description

Image sizing.

The default is Fit.

Variants§

§

Shrink

Shrinks the image if it’s too big.

§

Fit

Shrinks the image if it’s too big or expands it if it’s too small.

§

Scale(f64)

Scale.

Implementations§

Source§

impl Sizing

Source

pub fn original() -> Self

Keep the original size: Scale(1.).

Examples found in repository?
examples/scrollable.rs (line 24)
12fn main() {
13    let mut cursive = default();
14
15    cursive.add_layer(
16        Panel::new(
17            ImageView::default()
18                .with_image(
19                    // Note that RGBA is supported, too, if you need transparency
20                    Image::new_stream_from_jpeg_file(FILE, ImageFormat::RGB).expect("new_stream_from_jpeg_file"),
21                    // If you prefer to keep the image data in memory:
22                    // Image::new_owned_from_jpeg_file(FILE, ImageFormat::RGB, true).expect("new_owned_from_jpeg_file"),
23                )
24                .with_sizing(Sizing::original())
25                .scrollable()
26                .scroll_x(true),
27        )
28        .fixed_size((50, 20)),
29    );
30
31    cursive.add_global_callback('q', |cursive| cursive.quit());
32
33    cursive.run();
34}
More examples
Hide additional examples
examples/pdf.rs (line 23)
10fn main() {
11    let mut cursive = default();
12
13    // The constructor returns a vector of images, one for each page in the PDF
14    // PDF pages can be either PNG or RGBA (PNG is usually more efficient)
15    // Note that we can apply scaling during rendering
16    let images = Image::new_owned_from_pdf_file(FILE, ImageFormat::PNG, 1.5, false).expect("new_owned_from_pdf_file");
17
18    cursive.set_user_data(Pages::new(images));
19
20    cursive.add_layer(
21        Dialog::around(
22            Panel::new(
23                ImageView::default().with_sizing(Sizing::original()).with_name(NAME).scrollable().scroll_x(true),
24            )
25            .fixed_size((50, 30)),
26        )
27        .button("Previous", |cursive| flip_page(cursive, -1))
28        .button("Next", |cursive| flip_page(cursive, 1)),
29    );
30
31    select_page(&mut cursive, 0);
32
33    cursive.add_global_callback('q', |cursive| cursive.quit());
34
35    cursive.run();
36}

Trait Implementations§

Source§

impl Clone for Sizing

Source§

fn clone(&self) -> Sizing

Returns a duplicate 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 Debug for Sizing

Source§

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

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

impl Default for Sizing

Source§

fn default() -> Sizing

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

impl PartialEq for Sizing

Source§

fn eq(&self, other: &Sizing) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Sizing

Source§

impl StructuralPartialEq for Sizing

Auto Trait Implementations§

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

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(value: T, _simd: S) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

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

Source§

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>,

Source§

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>,

Source§

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

impl<T> With for T

Source§

fn wrap_with<U, F>(self, f: F) -> U
where F: FnOnce(Self) -> U,

Calls the given closure and return the result. Read more
Source§

fn with<F>(self, f: F) -> Self
where F: FnOnce(&mut Self),

Calls the given closure on self.
Source§

fn try_with<E, F>(self, f: F) -> Result<Self, E>
where F: FnOnce(&mut Self) -> Result<(), E>,

Calls the given closure on self.
Source§

fn with_if<F>(self, condition: bool, f: F) -> Self
where F: FnOnce(&mut Self),

Calls the given closure if condition == true.
Source§

impl<T> ErasedDestructor for T
where T: 'static,