mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
added option to position the header in a dialog
This commit is contained in:
parent
9b9619aa53
commit
592ecf4c09
@ -49,6 +49,9 @@ pub struct Dialog {
|
||||
// Possibly empty title.
|
||||
title: String,
|
||||
|
||||
// Where to put the title position
|
||||
title_position: HAlign,
|
||||
|
||||
// The actual inner view.
|
||||
content: SizedView<Box<View>>,
|
||||
|
||||
@ -85,6 +88,7 @@ impl Dialog {
|
||||
content: SizedView::new(Box::new(view)),
|
||||
buttons: Vec::new(),
|
||||
title: String::new(),
|
||||
title_position: HAlign::Center,
|
||||
focus: Focus::Content,
|
||||
padding: Vec4::new(1, 1, 0, 0),
|
||||
borders: Vec4::new(1, 1, 1, 1),
|
||||
@ -169,6 +173,16 @@ impl Dialog {
|
||||
self.title = label.into();
|
||||
}
|
||||
|
||||
/// Sets the horizontal position of the title in the dialog.
|
||||
pub fn title_position(self, align: HAlign) -> Self {
|
||||
self.with(|s| s.set_title_position(align))
|
||||
}
|
||||
|
||||
/// Sets the horizontal position of the title in the dialog.
|
||||
pub fn set_title_position(&mut self, align: HAlign) {
|
||||
self.title_position = align;
|
||||
}
|
||||
|
||||
/// Sets the padding in the dialog (around content and buttons).
|
||||
pub fn padding<T: Into<Vec4>>(mut self, padding: T) -> Self {
|
||||
self.padding = padding.into();
|
||||
@ -348,7 +362,11 @@ impl Dialog {
|
||||
if len + 4 > printer.size.x {
|
||||
return;
|
||||
}
|
||||
let x = (printer.size.x - len) / 2;
|
||||
let x = match self.title_position {
|
||||
HAlign::Left => 3,
|
||||
HAlign::Center => (printer.size.x - len) / 2,
|
||||
HAlign::Right => printer.size.x - len - 3,
|
||||
};
|
||||
printer.with_high_border(false, |printer| {
|
||||
printer.print((x - 2, 0), "┤ ");
|
||||
printer.print((x + len, 0), " ├");
|
||||
|
Loading…
Reference in New Issue
Block a user