]> uap-core.de Git - note.git/commitdiff
implement LinkButton methods main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 4 May 2026 19:40:53 +0000 (21:40 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 4 May 2026 19:40:53 +0000 (21:40 +0200)
ui-rs/src/ui/button.rs

index c4795e14c9a42e21d7af730489cac934513219db..887fb05c10085faade1a11d77b37d12cb9bca8ee 100644 (file)
@@ -30,7 +30,7 @@
 #[allow(unused_imports)]
 
 use std::ffi::{c_char, c_int, c_void};
-use std::ffi::CString;
+use std::ffi::{CStr, CString};
 use ui_rs_derive::{UiModel};
 use crate::ui::{event, toolkit, EventWrapper};
 use crate::ui::ffi::*;
@@ -767,6 +767,60 @@ pub fn link_set_visited(value: &toolkit::UiString, visited: bool) {
     }
 }
 
+impl LinkButton {
+    pub fn set_label(&mut self, label: &str) {
+        let cstr = CString::new(label).unwrap();
+        unsafe {
+            ui_linkbutton_set_label(self.ptr, cstr.as_ptr());
+        }
+    }
+
+    pub fn set_uri(&mut self, uri: &str) {
+        let cstr = CString::new(uri).unwrap();
+        unsafe {
+            ui_linkbutton_set_uri(self.ptr, cstr.as_ptr());
+        }
+    }
+
+    pub fn set_visited(&mut self, visited: bool) {
+        unsafe {
+            ui_linkbutton_set_visited(self.ptr, visited as c_int);
+        }
+    }
+
+    pub fn get_label(&self) -> String {
+        unsafe {
+            let cstr_ptr = unsafe { ui_linkbutton_get_label(self.ptr) };
+            if cstr_ptr.is_null() {
+                return String::new();
+            }
+            let cstr = CStr::from_ptr(cstr_ptr);
+            let str = cstr.to_string_lossy().into_owned();
+            libc::free(cstr_ptr as *mut c_void);
+            str
+        }
+    }
+
+    pub fn get_uri(&self) -> String {
+        unsafe {
+            let cstr_ptr = unsafe { ui_linkbutton_get_uri(self.ptr) };
+            if cstr_ptr.is_null() {
+                return String::new();
+            }
+            let cstr = CStr::from_ptr(cstr_ptr);
+            let str = cstr.to_string_lossy().into_owned();
+            libc::free(cstr_ptr as *mut c_void);
+            str
+        }
+    }
+
+    pub fn get_visited(&self) -> bool {
+        unsafe {
+            ui_linkbutton_get_visited(self.ptr) != 0
+        }
+    }
+}
+
 extern "C" {
     fn ui_button_create(obj: *const UiObject, args: *const UiButtonArgs) -> *mut c_void;
     fn ui_togglebutton_create(obj: *const UiObject, args: *const UiToggleArgs) -> *mut c_void;
@@ -867,4 +921,10 @@ extern "C" {
     fn ui_linkbutton_value_set_uri(str: *mut UiString, uri: *const c_char);
     fn ui_linkbutton_value_set_visited(str: *mut UiString, visited: c_int);
 
+    fn ui_linkbutton_set_label(button: *mut c_void, label: *const c_char);
+    fn ui_linkbutton_set_uri(button: *mut c_void, uri: *const c_char);
+    fn ui_linkbutton_set_visited(button: *mut c_void, visited: c_int);
+    fn ui_linkbutton_get_label(button: *mut c_void) -> *mut c_char;
+    fn ui_linkbutton_get_uri(button: *mut c_void) -> *mut c_char;
+    fn ui_linkbutton_get_visited(button: *mut c_void) -> c_int;
 }