pub struct Dialog { /* private fields */ }
Expand description
Pack labels, buttons and other widgets into dialogs
§Examples
use oxide::core::{VerticalAlign, HorizontalAlign, ButtonResult, Widget};
use oxide::{Dialog, StdButton};
let mut maindlg = Dialog::new(60, 10);
let mut b1 = StdButton::new("Quit", 'q', ButtonResult::Ok);
b1.pack(&maindlg, HorizontalAlign::Left, VerticalAlign::Middle, (1,1));
maindlg.draw_box();
// draw to terminal
// maindlg.draw(&mut term);
Implementations§
Source§impl Dialog
impl Dialog
Sourcepub fn new(cols: usize, rows: usize) -> Dialog
pub fn new(cols: usize, rows: usize) -> Dialog
Construct a new Dialog widget cols
wide by rows
high.
§Examples
use oxide::Dialog;
let mut maindlg = Dialog::new(60, 10);
Add an existing widget that implements the Button trait.
§Examples
use oxide::core::{Widget, ButtonResult, HorizontalAlign, VerticalAlign};
use oxide::{Dialog, StdButton};
let mut maindlg = Dialog::new(60, 10);
let mut b1 = StdButton::new("Quit", 'q', ButtonResult::Ok);
b1.pack(&maindlg, HorizontalAlign::Middle, VerticalAlign::Middle, (1,1));
maindlg.add_button(b1);
Sourcepub fn add_layout<T: Layout + 'static>(&mut self, layout: T)
pub fn add_layout<T: Layout + 'static>(&mut self, layout: T)
Add an existing widget that implements the Layout trait. NEEDS A REWORK, the way of passing in a vector of buttons is ugly and a very bad API.
§Examples
use oxide::core::{HorizontalAlign, VerticalAlign, ButtonResult, Button, Widget};
use oxide::{Dialog, StdButton, VerticalLayout};
let mut maindlg = Dialog::new(60, 10);
let b1 = StdButton::new("Foo", 'f', ButtonResult::Ok);
let b2 = StdButton::new("Bar", 'b', ButtonResult::Cancel);
let vec = vec![b1, b2].into_iter().map(Box::new).map(|x| x as Box<Button>).collect();
let mut vlayout = VerticalLayout::from_vec(vec, 0);
vlayout.pack(&maindlg, HorizontalAlign::Middle, VerticalAlign::Middle, (0,0));
maindlg.add_layout(vlayout);
Sourcepub fn add_label(&mut self, label: Label)
pub fn add_label(&mut self, label: Label)
Add an existing label that contains some text.
§Examples
use oxide::core::{HorizontalAlign, VerticalAlign, Widget};
use oxide::{Dialog, Label};
let mut maindlg = Dialog::new(60, 10);
let mut lbl = Label::from_str("Foo");
lbl.pack(&maindlg, HorizontalAlign::Middle, VerticalAlign::Middle, (0,0));
maindlg.add_label(lbl);
Change the state of an existing CheckButton, if any exists, within the dialog. If an invalid button result is given, the function will panic. Note StdButtons are still valid handles for this function, however they will not actually do anything. This function is for buttons that perform some action upon being pressed.
§Examples
// match character for dialog
match dialog.result_for_key(ch) {
Some(ButtonResult::Ok) => {
dialog.button_pressed(ButtonResult::Custom(i));
// do stuff ...
},
_ => { }
}
For buttons that have a state manager, this function will return the current state of the button. CheckButton for example uses a state to manage whether the button is checked, different actions can be taken depending on the state once read.
§Examples
// match character for dialog
match dialog.result_for_key(ch) {
Some(ButtonResult::Ok) => {
dialog.button_pressed(ButtonResult::Custom(i));
if dialog.is_button_pressed(ButtonResult::Custom(i)) {
// do ...
} else {
// do else ...
}
},
_ => { }
}
Sourcepub fn result_for_key(&self, key: char) -> Option<ButtonResult>
pub fn result_for_key(&self, key: char) -> Option<ButtonResult>
Checks whether the char passed is a valid key for any buttons currently
drawn within the dialog, if so the corresponding ButtonResult
is returned
Trait Implementations§
Source§impl Widget for Dialog
impl Widget for Dialog
Source§fn draw(&mut self, parent: &mut dyn CellAccessor)
fn draw(&mut self, parent: &mut dyn CellAccessor)
CellAccessor
passedSource§fn pack(
&mut self,
parent: &dyn HasSize,
halign: HorizontalAlign,
valign: VerticalAlign,
margin: (usize, usize),
)
fn pack( &mut self, parent: &dyn HasSize, halign: HorizontalAlign, valign: VerticalAlign, margin: (usize, usize), )
parent
as reference