mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 09:25:01 +00:00
Add lines and boxes to printer.
Dialog now draws its box.
This commit is contained in:
parent
7d301e1980
commit
919e60d4ce
@ -20,6 +20,32 @@ impl Printer {
|
||||
ncurses::mvwprintw(self.win, (p.y + self.offset.y) as i32, (p.x + self.offset.x) as i32, text);
|
||||
}
|
||||
|
||||
/// Prints a vertical line using the given character.
|
||||
pub fn print_vline<T: ToVec2>(&self, c: char, start: T, len: u32) {
|
||||
let p = start.to_vec2();
|
||||
ncurses::mvwvline(self.win, (p.y + self.offset.y) as i32, (p.x + self.offset.x) as i32, c as u64, len as i32);
|
||||
}
|
||||
|
||||
/// Prints a horizontal line using the given character.
|
||||
pub fn print_hline<T: ToVec2>(&self, c: char, start: T, len: u32) {
|
||||
let p = start.to_vec2();
|
||||
ncurses::mvwhline(self.win, (p.y + self.offset.y) as i32, (p.x + self.offset.x) as i32, c as u64, len as i32);
|
||||
}
|
||||
|
||||
pub fn print_box<T: ToVec2>(&self, start: T, size: T, corners: char, horizontal: char, vertical: char) {
|
||||
let start_v = start.to_vec2();
|
||||
let size_v = size.to_vec2() - (1,1);
|
||||
|
||||
self.print(start_v, &corners.to_string());
|
||||
self.print(start_v + size_v.keep_x(), &corners.to_string());
|
||||
self.print(start_v + size_v.keep_y(), &corners.to_string());
|
||||
self.print(start_v + size_v, &corners.to_string());
|
||||
self.print_hline(horizontal, start_v + (1,0), size_v.x - 1);
|
||||
self.print_hline(horizontal, start_v + (1,0) + size_v.keep_y(), size_v.x - 1);
|
||||
self.print_vline(vertical, start_v + (0,1), size_v.y - 1);
|
||||
self.print_vline(vertical, start_v + (0,1) + size_v.keep_x(), size_v.y - 1);
|
||||
}
|
||||
|
||||
/// Returns a printer on a subset of this one's area.
|
||||
pub fn sub_printer<S: ToVec2>(&self, offset: S, size: S) -> Printer {
|
||||
let offset_v = offset.to_vec2();
|
||||
|
@ -56,6 +56,12 @@ impl ToVec2 for Vec2 {
|
||||
}
|
||||
}
|
||||
|
||||
impl ToVec2 for (i32,i32) {
|
||||
fn to_vec2(self) -> Vec2 {
|
||||
(self.0 as u32, self.1 as u32).to_vec2()
|
||||
}
|
||||
}
|
||||
|
||||
impl ToVec2 for (u32,u32) {
|
||||
fn to_vec2(self) -> Vec2 {
|
||||
Vec2::new(self.0, self.1)
|
||||
|
@ -79,10 +79,8 @@ impl View for Dialog {
|
||||
|
||||
self.content.draw(&printer.sub_printer(self.borders.top_left() + self.padding.top_left(), inner_size), focused && self.focus == Focus::Content);
|
||||
|
||||
printer.print(Vec2::new(0,0), "+");
|
||||
printer.print(Vec2::new(printer.size.x-1, 0), "+");
|
||||
printer.print(Vec2::new(0, printer.size.y-1), "+");
|
||||
printer.print(Vec2::new(printer.size.x-1, printer.size.y-1), "+");
|
||||
printer.print_box(Vec2::new(0,0), printer.size, '+', '-', '|');
|
||||
|
||||
}
|
||||
|
||||
fn get_min_size(&self, req: SizeRequest) -> Vec2 {
|
||||
@ -135,6 +133,14 @@ impl View for Dialog {
|
||||
},
|
||||
Focus::Button(i) => match self.buttons[i].on_key_event(ch) {
|
||||
EventResult::Ignored => match ch {
|
||||
ncurses::KEY_UP => {
|
||||
if self.content.take_focus() {
|
||||
self.focus = Focus::Content;
|
||||
EventResult::consume()
|
||||
} else {
|
||||
EventResult::Ignored
|
||||
}
|
||||
},
|
||||
ncurses::KEY_RIGHT if i+1 < self.buttons.len() => {
|
||||
self.focus = Focus::Button(i+1);
|
||||
EventResult::consume()
|
||||
|
Loading…
Reference in New Issue
Block a user