#![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) {
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);
+ }
+ }
+}