webview
A desktop program with an HTML interface in a native window.
import webview
This package opens a native window with the browser the operating system already has in it: WebView2 on Windows, WKWebView on macOS and WebKitGTK on Linux. Write the interface of the program in HTML and CSS, show it with SetHTML or Navigate, and start the event loop with Run.
The examples open a window, which is why the site only checks them.
Types
WebView
struct WebView| Name | Type | Description |
|---|---|---|
handle | void* | The handle of the browser on Linux and CEF. |
window | void* | The handle of the window in the operating system. |
closed | bool = false | The window has been closed. |
import webview
func main:
mut win := webview.Create(true)
win.SetTitle("hello")
win.SetSize(800, 600, webview.HINT_NONE)
win.Init("window.salam = { version: 1 };")
win.SetHTML("<h1>hello world</h1>")
win.Eval("document.title = 'ready'")
win.Run()
if not win.IsClosed():
win.Terminate()
end
win.Destroy()
println webview.HINT_FIXED
endDestroy
func Destroy()The example for this item is shown with the ones above: webview-Window.salam
Run
func Run()The example for this item is shown with the ones above: webview-Window.salam
Terminate
func Terminate()The example for this item is shown with the ones above: webview-Window.salam
SetTitle
func SetTitle(title: str)The example for this item is shown with the ones above: webview-Window.salam
SetSize
func SetSize(width: int, height: int, hints: int)HINT constants.The example for this item is shown with the ones above: webview-Window.salam
SetHTML
func SetHTML(html: str)The example for this item is shown with the ones above: webview-Window.salam
Navigate
func Navigate(url: str)import webview
func main:
mut win := webview.Create()
win.SetTitle("the Salam language")
win.SetSize(1024, 768, webview.HINT_FIXED)
win.Navigate("https://salamlang.github.io/Salam/")
win.Run()
win.Destroy()
endEval
func Eval(js: str)The example for this item is shown with the ones above: webview-Window.salam
Init
func Init(js: str)The example for this item is shown with the ones above: webview-Window.salam
IsClosed
func IsClosed(): boolThe example for this item is shown with the ones above: webview-Window.salam
Constants and variables
HINT_NONE
const HINT_NONE: i32 = 0The example for this item is shown with the ones above: webview-Window.salam
HINT_FIXED
const HINT_FIXED: i32 = 1The example for this item is shown with the ones above: webview-Window.salam
Functions
Create
func Create(_debug: bool = false): WebViewThe example for this item is shown with the ones above: webview-Window.salam