Skip to content

Commit

Permalink
Merge pull request #6 from SpikeHD/filling_gaps
Browse files Browse the repository at this point in the history
Introduce missing functionality
  • Loading branch information
neroist authored Mar 29, 2024
2 parents 1c02aa0 + 8a0d2d7 commit 5cd79d4
Showing 1 changed file with 50 additions and 3 deletions.
53 changes: 50 additions & 3 deletions src/webui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ impl WebUIBrowser {

// Impl equality operator
impl PartialEq for WebUIBrowser {
fn eq(&self, other: &Self) -> bool {
self.to_usize() == other.to_usize()
}
fn eq(&self, other: &Self) -> bool {
self.to_usize() == other.to_usize()
}
}

// Runtimes
Expand Down Expand Up @@ -176,6 +176,21 @@ impl Window {
js
}

pub fn set_icon(&self, icon: impl AsRef<str>, kind: impl AsRef<str>) {
set_icon(self.id, icon.as_ref(), kind.as_ref());
}

pub fn set_file_handler(
&self,
handler: unsafe extern "C" fn(*const i8, *mut i32) -> *const std::os::raw::c_void,
) {
set_file_handler(self.id, handler);
}

pub fn set_runtime(&self, runtime: WebUIRuntime) {
set_runtime(self.id, runtime);
}

pub fn close(&self) {
close(self.id);
}
Expand Down Expand Up @@ -298,6 +313,12 @@ pub fn wait() {
}
}

pub fn set_timeout(seconds: usize) {
unsafe {
webui_set_timeout(seconds);
}
}

pub fn exit() {
unsafe {
webui_exit();
Expand Down Expand Up @@ -329,6 +350,23 @@ pub fn is_shown(win: usize) -> bool {
unsafe { webui_is_shown(win) }
}

pub fn set_icon(win: usize, icon: &str, kind: &str) {
let icon_c_str = CString::new(icon).unwrap();
let kind_c_str = CString::new(kind).unwrap();
let icon_c_char: *const c_char = icon_c_str.as_ptr() as *const c_char;
let kind_c_char: *const c_char = kind_c_str.as_ptr() as *const c_char;

unsafe {
webui_set_icon(win, icon_c_char, kind_c_char);
}
}

pub fn set_runtime(win: usize, runtime: WebUIRuntime) {
unsafe {
webui_set_runtime(win, runtime as usize);
}
}

pub fn close(win: usize) {
unsafe {
webui_close(win);
Expand Down Expand Up @@ -409,3 +447,12 @@ pub fn bind(win: usize, element: &str, func: fn(Event)) {
GLOBAL_ARRAY[window_id_64][element_index_64] = GlobalArray::Some(func as FunctionType);
}
}

pub fn set_file_handler(
win: usize,
handler: unsafe extern "C" fn(*const i8, *mut i32) -> *const std::os::raw::c_void,
) {
unsafe {
webui_set_file_handler(win, Some(handler));
}
}

0 comments on commit 5cd79d4

Please sign in to comment.