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>
impl<'a> WebViewBuilder<'a>
sourcepub fn build(self) -> WebView
pub fn build(self) -> WebView
Builds the WebView.
Call this function when all settings are set.
sourcepub fn title(self, val: &'a str) -> WebViewBuilder<'a>
pub fn title(self, val: &'a str) -> WebViewBuilder<'a>
Sets the title of the window containing the web view.
sourcepub fn initial_bounds(self, w: i32, h: i32) -> WebViewBuilder<'a>
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.
sourcepub fn save_bounds(self) -> WebViewBuilder<'a>
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.
sourcepub fn without_native_titlebar(self) -> WebViewBuilder<'a>
pub fn without_native_titlebar(self) -> WebViewBuilder<'a>
Hides the native window titlebar
Only working on Windows
sourcepub fn url(self, val: &'a str) -> WebViewBuilder<'a>
pub fn url(self, val: &'a str) -> WebViewBuilder<'a>
Sets the Web View’s url
You can use
http(s)://
file://
sourcepub fn debug_url(self, val: &'a str) -> WebViewBuilder<'a>
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://
sourcepub fn webroot(self, webroot: Dir<'static>) -> WebViewBuilder<'a>
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();
}
sourcepub fn query_string(self, query_string: &'a str) -> WebViewBuilder<'a>
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¶m2=somthing")
.build();
webview
}
sourcepub fn devtools(self, only_when_debugging: bool) -> WebViewBuilder<'a>
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()
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.