Struct webview_app::webview::WebViewBuilder

source ·
pub struct WebViewBuilder<'a> { /* private fields */ }
Expand description

Builder to construct a WebView

Implementations§

source§

impl<'a> WebViewBuilder<'a>

source

pub fn build(self) -> WebView

Builds the WebView.

Call this function when all settings are set.

source

pub fn title(self, val: &'a str) -> WebViewBuilder<'a>

Sets the title of the window containing the web view.

source

pub fn initial_bounds(self, w: i32, h: i32) -> WebViewBuilder<'a>

With the help of this method you can initialize the size of the window with custom values. In combination with “save_bounds()” this is the initial width and heigth of the window at first start, otherwise the window is always starting with these values.

source

pub fn save_bounds(self) -> WebViewBuilder<'a>

Saves window bounds after closing app.

When you call save_bounds, then windows location and width and height and normal/maximized state is saved on close. After restarting the app the webview is displayed at these settings again.

source

pub fn without_native_titlebar(self) -> WebViewBuilder<'a>

Hides the native window titlebar

Only working on Windows

source

pub fn url(self, val: &'a str) -> WebViewBuilder<'a>

Sets the Web View’s url

You can use

  • http(s)://
  • file://
source

pub fn debug_url(self, val: &'a str) -> WebViewBuilder<'a>

Sets the Web View’s url when debugging

This url is used when the app is being debugged. For example, if you use a react website you can set

  • debug_url(http://localhost:5173)

and for the release version you set an url to the published web site

You can use

  • http(s)://
  • file://
source

pub fn webroot(self, webroot: Dir<'static>) -> WebViewBuilder<'a>

If you want your web site be included as a resource in the binary file, call this method.

You must not call the url() method. It is set automatically to res://webroot/index.html

index.html has to be present in the webroot directory. All dependant web site resources have to be relatively referenced. The complete web site can be included.

For this purpose you have to add the crate https://crates.io/crates/include_dir.

§Hints
  • The path to webroot is relative to the crates root directory
  • If you set debug_url(...) then this url is loaded in debug version (for example a react website hosted by vite in comparison to the published react website included in the binary)
§example
use include_dir::{include_dir};
use webview_app::webview::WebView;

fn main() {
    let webview = 
        WebView::builder()
            .appid("de.uriegel.hello")
            .title("Website form custom resources 🦞")
            .webroot(include_dir!("webroots/custom_resources"))
            .build();
    webview.run();
}
source

pub fn query_string(self, query_string: &'a str) -> WebViewBuilder<'a>

Sets the query string to the final webroot’s url

§example
use include_dir::{include_dir};
use webview_app::webview::WebView;

fn on_activate(app: &Application)->WebView {
    let webview = 
        WebView::builder()
            .appid("de.uriegel.hello".to_string())
            .title("Website form custom resources 🦞")
            .webroot(include_dir!("webroots/custom_resources"))
            .query_string("?param1=test&param2=somthing")
            .build();
    webview
}
source

pub fn devtools(self, only_when_debugging: bool) -> WebViewBuilder<'a>

Enable (not to show) the developer tools.

Used to enable the developer tools. Otherwise it is not possible to open these tools. The developer tools can be shown by default context menu or by calling the javascript method WebView.showDevtools()

source

pub fn default_contextmenu_disabled(self) -> WebViewBuilder<'a>

Disable the default context menu.

If you set default_contextmenu(), the web view’s default context menu is not being displayed when you right click the mouse.

Auto Trait Implementations§

§

impl<'a> !Freeze for WebViewBuilder<'a>

§

impl<'a> !RefUnwindSafe for WebViewBuilder<'a>

§

impl<'a> !Send for WebViewBuilder<'a>

§

impl<'a> !Sync for WebViewBuilder<'a>

§

impl<'a> Unpin for WebViewBuilder<'a>

§

impl<'a> !UnwindSafe for WebViewBuilder<'a>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.