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: u32Viewport width in pixels.
height: u32Viewport height in pixels.
device_scale_factor: f64Device scale factor (DPR). Higher values (e.g., 2.0, 3.0) produce sharper images. Default is 1.0.
is_mobile: boolWhether to emulate a mobile device. Default is false.
has_touch: boolWhether touch events are supported. Default is false.
is_landscape: boolWhether viewport is in landscape mode. Default is false.
Implementations§
Source§impl Viewport
impl Viewport
Sourcepub fn new(width: u32, height: u32) -> Self
pub fn new(width: u32, height: u32) -> Self
Creates a new viewport with specified dimensions and default settings.
Sourcepub fn builder() -> ViewportBuilder
pub fn builder() -> ViewportBuilder
Creates a new viewport builder for fluent configuration.
Sourcepub fn with_device_scale_factor(self, factor: f64) -> Self
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)
Sourcepub fn with_mobile(self, is_mobile: bool) -> Self
pub fn with_mobile(self, is_mobile: bool) -> Self
Sets whether to emulate a mobile device.
Sourcepub fn with_touch(self, has_touch: bool) -> Self
pub fn with_touch(self, has_touch: bool) -> Self
Sets whether touch events are supported.
Sourcepub fn with_landscape(self, is_landscape: bool) -> Self
pub fn with_landscape(self, is_landscape: bool) -> Self
Sets whether the viewport is in landscape mode.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Viewport
impl RefUnwindSafe for Viewport
impl Send for Viewport
impl Sync for Viewport
impl Unpin for Viewport
impl UnwindSafe for Viewport
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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