Skip to content

Commit 98ec4db

Browse files
mochalinsjinzhongjia
authored andcommitted
feat: Add setFileHandlerWindow, setMinimumSize
1 parent 5b69b95 commit 98ec4db

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

build.zig.zon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
.minimum_zig_version = "0.11.0",
55
.dependencies = .{
66
.webui = .{
7-
.url = "https://github.com/webui-dev/webui/archive/ead99700e99d25500f8a4a4b5ca9efcc6f28b47d.tar.gz",
8-
.hash = "122088eb8bdc74d983f96cc4a4f1ad80b1d78cdbb60b302047c40557bae95cc3c24f",
7+
.url = "https://github.com/webui-dev/webui/archive/cf0c54e.tar.gz",
8+
.hash = "1220aacf86c4580492e1ce126a611e034f2c8b402b2b4eff46b227b994548db2c2d7",
99
},
1010
},
1111
.paths = .{

src/webui.zig

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ pub fn setDefaultRootFolder(path: [:0]const u8) bool {
168168

169169
/// Set a custom handler to serve files. This custom handler should
170170
/// return full HTTP header and body.
171+
/// This deactivates any previous handler set with `setFileHandlerWindow`.
171172
pub fn setFileHandler(self: Self, comptime handler: fn (filename: []const u8) ?[]const u8) void {
172173
const tmp_struct = struct {
173174
fn handle(tmp_filename: [*c]const u8, length: [*c]c_int) callconv(.C) ?*const anyopaque {
@@ -184,6 +185,25 @@ pub fn setFileHandler(self: Self, comptime handler: fn (filename: []const u8) ?[
184185
WebUI.webui_set_file_handler(self.window_handle, tmp_struct.handle);
185186
}
186187

188+
/// Set a custom handler to serve files. This custom handler should
189+
/// return full HTTP header and body.
190+
/// This deactivates any previous handler set with `setFileHandler`.
191+
pub fn setFileHandlerWindow(self: Self, comptime handler: fn (window_handle: usize, filename: []const u8) ?[]const u8) void {
192+
const tmp_struct = struct {
193+
fn handle(window: usize, tmp_filename: [*c]const u8, length: [*c]c_int) callconv(.C) ?*const anyopaque {
194+
const len = str_len(tmp_filename);
195+
const content = handler(window, tmp_filename[0..len]);
196+
if (content) |val| {
197+
length.* = @intCast(val.len);
198+
return @ptrCast(val.ptr);
199+
}
200+
201+
return null;
202+
}
203+
};
204+
WebUI.webui_set_file_handler_window(self.window_handle, tmp_struct.handle);
205+
}
206+
187207
/// Check if the specified window is still running.
188208
pub fn isShown(self: Self) bool {
189209
return WebUI.webui_is_shown(self.window_handle);
@@ -252,6 +272,11 @@ pub fn setSize(self: Self, width: u32, height: u32) void {
252272
WebUI.webui_set_size(self.window_handle, @intCast(width), @intCast(height));
253273
}
254274

275+
/// Set the window minimum size.
276+
pub fn setMinimumSize(self: Self, width: u32, height: u32) void {
277+
WebUI.webui_set_minimum_size(self.window_handle, @intCast(width), @intCast(height));
278+
}
279+
255280
/// Set the window position.
256281
pub fn setPosition(self: Self, x: u32, y: u32) void {
257282
WebUI.webui_set_position(self.window_handle, @intCast(x), @intCast(y));

0 commit comments

Comments
 (0)