@@ -11,6 +11,7 @@ const webui = @This();
1111
1212const builtin = @import ("builtin" );
1313const std = @import ("std" );
14+ const windows = std .os .windows ;
1415
1516const flags = @import ("flags" );
1617
@@ -32,7 +33,7 @@ pub fn newWindowWithId(id: usize) webui {
3233 std .log .err ("id {} is illegal" , .{id });
3334 if (comptime builtin .zig_version .minor == 11 ) {
3435 std .os .exit (1 );
35- } else if (comptime builtin .zig_version .minor = = 12 ) {
36+ } else if (comptime builtin .zig_version .minor > = 12 ) {
3637 std .posix .exit (1 );
3738 }
3839 }
@@ -122,6 +123,12 @@ pub fn setHighContrast(self: webui, status: bool) void {
122123 c .webui_set_high_contrast (self .window_handle , status );
123124}
124125
126+ /// Sets whether the window frame is resizable or fixed.
127+ /// Works only on WebView window.
128+ pub fn setResizable (self : webui , status : bool ) void {
129+ c .webui_set_resizable (self .window_handle , status );
130+ }
131+
125132pub fn isHighConstrast () bool {
126133 return c .webui_is_high_contrast ();
127134}
@@ -137,10 +144,22 @@ pub fn wait() void {
137144 c .webui_wait ();
138145}
139146
147+ /// Close a specific window only. The window object will still exist.
148+ /// All clients.
140149pub fn close (self : webui ) void {
141150 c .webui_close (self .window_handle );
142151}
143152
153+ /// Minimize a WebView window.
154+ pub fn minimize (self : webui ) void {
155+ c .webui_minimize (self .window_handle );
156+ }
157+
158+ /// Maximize a WebView window.
159+ pub fn maximize (self : webui ) void {
160+ c .webui_maximize (self .window_handle );
161+ }
162+
144163/// Close a specific window and free all memory resources.
145164pub fn destroy (self : webui ) void {
146165 c .webui_destroy (self .window_handle );
@@ -157,6 +176,11 @@ pub fn setRootFolder(self: webui, path: [:0]const u8) bool {
157176 return c .webui_set_root_folder (self .window_handle , path .ptr );
158177}
159178
179+ /// Set custom browser folder path.
180+ pub fn setBrowserFolder (self : webui , path : [:0 ]const u8 ) bool {
181+ return c .webui_set_browser_folder (self .window_handle , path .ptr );
182+ }
183+
160184/// Set the web-server root folder path for all windows.
161185/// Should be used before `show()`.
162186pub fn setDefaultRootFolder (path : [:0 ]const u8 ) bool {
@@ -229,6 +253,7 @@ pub fn setIcon(self: webui, icon: [:0]const u8, icon_type: [:0]const u8) void {
229253
230254/// Base64 encoding. Use this to safely send text based data to the UI. If
231255/// it fails it will return NULL.
256+ /// you need free the return memory with free function
232257pub fn encode (str : [:0 ]const u8 ) ? []u8 {
233258 const ptr = c .webui_encode (str .ptr );
234259 if (ptr == null ) {
@@ -241,6 +266,7 @@ pub fn encode(str: [:0]const u8) ?[]u8 {
241266/// Base64 decoding.
242267/// Use this to safely decode received Base64 text from the UI.
243268/// If it fails it will return NULL.
269+ /// you need free the return memory with free function
244270pub fn decode (str : [:0 ]const u8 ) ? []u8 {
245271 const ptr = c .webui_decode (str .ptr );
246272 if (ptr == null ) {
@@ -295,6 +321,12 @@ pub fn setPosition(self: webui, x: u32, y: u32) void {
295321 c .webui_set_position (self .window_handle , x , y );
296322}
297323
324+ /// Centers the window on the screen. Works better with
325+ /// WebView. Call this function before `webui_show()` for better results.
326+ pub fn setCenter (self : webui ) void {
327+ c .webui_set_center (self .window_handle );
328+ }
329+
298330/// Set the web browser profile to use.
299331/// An empty `name` and `path` means the default user profile.
300332/// Need to be called before `show()`.
@@ -356,6 +388,12 @@ pub fn getChildProcessId(self: webui) usize {
356388 return c .webui_get_child_process_id (self .window_handle );
357389}
358390
391+ /// Gets Win32 window `HWND`. More reliable with WebView
392+ /// than web browser window, as browser PIDs may change on launch.
393+ pub fn win32GetHwnd (self : webui ) windows.HWND {
394+ const tmp_hwnd = c .webui_win32_get_hwnd (self .window_handle );
395+ return @ptrCast (tmp_hwnd );
396+ }
359397/// Get the network port of a running window.
360398/// This can be useful to determine the HTTP link of `webui.js`
361399pub fn getPort (self : webui ) usize {
@@ -388,6 +426,16 @@ pub fn setEventBlocking(self: webui, status: bool) void {
388426 c .webui_set_event_blocking (self .window_handle , status );
389427}
390428
429+ /// Make a WebView window frameless.
430+ pub fn setFrameless (self : webui , status : bool ) void {
431+ c .webui_set_frameless (self .window_handle , status );
432+ }
433+
434+ /// Make a WebView window transparent.
435+ pub fn setTransparent (self : webui , status : bool ) void {
436+ c .webui_set_transparent (self .window_handle , status );
437+ }
438+
391439/// Get the HTTP mime type of a file.
392440pub fn getMimeType (file : [:0 ]const u8 ) [:0 ]const u8 {
393441 const res = c .webui_get_mime_type (file .ptr );
@@ -603,8 +651,8 @@ pub fn interfaceRunClient(self: webui, event_number: usize, script_content: [:0]
603651}
604652
605653// Run JavaScript and get the response back. Single client.
606- pub fn interfaceScriptClient (self : webui , event_number : usize , script_content : [:0 ]const u8 , timeout : usize , buffer : []u8 ) void {
607- c .webui_interface_script_client (self .window_handle , event_number , script_content .ptr , timeout , buffer .ptr , buffer .len );
654+ pub fn interfaceScriptClient (self : webui , event_number : usize , script_content : [:0 ]const u8 , timeout : usize , buffer : []u8 ) bool {
655+ return c .webui_interface_script_client (self .window_handle , event_number , script_content .ptr , timeout , buffer .ptr , buffer .len );
608656}
609657
610658/// a very convenient function for binding callback.
@@ -668,15 +716,15 @@ pub fn binding(self: webui, element: [:0]const u8, comptime callback: anytype) u
668716 param_tup [i ] = e ;
669717 },
670718 .Bool = > {
671- const res = getBoolAt (e , i );
719+ const res = e . getBoolAt (i );
672720 param_tup [i ] = res ;
673721 },
674722 .Int = > {
675- const res = getIntAt (e , i );
723+ const res = e . getIntAt (i );
676724 param_tup [i ] = @intCast (res );
677725 },
678726 .Float = > {
679- const res = getFloatAt (e , i );
727+ const res = e . getFloatAt (i );
680728 param_tup [i ] = res ;
681729 },
682730 .Pointer = > | pointer | {
@@ -687,8 +735,8 @@ pub fn binding(self: webui, element: [:0]const u8, comptime callback: anytype) u
687735 );
688736 @compileError (err_msg );
689737 }
690- const str_ptr = getStringAt (e , i );
691- const tmp_str_len = getSizeAt (e , i );
738+ const str_ptr = e . getStringAt (i );
739+ const tmp_str_len = e . getSizeAt (i );
692740 const str : []const u8 = str_ptr [0.. tmp_str_len ];
693741 param_tup [i ] = str ;
694742 },
@@ -993,7 +1041,7 @@ pub const Event = extern struct {
9931041
9941042 /// Get the first argument as float
9951043 pub fn getFloat (e : * Event ) f64 {
996- c .webui_get_float (e );
1044+ return c .webui_get_float (e );
9971045 }
9981046
9991047 /// Get an argument as string at a specific index
0 commit comments