use super::enums::{DataViewAlign, DataViewColumnFlags};
use super::renderer::DataViewRenderer;
use std::ffi::CString;
use wxdragon_sys as ffi;
pub struct DataViewColumn {
handle: *mut ffi::wxd_DataViewColumn_t,
}
impl DataViewColumn {
pub fn new(
title: &str,
renderer: &dyn DataViewRenderer,
model_column: usize,
width: i32,
align: DataViewAlign,
flags: DataViewColumnFlags,
) -> Self {
let title_cstr = CString::new(title).unwrap();
let handle = unsafe {
ffi::wxd_DataViewColumn_Create(
title_cstr.as_ptr(),
renderer.as_raw(),
model_column as i32, width,
align.bits() as i32, flags.bits() as i32, )
};
Self { handle }
}
pub unsafe fn from_ptr(ptr: *mut ffi::wxd_DataViewColumn_t) -> Self {
Self { handle: ptr }
}
pub fn as_raw(&self) -> *mut ffi::wxd_DataViewColumn_t {
self.handle
}
pub fn set_title(&self, title: &str) {
let title_cstr = CString::new(title).unwrap_or_default();
unsafe {
ffi::wxd_DataViewColumn_SetTitle(self.handle, title_cstr.as_ptr());
}
}
pub fn set_resizeable(&self, resizeable: bool) {
unsafe {
ffi::wxd_DataViewColumn_SetResizeable(self.handle, resizeable);
}
}
pub fn is_resizeable(&self) -> bool {
unsafe { ffi::wxd_DataViewColumn_IsResizeable(self.handle) }
}
pub fn set_sortable(&self, sortable: bool) {
unsafe {
ffi::wxd_DataViewColumn_SetSortable(self.handle, sortable);
}
}
pub fn is_sortable(&self) -> bool {
unsafe { ffi::wxd_DataViewColumn_IsSortable(self.handle) }
}
}