From 7564a5d1dbf84cf2b0ab254c2199bad265b6b1fa Mon Sep 17 00:00:00 2001 From: Chris Vest Date: Sun, 3 Mar 2019 10:37:50 +0100 Subject: [PATCH] Reduce the title drawing cut-off point by 2 characters. Panels and dialogs have borders with corners. Previously, the title would draw over the border corner, including its own end-points. Now the cut-off point is such that we do not draw the title if the right-hand end point and the border-corner do not also fit. --- src/views/dialog.rs | 7 ++++--- src/views/panel.rs | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/views/dialog.rs b/src/views/dialog.rs index 6e0aa3d..ce2e9aa 100644 --- a/src/views/dialog.rs +++ b/src/views/dialog.rs @@ -461,14 +461,15 @@ impl Dialog { fn draw_title(&self, printer: &Printer<'_, '_>) { if !self.title.is_empty() { let len = self.title.width(); - if len + 4 > printer.size.x { + let spacing = 3; //minimum distance to borders + let spacing_both_ends = 2 * spacing; + if len + spacing_both_ends > printer.size.x { return; } - let spacing = 3; //minimum distance to borders let x = spacing + self .title_position - .get_offset(len, printer.size.x - 2 * spacing); + .get_offset(len, printer.size.x - spacing_both_ends); printer.with_high_border(false, |printer| { printer.print((x - 2, 0), "┤ "); printer.print((x + len, 0), " ├"); diff --git a/src/views/panel.rs b/src/views/panel.rs index 2bb0c05..3476458 100644 --- a/src/views/panel.rs +++ b/src/views/panel.rs @@ -65,14 +65,15 @@ impl Panel { fn draw_title(&self, printer: &Printer<'_, '_>) { if !self.title.is_empty() { let len = self.title.width(); - if len + 4 > printer.size.x { + let spacing = 3; //minimum distance to borders + let spacing_both_ends = 2 * spacing; + if len + spacing_both_ends > printer.size.x { return; } - let spacing = 3; //minimum distance to borders let x = spacing + self .title_position - .get_offset(len, printer.size.x - 2 * spacing); + .get_offset(len, printer.size.x - spacing_both_ends); printer.with_high_border(false, |printer| { printer.print((x - 2, 0), "┤ "); printer.print((x + len, 0), " ├");