]> uap-core.de Git - note.git/commitdiff
implement some ui var types
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 1 Apr 2026 19:40:02 +0000 (21:40 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 1 Apr 2026 19:40:02 +0000 (21:40 +0200)
ui-rs/src/ui/ffi.rs
ui-rs/src/ui/toolkit.rs

index a266786ceacfa0a857d6724eb3951e47d7e2dbda..47051759a833b9a289497036dc76e4faf70cc3e4 100644 (file)
@@ -18,6 +18,10 @@ pub struct UiEvent {
     _private: [u8; 0],
 }
 
+#[repr(C)]
+pub struct UiText {
+    _private: [u8; 0],
+}
 #[repr(C)]
 pub struct UiString {
     _private: [u8; 0],
index e9281a1aa5acad5b96e4dc311bbcc58c46c9efbd..7d29052d4c4beff6676f84a6c561a1469d47ea00 100644 (file)
@@ -1,14 +1,37 @@
 #![allow(dead_code)]
 
-use std::ffi::{c_char, c_int, CString};
+use std::ffi::{c_char, c_int, CStr, CString};
 use crate::ui::ffi;
 
 pub struct UiObject {
     pub ptr: *const ffi::UiObject
 }
 
+pub struct UiText {
+    pub ptr: *const ffi::UiText
+}
+
+pub struct UiString {
+    pub ptr: *const ffi::UiString
+}
+
+pub struct UiInteger {
+    pub ptr: *const ffi::UiInteger
+}
+
+pub struct UiDouble {
+    pub ptr: *const ffi::UiDouble
+}
+
 extern "C" {
     fn ui_init(appname: *const c_char, argc: c_int, argv: *const *const c_char);
+
+    fn ui_text_get(value: *const ffi::UiText) -> *mut c_char;
+    fn ui_text_set(value: *const ffi::UiText, str: *const c_char);
+    fn ui_string_get(value: *const ffi::UiString) -> *mut c_char;
+    fn ui_string_set(value: *const ffi::UiString, str: *const c_char);
+    fn ui_int_get(value: *const ffi::UiInteger) -> i64;
+    fn ui_int_set(value: *const ffi::UiInteger, i: i64);
 }
 
 pub fn app_init(appname: &str) {
@@ -24,3 +47,53 @@ pub fn app_init(appname: &str) {
         ui_init(c_str, 0, std::ptr::null());
     }
 }
+
+impl UiText {
+    pub fn get(&self) -> String {
+        unsafe {
+            let cstr = ui_text_get(self.ptr);
+            CStr::from_ptr(cstr)
+                .to_string_lossy()
+                .into_owned()
+        }
+    }
+
+    pub fn set(&mut self, value: &str) {
+        let cstr = CString::new(value).unwrap();
+        unsafe {
+            ui_text_set(self.ptr, cstr.as_ptr());
+        }
+    }
+}
+
+impl UiString {
+    pub fn get(&self) -> String {
+        unsafe {
+            let cstr = ui_string_get(self.ptr);
+            CStr::from_ptr(cstr)
+                .to_string_lossy()
+                .into_owned()
+        }
+    }
+
+    pub fn set(&mut self, value: &str) {
+        let cstr = CString::new(value).unwrap();
+        unsafe {
+            ui_string_set(self.ptr, cstr.as_ptr());
+        }
+    }
+}
+
+impl UiInteger {
+    pub fn get(&self) -> i64 {
+        unsafe {
+            ui_int_get(self.ptr)
+        }
+    }
+
+    pub fn set(&mut self, value: i64) {
+        unsafe {
+            ui_int_set(self.ptr, value);
+        }
+    }
+}