Skip to content

Commit 39d18ea

Browse files
authored
core: update to beta 4 (#89)
1 parent 37e49f0 commit 39d18ea

File tree

3 files changed

+127
-15
lines changed

3 files changed

+127
-15
lines changed

build.zig.zon

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
.{
22
.name = .zig_webui,
3-
.version = "0.0.1",
4-
.minimum_zig_version = "0.12.0",
3+
.version = "2.5.0-beta.4",
54
.fingerprint = 0x95965ed3cdfb8c33,
5+
.minimum_zig_version = "0.14.0",
66
.dependencies = .{
77
.webui = .{
8-
.url = "https://github.com/webui-dev/webui/archive/5d497e3b839a93736be82107b333b4c0390dea2d.tar.gz",
9-
.hash = "webui-2.5.0-beta.3-pxqD5WZmNgCLmrqQW0U_NI4iq-z706dyreyXr-e7kFmZ",
8+
.hash = "webui-2.5.0-beta.4-pxqD5WQONwB73V_0MKBVXgR7k6t6pb_B3KfAZqfbPf-7",
9+
.url = "https://github.com/webui-dev/webui/archive/3c03d4f45cf6e65e678b0ca87f8ec28d952b9d78.tar.gz",
1010
},
1111
},
1212
.paths = .{

src/c.zig

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,15 @@ pub extern fn webui_set_custom_parameters(window: usize, params: [*:0]const u8)
187187
/// @example webui_set_high_contrast(my_window, true);
188188
pub extern fn webui_set_high_contrast(window: usize, status: bool) callconv(.C) void;
189189

190+
/// @brief Sets whether the window frame is resizable or fixed.
191+
/// Works only on WebView window.
192+
///
193+
/// @param window The window number
194+
/// @param status True or False
195+
///
196+
/// @example webui_set_resizable(myWindow, true);
197+
pub extern fn webui_set_resizable(window: usize, status: bool) callconv(.C) void;
198+
190199
/// @brief Get OS high contrast preference.
191200
///
192201
/// @return Returns True if OS is using high contrast theme
@@ -214,6 +223,20 @@ pub extern fn webui_wait() callconv(.C) void;
214223
/// @example webui_close(my_window);
215224
pub extern fn webui_close(window: usize) callconv(.C) void;
216225

226+
/// @brief Minimize a WebView window.
227+
///
228+
/// @param window The window number
229+
///
230+
/// @example webui_minimize(myWindow);
231+
pub extern fn webui_minimize(window: usize) callconv(.C) void;
232+
233+
/// @brief Maximize a WebView window.
234+
///
235+
/// @param window The window number
236+
///
237+
/// @example webui_maximize(myWindow);
238+
pub extern fn webui_maximize(window: usize) callconv(.C) void;
239+
217240
/// @brief Close a specific client.
218241
///
219242
/// @param e The event struct
@@ -241,6 +264,13 @@ pub extern fn webui_exit() callconv(.C) void;
241264
/// @example webui_set_root_folder(my_window, "/home/Foo/Bar/");
242265
pub extern fn webui_set_root_folder(window: usize, path: [*:0]const u8) callconv(.C) bool;
243266

267+
/// @brief Set custom browser folder path.
268+
///
269+
/// @param path The browser folder path
270+
///
271+
/// @example webui_set_browser_folder("/home/Foo/Bar/");
272+
pub extern fn webui_set_browser_folder(path: [*:0]const u8) callconv(.C) void;
273+
244274
/// @brief Set the web-server root folder path for all windows. Should be used
245275
/// before `webui_show()`.
246276
///
@@ -293,7 +323,7 @@ pub extern fn webui_set_file_handler_window(
293323
///
294324
pub extern fn webui_interface_set_response_file_handler(
295325
window: usize,
296-
response: ?*const anyopaque,
326+
response: *const anyopaque,
297327
length: usize,
298328
) callconv(.C) void;
299329

@@ -442,6 +472,14 @@ pub extern fn webui_set_minimum_size(
442472
/// @example webui_set_position(my_window, 100, 100);
443473
pub extern fn webui_set_position(window: usize, x: u32, y: u32) callconv(.C) void;
444474

475+
/// @brief Centers the window on the screen. Works better with
476+
/// WebView. Call this function before `webui_show()` for better results.
477+
///
478+
/// @param window The window number
479+
///
480+
/// @example webui_set_center(myWindow);
481+
pub extern fn webui_set_center(window: usize) callconv(.C) void;
482+
445483
/// @brief Set the web browser profile to use. An empty `name` and `path` means
446484
/// the default user profile. Need to be called before `webui_show()`.
447485
///
@@ -556,6 +594,16 @@ pub extern fn webui_get_parent_process_id(window: usize) callconv(.C) usize;
556594
/// @example const id: usize = webui_get_child_process_id(my_window);
557595
pub extern fn webui_get_child_process_id(window: usize) callconv(.C) usize;
558596

597+
/// @brief Gets Win32 window `HWND`. More reliable with WebView
598+
/// than web browser window, as browser PIDs may change on launch.
599+
///
600+
/// @param window The window number
601+
///
602+
/// @return Returns the window `hwnd` as `void*`
603+
///
604+
/// @example HWND hwnd = webui_win32_get_hwnd(myWindow);
605+
pub extern fn webui_win32_get_hwnd(window: usize) callconv(.C) *anyopaque;
606+
559607
/// @brief Get the network port of a running window.
560608
/// This can be useful to determine the HTTP link of `webui.js`
561609
///
@@ -604,6 +652,22 @@ pub extern fn webui_set_config(option: Config, status: bool) callconv(.C) void;
604652
/// @example webui_set_event_blocking(my_window, true);
605653
pub extern fn webui_set_event_blocking(window: usize, status: bool) callconv(.C) void;
606654

655+
/// @brief Make a WebView window frameless.
656+
///
657+
/// @param window The window number
658+
/// @param status The frameless status `true` or `false`
659+
///
660+
/// @example webui_set_frameless(myWindow, true);
661+
pub extern fn webui_set_frameless(window: usize, status: bool) callconv(.C) void;
662+
663+
/// @brief Make a WebView window transparent.
664+
///
665+
/// @param window The window number
666+
/// @param status The transparency status `true` or `false`
667+
///
668+
/// @example webui_set_transparent(myWindow, true);
669+
pub extern fn webui_set_transparent(window: usize, status: bool) callconv(.C) void;
670+
607671
/// @brief Get the HTTP mime type of a file.
608672
///
609673
/// @return Returns the HTTP mime string
@@ -1050,4 +1114,4 @@ pub extern fn webui_interface_script_client(
10501114
timeout: usize,
10511115
buffer: [*c]u8,
10521116
buffer_length: usize,
1053-
) callconv(.C) void;
1117+
) callconv(.C) bool;

src/webui.zig

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const webui = @This();
1111

1212
const builtin = @import("builtin");
1313
const std = @import("std");
14+
const windows = std.os.windows;
1415

1516
const 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+
125132
pub 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.
140149
pub 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.
145164
pub 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()`.
162186
pub 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
232257
pub 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
244270
pub 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`
361399
pub 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.
392440
pub 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

Comments
 (0)