Viewport

Struct Viewport 

Source
pub struct Viewport {
    pub width: u32,
    pub height: u32,
    pub device_scale_factor: f64,
    pub is_mobile: bool,
    pub has_touch: bool,
    pub is_landscape: bool,
}
Expand description

Viewport configuration for controlling page dimensions and device emulation.

Similar to Puppeteer’s page.setViewport(), this allows you to control the page dimensions and device scale factor for higher quality screenshots.

§Example

use cdp_html_shot::Viewport;

// Create a high-DPI viewport for sharper images
let viewport = Viewport::new(1920, 1080)
    .with_device_scale_factor(2.0);

// Or use builder pattern for full control
let viewport = Viewport::builder()
    .width(1280)
    .height(720)
    .device_scale_factor(3.0)
    .is_mobile(false)
    .build();

Fields§

§width: u32

Viewport width in pixels.

§height: u32

Viewport height in pixels.

§device_scale_factor: f64

Device scale factor (DPR). Higher values (e.g., 2.0, 3.0) produce sharper images. Default is 1.0.

§is_mobile: bool

Whether to emulate a mobile device. Default is false.

§has_touch: bool

Whether touch events are supported. Default is false.

§is_landscape: bool

Whether viewport is in landscape mode. Default is false.

Implementations§

Source§

impl Viewport

Source

pub fn new(width: u32, height: u32) -> Self

Creates a new viewport with specified dimensions and default settings.

Source

pub fn builder() -> ViewportBuilder

Creates a new viewport builder for fluent configuration.

Source

pub fn with_device_scale_factor(self, factor: f64) -> Self

Sets the device scale factor (DPR) for higher quality images.

Common values:

  • 1.0: Standard resolution
  • 2.0: Retina/HiDPI (2x sharper)
  • 3.0: Ultra-high DPI (3x sharper)
Source

pub fn with_mobile(self, is_mobile: bool) -> Self

Sets whether to emulate a mobile device.

Source

pub fn with_touch(self, has_touch: bool) -> Self

Sets whether touch events are supported.

Source

pub fn with_landscape(self, is_landscape: bool) -> Self

Sets whether the viewport is in landscape mode.

Trait Implementations§

Source§

impl Clone for Viewport

Source§

fn clone(&self) -> Viewport

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 Viewport

Source§

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

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

impl Default for Viewport

Source§

fn default() -> Self

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V