1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
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); }
}
}
|