mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-10 03:10:41 +00:00
More fixes for insufficient space.
This commit is contained in:
parent
8750185f8c
commit
4120203844
@ -126,21 +126,25 @@ impl Printer {
|
||||
/// printer.print_box((0,0), (6,4));
|
||||
/// ```
|
||||
pub fn print_box<T: Into<Vec2>, S: Into<Vec2>>(&self, start: T, size: S) {
|
||||
let start_v = start.into();
|
||||
let size_v = size.into() - (1, 1);
|
||||
let start = start.into();
|
||||
let size = size.into();
|
||||
if size.x < 2 || size.y < 2 {
|
||||
return;
|
||||
}
|
||||
let size = size - (1, 1);
|
||||
|
||||
self.print(start_v, "┌");
|
||||
self.print(start_v + size_v.keep_x(), "┐");
|
||||
self.print(start_v + size_v.keep_y(), "└");
|
||||
self.print(start_v + size_v, "┘");
|
||||
self.print(start, "┌");
|
||||
self.print(start + size.keep_x(), "┐");
|
||||
self.print(start + size.keep_y(), "└");
|
||||
self.print(start + size, "┘");
|
||||
|
||||
self.print_hline(start_v + (1, 0), size_v.x - 1, "─");
|
||||
self.print_vline(start_v + (0, 1), size_v.y - 1, "│");
|
||||
self.print_hline(start_v + (1, 0) + size_v.keep_y(),
|
||||
size_v.x - 1,
|
||||
self.print_hline(start + (1, 0), size.x - 1, "─");
|
||||
self.print_vline(start + (0, 1), size.y - 1, "│");
|
||||
self.print_hline(start + (1, 0) + size.keep_y(),
|
||||
size.x - 1,
|
||||
"─");
|
||||
self.print_vline(start_v + (0, 1) + size_v.keep_x(),
|
||||
size_v.y - 1,
|
||||
self.print_vline(start + (0, 1) + size.keep_x(),
|
||||
size.y - 1,
|
||||
"│");
|
||||
}
|
||||
|
||||
@ -176,11 +180,12 @@ impl Printer {
|
||||
pub fn sub_printer<S: Into<Vec2>, T: Into<Vec2>>(&self, offset: S,
|
||||
size: T, focused: bool)
|
||||
-> Printer {
|
||||
let size = size.into();
|
||||
let offset = offset.into().or_min(self.size);
|
||||
Printer {
|
||||
offset: self.offset + offset,
|
||||
// We can't be larger than what remains
|
||||
size: Vec2::min(self.size - offset, size.into()),
|
||||
size: Vec2::min(self.size - offset, size),
|
||||
focused: self.focused && focused,
|
||||
theme: self.theme.clone(),
|
||||
}
|
||||
|
@ -63,6 +63,10 @@ impl Button {
|
||||
impl View for Button {
|
||||
fn draw(&self, printer: &Printer) {
|
||||
|
||||
if printer.size.x == 0 {
|
||||
return;
|
||||
}
|
||||
|
||||
let style = if !self.enabled {
|
||||
ColorStyle::Secondary
|
||||
} else if !printer.focused {
|
||||
|
@ -172,6 +172,9 @@ impl View for Dialog {
|
||||
|
||||
if !self.title.is_empty() {
|
||||
let len = self.title.width();
|
||||
if len + 4 > printer.size.x {
|
||||
return;
|
||||
}
|
||||
let x = (printer.size.x - len) / 2;
|
||||
printer.print((x - 2, 0), "┤ ");
|
||||
printer.print((x + len, 0), " ├");
|
||||
|
@ -134,6 +134,10 @@ impl MenuPopup {
|
||||
|
||||
impl View for MenuPopup {
|
||||
fn draw(&self, printer: &Printer) {
|
||||
if printer.size.x < 2 || printer.size.y < 2 {
|
||||
return;
|
||||
}
|
||||
|
||||
let h = self.menu.len();
|
||||
let offset = self.align.v.get_offset(h, printer.size.y);
|
||||
let printer =
|
||||
@ -155,11 +159,13 @@ impl View for MenuPopup {
|
||||
printer.print_hdelim((0, 0), printer.size.x)
|
||||
}
|
||||
MenuItem::Subtree(ref label, _) => {
|
||||
if printer.size.x < 4 { return; }
|
||||
printer.print_hline((1, 0), printer.size.x - 2, " ");
|
||||
printer.print((2, 0), label);
|
||||
printer.print((printer.size.x - 4, 0), ">>");
|
||||
}
|
||||
MenuItem::Leaf(ref label, _) => {
|
||||
if printer.size.x < 2 { return; }
|
||||
printer.print_hline((1, 0), printer.size.x - 2, " ");
|
||||
printer.print((2, 0), label);
|
||||
}
|
||||
|
@ -156,7 +156,9 @@ impl<T: 'static> SelectView<T> {
|
||||
let x = self.align.h.get_offset(l, printer.size.x);
|
||||
printer.print_hline((0, 0), x, " ");
|
||||
printer.print((x, 0), &self.items[i].label);
|
||||
printer.print_hline((x + l, 0), printer.size.x - l - x, " ");
|
||||
if l < printer.size.x {
|
||||
printer.print_hline((x + l, 0), printer.size.x - l - x, " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user