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
76
77
78
79
80
use std::cell::Cell;
use std::ffi::CString;
use std::os::raw::c_char;
use newt_sys::*;
use crate::component::Component;
#[derive(Component)]
pub struct Textbox {
co: Cell<newtComponent>,
added_to_parent: Cell<bool>
}
impl Textbox {
pub fn new(left: i32, top: i32, width: i32, height: i32, flags: i32)
-> Textbox {
Textbox {
co: unsafe {
let co = newtTextbox(left, top, width, height, flags);
Cell::new(co)
},
added_to_parent: Cell::new(false)
}
}
pub fn new_reflowed(left: i32, top: i32, text: &str, width: i32,
flex_down: i32, flex_up: i32, flags: i32)
-> Textbox {
let c_text = CString::new(text).unwrap();
Textbox {
co: unsafe {
let co = newtTextboxReflowed(left, top,
c_text.as_ptr() as *mut c_char,
width, flex_down, flex_up,
flags);
Cell::new(co)
},
added_to_parent: Cell::new(false)
}
}
pub fn set_text(&self, text: &str) {
let c_text = CString::new(text).unwrap();
unsafe { newtTextboxSetText(self.co(), c_text.as_ptr()); }
}
pub fn set_height(&self, height: i32) {
unsafe { newtTextboxSetHeight(self.co(), height); }
}
pub fn get_num_lines(&self) -> i32 {
unsafe { newtTextboxGetNumLines(self.co()) }
}
pub fn set_colors(&self, normal: i32, active: i32) {
unsafe { newtTextboxSetColors(self.co(), normal, active); }
}
}