Skip to main content

ViewerOptions

Struct ViewerOptions 

Source
pub struct ViewerOptions {
    pub content: ViewerContent,
    pub window: WindowOptions,
    pub behaviour: BehaviourOptions,
    pub environment: EnvironmentOptions,
    pub dialog: DialogOptions,
    pub wait: ViewerWaitMode,
}
Expand description

Options for configuring a viewer instance.

This struct provides full control over how the viewer window behaves, what content it displays, and how it interacts with the user.

§Examples

Creating options for different content types:

use html_view::ViewerOptions;
use std::path::PathBuf;

// Inline HTML
let opts1 = ViewerOptions::inline_html("<h1>Hello</h1>");

// Local file
let opts2 = ViewerOptions::local_file(PathBuf::from("index.html"));

// Application directory
let opts3 = ViewerOptions::app_dir(PathBuf::from("./dist"));

Customizing options:

use html_view::ViewerOptions;

let mut opts = ViewerOptions::inline_html("<h1>Custom</h1>");
opts.window.width = Some(800);
opts.window.height = Some(600);
opts.window.title = Some("My App".to_string());
opts.behaviour.enable_devtools = true;
opts.environment.timeout_seconds = Some(30);

Fields§

§content: ViewerContent

The content to display.

See ViewerContent for all supported content types.

§window: WindowOptions

Window configuration.

Controls size, position, decorations, and visual appearance.

§behaviour: BehaviourOptions

Behaviour and security options.

Controls navigation, remote content, devtools, and notifications.

§environment: EnvironmentOptions

Environment options.

Controls working directory and timeout behavior.

§dialog: DialogOptions

Dialog configuration.

Controls whether file and message dialogs are allowed.

§wait: ViewerWaitMode

Whether to wait for the viewer to close.

In ViewerWaitMode::Blocking mode, the call blocks until the window closes. In ViewerWaitMode::NonBlocking mode, returns immediately with a handle.

Implementations§

Source§

impl ViewerOptions

Source

pub fn inline_html<S: Into<String>>(html: S) -> Self

Create options for displaying inline HTML with default settings.

This uses secure defaults:

  • Window size: 1024x768
  • Resizable: true
  • External navigation: disabled
  • Devtools: disabled
  • Remote content: disabled
  • Wait mode: Blocking
§Example
use html_view::ViewerOptions;

let options = ViewerOptions::inline_html("<h1>Hello!</h1>");
Source

pub fn local_file(path: PathBuf) -> Self

Create options for displaying a local HTML file.

§Example
use html_view::ViewerOptions;
use std::path::PathBuf;

let options = ViewerOptions::local_file(PathBuf::from("index.html"));
Source

pub fn app_dir(root: PathBuf) -> Self

Create options for displaying an HTML application directory.

§Example
use html_view::ViewerOptions;
use std::path::PathBuf;

let options = ViewerOptions::app_dir(PathBuf::from("./dist"));
Source

pub fn remote_url(url: Url) -> Self

Create options for displaying a remote URL.

Note: This automatically enables allow_remote_content in the behaviour options.

§Example
use html_view::ViewerOptions;
use url::Url;

let url = Url::parse("https://example.com").unwrap();
let options = ViewerOptions::remote_url(url);
Source

pub fn new() -> ViewerOptionsBuilder

Create a new builder for ViewerOptions.

Trait Implementations§

Source§

impl Clone for ViewerOptions

Source§

fn clone(&self) -> ViewerOptions

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 ViewerOptions

Source§

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

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

impl Default for ViewerOptions

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