Skip to content

Commit

Permalink
The draw content implementation now has a single branch
Browse files Browse the repository at this point in the history
  • Loading branch information
razvan.iliescu2912 committed Nov 15, 2024
1 parent 8b83360 commit 7af3208
Showing 1 changed file with 13 additions and 39 deletions.
52 changes: 13 additions & 39 deletions cursive-core/src/views/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@ impl Dialog {
}

fn draw_buttons(&self, printer: &Printer) -> Option<usize> {

match self.button_orientation {
direction::Orientation::Horizontal => {
let mut buttons_height = 0;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 7af3208

Please sign in to comment.