From: Olaf Wintermann Date: Wed, 1 Apr 2026 19:40:02 +0000 (+0200) Subject: implement some ui var types X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=4eb681b4c0e7804b5e052565374a4e665f66c94a;p=note.git implement some ui var types --- diff --git a/ui-rs/src/ui/ffi.rs b/ui-rs/src/ui/ffi.rs index a266786..4705175 100644 --- a/ui-rs/src/ui/ffi.rs +++ b/ui-rs/src/ui/ffi.rs @@ -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], diff --git a/ui-rs/src/ui/toolkit.rs b/ui-rs/src/ui/toolkit.rs index e9281a1..7d29052 100644 --- a/ui-rs/src/ui/toolkit.rs +++ b/ui-rs/src/ui/toolkit.rs @@ -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); + } + } +}