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