mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Merge pull request #169 from punkkeks/dialog_position
added option to position the header in a dialog
This commit is contained in:
commit
9cb74c7497
@ -49,6 +49,9 @@ pub struct Dialog {
|
|||||||
// Possibly empty title.
|
// Possibly empty title.
|
||||||
title: String,
|
title: String,
|
||||||
|
|
||||||
|
// Where to put the title position
|
||||||
|
title_position: HAlign,
|
||||||
|
|
||||||
// The actual inner view.
|
// The actual inner view.
|
||||||
content: SizedView<Box<View>>,
|
content: SizedView<Box<View>>,
|
||||||
|
|
||||||
@ -85,6 +88,7 @@ impl Dialog {
|
|||||||
content: SizedView::new(Box::new(view)),
|
content: SizedView::new(Box::new(view)),
|
||||||
buttons: Vec::new(),
|
buttons: Vec::new(),
|
||||||
title: String::new(),
|
title: String::new(),
|
||||||
|
title_position: HAlign::Center,
|
||||||
focus: Focus::Content,
|
focus: Focus::Content,
|
||||||
padding: Vec4::new(1, 1, 0, 0),
|
padding: Vec4::new(1, 1, 0, 0),
|
||||||
borders: Vec4::new(1, 1, 1, 1),
|
borders: Vec4::new(1, 1, 1, 1),
|
||||||
@ -169,6 +173,18 @@ impl Dialog {
|
|||||||
self.title = label.into();
|
self.title = label.into();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the horizontal position of the title in the dialog.
|
||||||
|
/// The default position is `HAlign::Center`
|
||||||
|
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.
|
||||||
|
/// The default position is `HAlign::Center`
|
||||||
|
pub fn set_title_position(&mut self, align: HAlign) {
|
||||||
|
self.title_position = align;
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets the padding in the dialog (around content and buttons).
|
/// Sets the padding in the dialog (around content and buttons).
|
||||||
pub fn padding<T: Into<Vec4>>(mut self, padding: T) -> Self {
|
pub fn padding<T: Into<Vec4>>(mut self, padding: T) -> Self {
|
||||||
self.padding = padding.into();
|
self.padding = padding.into();
|
||||||
@ -348,7 +364,8 @@ impl Dialog {
|
|||||||
if len + 4 > printer.size.x {
|
if len + 4 > printer.size.x {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let x = (printer.size.x - len) / 2;
|
let spacing = 3; //minimum distance to borders
|
||||||
|
let x = spacing + self.title_position.get_offset(len, printer.size.x - 2 * spacing);
|
||||||
printer.with_high_border(false, |printer| {
|
printer.with_high_border(false, |printer| {
|
||||||
printer.print((x - 2, 0), "┤ ");
|
printer.print((x - 2, 0), "┤ ");
|
||||||
printer.print((x + len, 0), " ├");
|
printer.print((x + len, 0), " ├");
|
||||||
|
Loading…
Reference in New Issue
Block a user