-use std::path::Path;
-use std::fs;
-
fn main() {
- let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
- let lib_dir = Path::new(&manifest_dir).join("../build/lib");
- let config_mk = Path::new(&manifest_dir).join("../config.mk");
-
- println!("cargo:rustc-link-search=native={}", lib_dir.display());
- println!("cargo:rustc-link-lib=static=uitk");
- println!("cargo:rustc-link-lib=static=ucx");
- let content = fs::read_to_string(&config_mk)
- .expect(&format!("Failed to read {}", config_mk.display()));
- for line in content.lines() {
- if line.starts_with("TK_LDFLAGS") {
- let parts: Vec<&str> = line.split_whitespace().collect();
- for token in &parts[2..] {
- if let Some(lib) = token.strip_prefix("-l") {
- println!("cargo:rustc-link-lib={}", lib);
- } else if token.starts_with("-L") {
- let path = &token[2..];
- println!("cargo:rustc-link-search=native={}", path);
- } else if token.starts_with("-R") {
- let path = &token[2..];
- println!("cargo:rustc-link-arg=-Wl,-rpath,{}", path);
- } else {
- println!("cargo:rustc-link-arg={}", token);
- }
- }
- }
- }
}
+use ui_rs::ui;
fn main() {
+ ui::app_init(Default::default());
+ ui::app_main();
}
+use std::path::Path;
+use std::fs;
+
fn main() {
+ let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
+ let lib_dir = Path::new(&manifest_dir).join("../build/lib");
+ let config_mk = Path::new(&manifest_dir).join("../config.mk");
+
+ println!("cargo:rustc-link-search=native={}", lib_dir.display());
+ println!("cargo:rustc-link-lib=static=uitk");
+ println!("cargo:rustc-link-lib=static=ucx");
-}
\ No newline at end of file
+ // read the toolkit linker flags from the config.mk file
+ let content = fs::read_to_string(&config_mk)
+ .expect(&format!("Failed to read {}", config_mk.display()));
+ for line in content.lines() {
+ if line.starts_with("TK_LDFLAGS += ") || line.starts_with("TK_LDFLAGS = ") {
+ let parts: Vec<&str> = line.split_whitespace().collect();
+ for token in &parts[2..] {
+ if let Some(lib) = token.strip_prefix("-l") {
+ println!("cargo:rustc-link-lib={}", lib);
+ } else if token.starts_with("-L") {
+ let path = &token[2..];
+ println!("cargo:rustc-link-search=native={}", path);
+ } else if token.starts_with("-R") {
+ let path = &token[2..];
+ println!("cargo:rustc-link-arg=-Wl,-rpath,{}", path);
+ } else {
+ println!("cargo:rustc-link-arg={}", token);
+ }
+ }
+ }
+ }
+}
--- /dev/null
+#![allow(dead_code)]
+
+use std::ffi::c_void;
+
+
+#[repr(C)]
+pub struct UiContext {
+ _private: [u8; 0],
+}
+
+#[repr(C)]
+pub struct UiObject {
+ _private: [u8; 0],
+}
+
+#[repr(C)]
+pub struct UiEvent {
+ _private: [u8; 0],
+}
+
+#[repr(C)]
+pub struct UiString {
+ _private: [u8; 0],
+}
+
+#[repr(C)]
+pub struct UiInteger {
+ _private: [u8; 0],
+}
+
+#[repr(C)]
+pub struct UiDouble {
+ _private: [u8; 0],
+}
+
+#[repr(C)]
+pub struct UiRange {
+ _private: [u8; 0],
+}
+
+#[repr(C)]
+pub struct UiList {
+ _private: [u8; 0],
+}
+
+pub type UiCallback = Option<extern "C" fn(event: *const UiEvent, *mut c_void)>;
+
--- /dev/null
+mod ffi;
+mod toolkit;
+
+pub use toolkit::*;
\ No newline at end of file
--- /dev/null
+#![allow(dead_code)]
+
+use std::ffi::{c_char, c_int, c_void, CString};
+use super::ffi::*;
+
+extern "C" {
+ fn ui_init(appname: *const c_char, argc: c_int, argv: *const *const c_char);
+ fn ui_main();
+
+ fn ui_onstartup(callback: UiCallback, userdata: *mut c_void);
+}
+
+pub fn app_init(appname: &str) {
+ unsafe {
+ let c_str = if appname.len() > 0 {
+ let s = CString::new(appname).unwrap();
+ s.as_ptr()
+ } else {
+ std::ptr::null()
+ };
+ ui_init(c_str, 0, std::ptr::null());
+ }
+}
+
+pub fn app_main() {
+ unsafe {
+ ui_main();
+ }
+}
+
+pub fn onstartup(callback: UiCallback) {
+ unsafe {
+ ui_onstartup(callback, std::ptr::null_mut());
+ }
+}