Standard library · Machine learning

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
A window with a browser inside it.
NameTypeDescription
handlevoid*The handle of the browser on Linux and CEF.
windowvoid*The handle of the window in the operating system.
closedbool = falseThe window has been closed.
webview-Window.salam
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
end

Destroy

func Destroy()
Closes the window and frees the resources.

The example for this item is shown with the ones above: webview-Window.salam

Run

func Run()
Runs the event loop until the window is closed.

The example for this item is shown with the ones above: webview-Window.salam

Terminate

func Terminate()
Stops the event loop.

The example for this item is shown with the ones above: webview-Window.salam

SetTitle

func SetTitle(title: str)
The window title.

The example for this item is shown with the ones above: webview-Window.salam

SetSize

func SetSize(width: int, height: int, hints: int)
The window size, with one of the HINT constants.

The example for this item is shown with the ones above: webview-Window.salam

SetHTML

func SetHTML(html: str)
Shows the HTML content.

The example for this item is shown with the ones above: webview-Window.salam

Navigate

func Navigate(url: str)
Opens the address.
webview-Navigate.salam
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()
end

Eval

func Eval(js: str)
Runs JavaScript in the current page.

The example for this item is shown with the ones above: webview-Window.salam

Init

func Init(js: str)
The JavaScript that runs before every page.

The example for this item is shown with the ones above: webview-Window.salam

IsClosed

func IsClosed(): bool
The window has been closed.

The example for this item is shown with the ones above: webview-Window.salam

Constants and variables

HINT_NONE

const HINT_NONE: i32 = 0
The user can resize the window.

The example for this item is shown with the ones above: webview-Window.salam

HINT_FIXED

const HINT_FIXED: i32 = 1
The window size is fixed.

The example for this item is shown with the ones above: webview-Window.salam

Functions

Create

func Create(_debug: bool = false): WebView
Makes a new window; with the debug flag the developer tools open with it.

The example for this item is shown with the ones above: webview-Window.salam