ncurses_rs/window/mod.rs
1use ::context::Context;
2
3pub struct Window {
4 /// the height of the window in characters
5 height: u64,
6 /// the width of the window in characters
7 width: u64,
8 /// the x-coordinate that the window starts at
9 x: u64,
10 /// the y-coordinate that the window starts at
11 y: u64,
12 /// the pointer to the actual window in memory
13 pub ptr: *const u64
14}
15
16#[link(name="ncurses")]
17extern {
18 fn newwin(lines: u64, cols: u64, x: u64, y: u64) -> *const u64;
19 fn delwin(ptr: *const u64);
20 fn wrefresh(ptr: *const u64);
21}
22
23impl Window {
24 /// Create a window and add it to the specified windowing context
25 /// # Arguments
26 ///
27 /// * `name` - the name to register the window under
28 /// * `height` - the height of the window
29 /// * `width` - the width of the window
30 /// * `x` - the starting x coordinate
31 /// * `y` - the starting y coordinate
32 /// * `context` - the ncurses context to create a window for
33 pub fn create_win(name: String, height:u64, width:u64, x:u64, y:u64, context: &mut Context) {
34 unsafe {
35 // get the pointer from ncurses
36 let ptr = newwin(height, width, x, y);
37 // refresh the window to allow unbuffered output
38 wrefresh(ptr);
39 // add the window to the context for usage
40 context.win.insert(name.clone(), Window { height, width, x, y, ptr} );
41 }
42
43 }
44}
45
46impl Drop for Window {
47 /// Clean up the window by removing it
48 fn drop(&mut self) {
49 unsafe { delwin(self.ptr); }
50 }
51}