]> uap-core.de Git - note.git/commitdiff
add webview bindings
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 1 Aug 2026 07:10:56 +0000 (09:10 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 1 Aug 2026 07:10:56 +0000 (09:10 +0200)
application/backend/src/backend.rs
application/note/src/notebook.rs
ui-rs/src/ui/ffi.rs
ui-rs/src/ui/mod.rs
ui-rs/src/ui/webview.rs [new file with mode: 0644]

index 5faf6421e0881e988fff4c82e9f55000acb4cbd8..2e46450332ddad99c92b9fb320c3325d203e8761 100644 (file)
@@ -814,7 +814,7 @@ impl BackendHandle {
                         from_collection_id,
                         to_collection_id: trash_id
                     };
-                    backend.send_broadcast(BroadcastMessage::NoteMoved(event));
+                    let _ = backend.send_broadcast(BroadcastMessage::NoteMoved(event));
                     
                     Ok(())
                 } else {
index 9590fb96033eaae83cd0287f72bd6b151e7feb9a..0ed22692cd87bb7d75904fb7bba533ecc62142fa 100644 (file)
@@ -419,7 +419,7 @@ impl Notebook {
             NoteId::Id(id) => {
                 let proxy = doc.doc_proxy();
                 self.backend.move_note_to_trash(self.collection_id, id, |result| {
-                    proxy.call_mainthread(|_doc, nb| {
+                    proxy.call_mainthread(|_doc, _nb| {
                         // in case the deletion was successful, a NoteMoved event is sent to
                         // all notebooks
                         if let Err(e) = result {
index 2fc9ab647a8b6ce2fb771059e5a424ad521808fa..1f9579f689482027297235098178c258bade79d5 100644 (file)
@@ -250,4 +250,9 @@ pub struct UiToolbarMenuArgs {
 #[repr(C)]
 pub struct UiImageViewerArgs {
     _private: [u8; 0],
-}
\ No newline at end of file
+}
+
+#[repr(C)]
+pub struct UiWebviewArgs {
+    _private: [u8; 0],
+}
index 338d46377288ffe9effdeb82654f09db945ae56b..78679e1001243ee7368b85b4949e6d7eca3c40d1 100644 (file)
@@ -41,6 +41,7 @@ mod toolbar;
 mod label;
 mod icon;
 mod image;
+mod webview;
 
 pub use toolkit::*;
 pub use event::*;
diff --git a/ui-rs/src/ui/webview.rs b/ui-rs/src/ui/webview.rs
new file mode 100644 (file)
index 0000000..1ddaa9d
--- /dev/null
@@ -0,0 +1,246 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2026 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#![allow(dead_code)]
+
+pub struct WebView {
+    ptr: *mut c_void
+}
+
+impl Widget for WebView {
+    fn get_widget(&self) -> *mut c_void {
+        self.ptr
+    }
+}
+
+pub struct WebViewBuilder<'a, T> {
+    args: *mut UiWebviewArgs,
+    obj: &'a mut toolkit::UiObject<T>,
+}
+
+impl<'a, T> Drop for WebViewBuilder<'a, T> {
+    fn drop(&mut self) {
+        unsafe {
+            ui_webview_args_free(self.args);
+        }
+    }
+}
+
+impl<'a, T> WebViewBuilder<'a, T> {
+    pub fn create(&mut self) -> WebView {
+        WebView { ptr: unsafe { ui_webview_create(self.obj.ptr, self.args) } }
+    }
+
+    pub fn fill(&mut self, fill: bool) -> &mut Self {
+        unsafe {
+            ui_webview_args_set_fill(self.args, fill as c_int);
+        }
+        self
+    }
+
+    pub fn hexpand(&mut self, value: bool) -> &mut Self {
+        unsafe {
+            ui_webview_args_set_hexpand(self.args, value as c_int);
+        }
+        self
+    }
+
+    pub fn vexpand(&mut self, value: bool) -> &mut Self {
+        unsafe {
+            ui_webview_args_set_vexpand(self.args, value as c_int);
+        }
+        self
+    }
+
+    pub fn hfill(&mut self, value: bool) -> &mut Self {
+        unsafe {
+            ui_webview_args_set_hfill(self.args, value as c_int);
+        }
+        self
+    }
+
+    pub fn vfill(&mut self, value: bool) -> &mut Self {
+        unsafe {
+            ui_webview_args_set_vfill(self.args, value as c_int);
+        }
+        self
+    }
+
+    pub fn override_defaults(&mut self, value: bool) -> &mut Self {
+        unsafe {
+            ui_webview_args_set_override_defaults(self.args, value as c_int);
+        }
+        self
+    }
+
+    pub fn margin(&mut self, value: i32) -> &mut Self {
+        unsafe {
+            ui_webview_args_set_margin(self.args, value);
+        }
+        self
+    }
+
+    pub fn margin_left(&mut self, value: i32) -> &mut Self {
+        unsafe {
+            ui_webview_args_set_margin_left(self.args, value);
+        }
+        self
+    }
+
+    pub fn margin_right(&mut self, value: i32) -> &mut Self {
+        unsafe {
+            ui_webview_args_set_margin_right(self.args, value);
+        }
+        self
+    }
+
+    pub fn margin_top(&mut self, value: i32) -> &mut Self {
+        unsafe {
+            ui_webview_args_set_margin_top(self.args, value);
+        }
+        self
+    }
+
+    pub fn margin_bottom(&mut self, value: i32) -> &mut Self {
+        unsafe {
+            ui_webview_args_set_margin_bottom(self.args, value);
+        }
+        self
+    }
+
+    pub fn colspan(&mut self, value: i32) -> &mut Self {
+        unsafe {
+            ui_webview_args_set_colspan(self.args, value);
+        }
+        self
+    }
+
+    pub fn rowspan(&mut self, value: i32) -> &mut Self {
+        unsafe {
+            ui_webview_args_set_rowspan(self.args, value);
+        }
+        self
+    }
+
+    pub fn name(&mut self, value: &str) -> &mut Self {
+        let cstr = CString::new(value).unwrap();
+        unsafe {
+            ui_webview_args_set_name(self.args, cstr.as_ptr());
+        }
+        self
+    }
+
+    pub fn style_class(&mut self, value: &str) -> &mut Self {
+        let cstr = CString::new(value).unwrap();
+        unsafe {
+            ui_webview_args_set_style_class(self.args, cstr.as_ptr());
+        }
+        self
+    }
+
+    pub fn value(&mut self, value: &toolkit::UiImage) -> &mut Self{
+        unsafe {
+            ui_webview_args_set_value(self.args, value.ptr);
+        }
+        self
+    }
+
+    pub fn varname(&mut self, varname: &str) -> &mut Self {
+        let cstr = CString::new(varname).unwrap();
+        unsafe {
+            ui_webview_args_set_varname(self.args, cstr.as_ptr());
+        }
+        self
+    }
+
+    pub fn visibility_states(&mut self, states: &[i32]) -> &mut Self {
+        unsafe {
+            ui_webview_args_set_visibility_states(self.args, states.as_ptr(), states.len() as c_int);
+        }
+        self
+    }
+
+    pub fn states(&mut self, states: &[i32]) -> &mut Self {
+        unsafe {
+            ui_webview_args_set_states(self.args, states.as_ptr(), states.len() as c_int);
+        }
+        self
+    }
+}
+
+impl<T> toolkit::UiObject<T> {
+    pub fn webview<'a>(&'a mut self) -> WebViewBuilder<'a, T> {
+        unsafe {
+            let args = ui_webview_args_new();
+            WebViewBuilder { args: args, obj: self }
+        }
+    }
+}
+
+/* -------------------------------- C functions -------------------------------- */
+use std::ffi::{c_char, c_double, c_int, c_void, CString};
+use crate::ui::{ffi, toolkit};
+use crate::ui::ffi::UiWebviewArgs;
+use crate::ui::widget::Widget;
+
+unsafe extern "C" {
+    fn ui_webview_reload(obj: *mut ffi::UiGeneric);
+    fn ui_webview_can_go_back(obj: *mut ffi::UiGeneric) -> c_int;
+    fn ui_webview_can_go_forward(obj: *mut ffi::UiGeneric) -> c_int;
+    fn ui_webview_go_back(obj: *mut ffi::UiGeneric);
+    fn ui_webview_go_forward(obj: *mut ffi::UiGeneric);
+    fn ui_webview_get_uri(obj: *mut ffi::UiGeneric) -> *const c_char;
+    fn ui_webview_enable_javascript(obj: *mut ffi::UiGeneric, enable: c_int);
+    fn ui_webview_set_zoom(obj: *mut ffi::UiGeneric, zoom: c_double);
+    fn ui_webview_get_zoom(obj: *mut ffi::UiGeneric) -> c_double;
+
+    fn ui_webview_create(obj: *mut ffi::UiObject, args: *const ffi::UiWebviewArgs) -> *mut c_void;
+
+    fn ui_webview_args_new() -> *mut UiWebviewArgs;
+    fn ui_webview_args_set_fill(args: *mut UiWebviewArgs, fill: c_int);
+    fn ui_webview_args_set_hexpand(args: *mut UiWebviewArgs, value: c_int);
+    fn ui_webview_args_set_vexpand(args: *mut UiWebviewArgs, value: c_int);
+    fn ui_webview_args_set_hfill(args: *mut UiWebviewArgs, value: c_int);
+    fn ui_webview_args_set_vfill(args: *mut UiWebviewArgs, value: c_int);
+    fn ui_webview_args_set_override_defaults(args: *mut UiWebviewArgs, value: c_int);
+    fn ui_webview_args_set_margin(args: *mut UiWebviewArgs, value: c_int);
+    fn ui_webview_args_set_margin_left(args: *mut UiWebviewArgs, value: c_int);
+    fn ui_webview_args_set_margin_right(args: *mut UiWebviewArgs, value: c_int);
+    fn ui_webview_args_set_margin_top(args: *mut UiWebviewArgs, value: c_int);
+    fn ui_webview_args_set_margin_bottom(args: *mut UiWebviewArgs, value: c_int);
+    fn ui_webview_args_set_colspan(args: *mut UiWebviewArgs, value: c_int);
+    fn ui_webview_args_set_rowspan(args: *mut UiWebviewArgs, value: c_int);
+    fn ui_webview_args_set_name(args: *mut UiWebviewArgs, name: *const c_char);
+    fn ui_webview_args_set_style_class(args: *mut UiWebviewArgs, classname: *const c_char);
+    fn ui_webview_args_set_style(args: *mut UiWebviewArgs, style: c_int);
+    fn ui_webview_args_set_value(args: *mut UiWebviewArgs, value: *mut ffi::UiGeneric);
+    fn ui_webview_args_set_varname(args: *mut UiWebviewArgs, varname: *const c_char);
+    fn ui_webview_args_set_states(args: *mut UiWebviewArgs, states: *const c_int, numstates: c_int);
+    fn ui_webview_args_set_visibility_states(args: *mut UiWebviewArgs, states: *const c_int, numstates: c_int);
+    fn ui_webview_args_free(args: *mut UiWebviewArgs);
+}