Skip to content

Repository files navigation

webview-zig

Zig binding for a tiny cross-platform webview library to build modern cross-platform GUIs.

Requirements

Usage

zig fetch --save https://github.com/thechampagne/webview-zig/archive/refs/heads/main.tar.gz

build.zig.zon:

.{
.dependencies= .{
.webview= .{
.url="https://github.com/thechampagne/webview-zig/archive/refs/heads/main.tar.gz" ,
//.hash = "12208586373679a455aa8ef874112c93c1613196f60137878d90ce9d2ae8fb9cd511",
},
},
}

build.zig:

constwebview=b.dependency("webview", .{
.target=target,
.optimize=optimize,
});
exe.root_module.addImport("webview", webview.module("webview"));
exe.linkLibrary(webview.artifact("webviewStatic")); // or "webviewShared" for shared library// exe.linkSystemLibrary("webview"); to link with installed prebuilt library without building

API

constWebView=struct {
constWebViewVersionInfo=struct {
version: struct {
major: c_uint,
minor: c_uint,
patch: c_uint,
},
version_number: [32]c_char,
pre_release: [48]c_char,
build_metadata: [48]c_char,
};
constDispatchCallback=*constfn (WebView, ?*anyopaque) void;
constBindCallback=*constfn ([:0]constu8, [:0]constu8, ?*anyopaque) void;
constWindowSizeHint=enum(c_uint) {
None,
Min,
Max,
Fixed
};
constNativeHandle=enum(c_uint) {
ui_window,
ui_widget,
browser_controller
};
constWebViewError=error {
MissingDependency,
Canceled,
InvalidState,
InvalidArgument,
Unspecified,
Duplicate,
NotFound,
};
fnCallbackContext(func: [DispatchCallback|BindCallback]) type {
returnstruct {
fninit(data: ?*anyopaque) @This();
};
}
fncreate(debug: bool, window: ?*anyopaque) WebView;
fnrun(self: WebView) WebViewError!void;
fnterminate(self: WebView) WebViewError!void;
fndispatch(self: WebView, ctx: *constCallbackContext) WebViewError!void;
fngetWindow(self: WebView) ?*anyopaque;
fngetNativeHandle(self: WebView, kind: NativeHandle) ?*anyopaque;
fnsetTitle(self: WebView, title: [:0]constu8) WebViewError!void;
fnsetSize(self: WebView, width: i32, height: i32, hint: WindowSizeHint) WebViewError!void;
fnnavigate(self: WebView, url: [:0]constu8) WebViewError!void;
fnsetHtml(self: WebView, html: [:0]constu8) WebViewError!void;
fninit(self: WebView, js: [:0]constu8) WebViewError!void;
fneval(self: WebView, js: [:0]constu8) WebViewError!void;
fnbind(self: WebView, name: [:0]constu8, ctx: *constCallbackContext) WebViewError!void;
fnunbind(self: WebView, name: [:0]constu8) WebViewError!void;
fnret(self: WebView ,seq: [:0]constu8, status: i32, result: [:0]constu8) WebViewError!void;
fnversion() *constWebViewVersionInfo;
fndestroy(self: WebView) WebViewError!void;
}

References

License

This repo is released under the MIT License.

Third party code:

About

⚡ Zig binding & wrapper for a tiny cross-platform webview library to build modern cross-platform GUIs.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages