From 7af3208638ab40aa687461cfdbcd07416e1de440 Mon Sep 17 00:00:00 2001 From: "razvan.iliescu2912" Date: Fri, 15 Nov 2024 23:09:55 +0200 Subject: [PATCH] The draw content implementation now has a single branch --- cursive-core/src/views/dialog.rs | 52 ++++++++------------------------ 1 file changed, 13 insertions(+), 39 deletions(-) diff --git a/cursive-core/src/views/dialog.rs b/cursive-core/src/views/dialog.rs index 53c9dbb0..f05159ae 100644 --- a/cursive-core/src/views/dialog.rs +++ b/cursive-core/src/views/dialog.rs @@ -644,6 +644,7 @@ impl Dialog { } fn draw_buttons(&self, printer: &Printer) -> Option { + match self.button_orientation { direction::Orientation::Horizontal => { let mut buttons_height = 0; @@ -746,46 +747,19 @@ impl Dialog { fn draw_content(&self, printer: &Printer, buttons_size: usize) { // What do we have left? - match self.button_orientation { - direction::Orientation::Horizontal => { - let taken = - Vec2::new(0, buttons_size) + self.borders.combined() + self.padding.combined(); - - let inner_size = match printer.size.checked_sub(taken) { - Some(s) => s, - None => return, - }; - - self.content.draw( - &printer - .offset(self.borders.top_left() + self.padding.top_left()) - .cropped(inner_size) - .focused(self.focus == DialogFocus::Content), - ); - } - direction::Orientation::Vertical => { - // TODO: show content if the buttons are vertically aligned - let taken = Vec2::new(buttons_size, 0) + self.padding.combined(); - - // Determine the remaining size for content - let inner_size = match printer.size.checked_sub(taken + self.borders.combined()) { - Some(s) => s, - None => return, // Not enough space for content - }; + let buttons_size = Vec2::from_major_minor(self.button_orientation, buttons_size, 0); + let taken = buttons_size + self.borders.combined() + self.padding.combined(); + let inner_size = match printer.size.checked_sub(taken) { + Some(s) => s, + None => return, + }; - // Offset the content to leave space for the button column - self.content.draw( - &printer - .offset( - self.borders.top_left() - + self.padding.top_left(), // Padding for the content - ) - .cropped(inner_size) - .focused(self.focus == DialogFocus::Content), - ); - } - } - + self.content.draw( + &printer + .offset(self.borders.top_left() + self.padding.top_left()) + .cropped(inner_size) + .focused(self.focus == DialogFocus::Content), + ) } fn draw_title(&self, printer: &Printer) {