use std::ptr; use crate::bindings; pub struct Log { ptr: *mut bindings::Logwidget, } pub struct LogBuilder<'a> { lefttop: (u32, u32), size: (u32, u32), title: Option<&'a str>, timestamps: bool, } impl<'a> LogBuilder<'a> { pub fn add_title<'s: 'a>(&'a mut self, title: &'s str) -> &'a mut LogBuilder<'a> { self.title = Some(title); self } pub fn set_timestamps(&'a mut self, timestamps: bool) -> &'a mut LogBuilder<'a> { self.timestamps = timestamps; self } pub fn create(&self) -> Log { Log { ptr: unsafe { bindings::lgw_make( self.lefttop.0 as i32, self.lefttop.1 as i32, self.size.0 as i32, self.size.1 as i32, match self.title { None => ptr::null(), Some(s) => s.as_ptr() as *const i8, }, self.timestamps) } } } } impl Log { pub fn new<'a>(lefttop: (u32, u32), size: (u32, u32)) -> LogBuilder<'a> { LogBuilder { lefttop, size, title: None, timestamps: false, } } pub fn redraw(&self) { unsafe { bindings::lgw_redraw(self.ptr); } } pub fn add(&mut self, line: &str) { unsafe { bindings::lgw_add(self.ptr, line.as_ptr() as *const i8); } } pub fn clear(&mut self) { unsafe { bindings::lgw_clear(self.ptr); } } pub fn change_title(&mut self, title: &str) { unsafe { bindings::lgw_changetitle(self.ptr, title.as_ptr() as *const i8); } } } impl Drop for Log { fn drop(&mut self) { unsafe { bindings::lgw_destroy(self.ptr); } } }