#[allow(unused_imports)]
use std::ffi::{c_char, c_int, c_void};
-use std::ffi::CString;
+use std::ffi::{CStr, CString};
use ui_rs_derive::{UiModel};
use crate::ui::{event, toolkit, EventWrapper};
use crate::ui::ffi::*;
}
}
+impl LinkButton {
+ pub fn set_label(&mut self, label: &str) {
+ let cstr = CString::new(label).unwrap();
+ unsafe {
+ ui_linkbutton_set_label(self.ptr, cstr.as_ptr());
+ }
+ }
+
+ pub fn set_uri(&mut self, uri: &str) {
+ let cstr = CString::new(uri).unwrap();
+ unsafe {
+ ui_linkbutton_set_uri(self.ptr, cstr.as_ptr());
+ }
+ }
+
+ pub fn set_visited(&mut self, visited: bool) {
+ unsafe {
+ ui_linkbutton_set_visited(self.ptr, visited as c_int);
+ }
+ }
+
+ pub fn get_label(&self) -> String {
+ unsafe {
+ let cstr_ptr = unsafe { ui_linkbutton_get_label(self.ptr) };
+ if cstr_ptr.is_null() {
+ return String::new();
+ }
+ let cstr = CStr::from_ptr(cstr_ptr);
+ let str = cstr.to_string_lossy().into_owned();
+ libc::free(cstr_ptr as *mut c_void);
+ str
+ }
+ }
+
+ pub fn get_uri(&self) -> String {
+ unsafe {
+ let cstr_ptr = unsafe { ui_linkbutton_get_uri(self.ptr) };
+ if cstr_ptr.is_null() {
+ return String::new();
+ }
+ let cstr = CStr::from_ptr(cstr_ptr);
+ let str = cstr.to_string_lossy().into_owned();
+ libc::free(cstr_ptr as *mut c_void);
+ str
+ }
+ }
+
+ pub fn get_visited(&self) -> bool {
+ unsafe {
+ ui_linkbutton_get_visited(self.ptr) != 0
+ }
+ }
+}
+
extern "C" {
fn ui_button_create(obj: *const UiObject, args: *const UiButtonArgs) -> *mut c_void;
fn ui_togglebutton_create(obj: *const UiObject, args: *const UiToggleArgs) -> *mut c_void;
fn ui_linkbutton_value_set_uri(str: *mut UiString, uri: *const c_char);
fn ui_linkbutton_value_set_visited(str: *mut UiString, visited: c_int);
+ fn ui_linkbutton_set_label(button: *mut c_void, label: *const c_char);
+ fn ui_linkbutton_set_uri(button: *mut c_void, uri: *const c_char);
+ fn ui_linkbutton_set_visited(button: *mut c_void, visited: c_int);
+ fn ui_linkbutton_get_label(button: *mut c_void) -> *mut c_char;
+ fn ui_linkbutton_get_uri(button: *mut c_void) -> *mut c_char;
+ fn ui_linkbutton_get_visited(button: *mut c_void) -> c_int;
}