use crate::event::WxEvtHandler;
use crate::geometry::{Point, Size};
use crate::id::Id;
use crate::window::{WindowHandle, WxWidget};
use std::ffi::CString;
use std::os::raw::c_int;
use wxdragon_sys as ffi;
widget_style_enum!(
name: StaticLineStyle,
doc: "Style flags for StaticLine.",
variants: {
Default: ffi::WXD_HORIZONTAL, "Default style (horizontal line).",
Vertical: ffi::WXD_VERTICAL, "Vertical line."
},
default_variant: Default
);
#[derive(Clone, Copy)]
pub struct StaticLine {
handle: WindowHandle,
}
impl StaticLine {
pub fn builder<W: WxWidget>(parent: &W) -> StaticLineBuilder<'_> {
StaticLineBuilder::new(parent)
}
pub fn window_handle(&self) -> WindowHandle {
self.handle
}
}
impl WxWidget for StaticLine {
fn handle_ptr(&self) -> *mut ffi::wxd_Window_t {
self.handle.get_ptr().unwrap_or(std::ptr::null_mut())
}
fn is_valid(&self) -> bool {
self.handle.is_valid()
}
}
impl WxEvtHandler for StaticLine {
unsafe fn get_event_handler_ptr(&self) -> *mut ffi::wxd_EvtHandler_t {
self.handle.get_ptr().unwrap_or(std::ptr::null_mut()) as *mut ffi::wxd_EvtHandler_t
}
}
impl crate::event::WindowEvents for StaticLine {}
widget_builder!(
name: StaticLine,
parent_type: &'a dyn WxWidget,
style_type: StaticLineStyle,
fields: {
name: String = "staticLine".to_string()
},
build_impl: |slf| {
let c_name = CString::new(slf.name.as_str()).expect("CString::new failed for name");
let ptr = unsafe {
ffi::wxd_StaticLine_Create(
slf.parent.handle_ptr(),
slf.id as c_int,
slf.pos.into(),
slf.size.into(),
slf.style.bits() as ffi::wxd_Style_t,
c_name.as_ptr(),
)
};
if ptr.is_null() {
panic!("wxd_StaticLine_Create returned null");
}
StaticLine {
handle: WindowHandle::new(ptr as *mut ffi::wxd_Window_t),
}
}
);
#[cfg(feature = "xrc")]
impl crate::xrc::XrcSupport for StaticLine {
unsafe fn from_xrc_ptr(ptr: *mut ffi::wxd_Window_t) -> Self {
StaticLine {
handle: WindowHandle::new(ptr),
}
}
}
impl crate::window::FromWindowWithClassName for StaticLine {
fn class_name() -> &'static str {
"wxStaticLine"
}
unsafe fn from_ptr(ptr: *mut ffi::wxd_Window_t) -> Self {
StaticLine {
handle: WindowHandle::new(ptr),
}
}
}