ui_text_set(self.ptr, cstr.as_ptr());
}
}
+
+ pub fn substring(&self, start: usize, end: usize) -> String {
+ unsafe {
+ let cstr = ui_text_getsubstr(self.ptr, start as c_int, end as c_int);
+ CStr::from_ptr(cstr)
+ .to_string_lossy()
+ .into_owned()
+ }
+ }
+
+ pub fn insert(&mut self, index: usize, value: &str) {
+ unsafe {
+ let cstr = CString::new(value).unwrap();
+ ui_text_insert(self.ptr, index as c_int, cstr.as_ptr());
+ }
+ }
+
+ pub fn replace(&mut self, begin: usize, end: usize, value: &str) {
+ unsafe {
+ let cstr = CString::new(value).unwrap();
+ ui_text_replace(self.ptr, begin as c_int, end as c_int, cstr.as_ptr());
+ }
+ }
+
+ pub fn position(&self) -> usize {
+ unsafe {
+ ui_text_position(self.ptr) as usize
+ }
+ }
+
+ pub fn set_position(&mut self, position: usize) {
+ unsafe {
+ ui_text_setposition(self.ptr, position as c_int);
+ }
+ }
+
+ pub fn show_position(&mut self, pos: usize) {
+ unsafe {
+ ui_text_showposition(self.ptr, pos as c_int);
+ }
+ }
+
+ pub fn selection(&self) -> (usize, usize) {
+ unsafe {
+ let mut begin = 0;
+ let mut end = 0;
+ ui_text_selection(self.ptr, &mut begin, &mut end);
+ (begin as usize, end as usize)
+ }
+ }
+
+ pub fn set_selection(&mut self, begin: usize, end: usize) {
+ unsafe {
+ ui_text_setselection(self.ptr, begin as c_int, end as c_int);
+ }
+ }
+
+ pub fn length(&self) -> usize {
+ unsafe {
+ ui_text_length(self.ptr) as usize
+ }
+ }
+
+ pub fn remove(&mut self, begin: usize, end: usize) {
+ unsafe {
+ ui_text_remove(self.ptr, begin as c_int, end as c_int);
+ }
+ }
}
impl UiString {
fn ui_list_getselection(list: *const ffi::UiList) -> c_int;
fn ui_list_setselection(list: *mut ffi::UiList, selection: c_int);
fn ui_list_setselection2(list: *mut ffi::UiList, selection: c_int, event: c_int);
+
+ fn ui_text_getsubstr(text: *const ffi::UiText, begin: c_int, end: c_int) -> *const c_char;
+ fn ui_text_insert(text: *mut ffi::UiText, pos: c_int, str: *const c_char);
+ fn ui_text_replace(text: *mut ffi::UiText, begin: c_int, end: c_int, str: *const c_char);
+ fn ui_text_setposition(text: *mut ffi::UiText, pos: c_int);
+ fn ui_text_position(text: *const ffi::UiText) -> c_int;
+ fn ui_text_showposition(text: *mut ffi::UiText, pos: c_int);
+ fn ui_text_setselection(text: *mut ffi::UiText, begin: c_int, end: c_int);
+ fn ui_text_selection(text: *const ffi::UiText, begin: *mut c_int, end: *mut c_int);
+ fn ui_text_length(text: *const ffi::UiText) -> c_int;
+ fn ui_text_remove(text: *mut ffi::UiText, begin: c_int, end: c_int);
}
void ui_list_class_set_iter(UiList *list, void *iter) {
list->iter = iter;
}
+
+/* ---------------- Text functions ---------------- */
+
+char* ui_text_getsubstr(UiText *text, int begin, int end) {
+ if(text->getsubstr) {
+ text->getsubstr(text, begin, end);
+ } else {
+ return NULL;
+ }
+}
+
+void ui_text_insert(UiText *text, int pos, const char *str) {
+ if(text->insert) {
+ text->insert(text, pos, str);
+ }
+}
+
+void ui_text_replace(UiText *text, int begin, int end, const char *str) {
+ if(text->replace) {
+ text->replace(text, begin, end, str);
+ }
+}
+
+void ui_text_setposition(UiText *text, int pos) {
+ if(text->setposition) {
+ text->setposition(text, pos);
+ }
+}
+
+int ui_text_position(UiText *text) {
+ if(text->position) {
+ return text->position(text);
+ } else {
+ return 0;
+ }
+}
+
+void ui_text_showposition(UiText *text, int pos) {
+ if(text->showposition) {
+ text->showposition(text, pos);
+ }
+}
+
+void ui_text_setselection(UiText *text, int begin, int end) {
+ if(text->setselection) {
+ text->setselection(text, begin, end);
+ }
+}
+
+void ui_text_selection(UiText *text, int *begin, int *end) {
+ if(text->selection) {
+ text->selection(text, begin, end);
+ } else {
+ if(begin) {
+ *begin = 0;
+ }
+ if(end) {
+ *end = 0;
+ }
+ }
+}
+
+int ui_text_length(UiText *text) {
+ if(text->length) {
+ return text->length(text);
+ } else {
+ return 0;
+ }
+}
+void ui_text_remove(UiText *text, int begin, int end) {
+ if(text->remove) {
+ text->remove(text, begin, end);
+ }
+}
UIEXPORT void ui_add_image(char *imgname, char *filename); // TODO: remove?
-
+UIEXPORT char* ui_text_getsubstr(UiText *text, int begin, int end);
+UIEXPORT void ui_text_insert(UiText *text, int pos, const char *str);
+UIEXPORT void ui_text_replace(UiText *text, int begin, int end, const char *str);
+UIEXPORT void ui_text_setposition(UiText *text, int pos);
+UIEXPORT int ui_text_position(UiText *text);
+UIEXPORT void ui_text_showposition(UiText *text, int pos);
+UIEXPORT void ui_text_setselection(UiText *text, int begin, int end);
+UIEXPORT void ui_text_selection(UiText *text, int *begin, int *end);
+UIEXPORT int ui_text_length(UiText *text);
+UIEXPORT void ui_text_remove(UiText *text, int begin, int end);
UIEXPORT UiStr ui_str(char *cstr);
UIEXPORT UiStr ui_str_free(char *str, void (*free)(void *v));