Struct Dialog

Source
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

Source

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);
Source

pub fn add_button<T: Button + 'static>(&mut self, button: T)

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);
Source

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);
Source

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);
Source

pub fn button_pressed(&mut self, res: ButtonResult)

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 ...
    },
    _                       => { }
}
Source

pub fn is_button_pressed(&self, res: ButtonResult) -> bool

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 ...
        }
    },
    _                       => { }
}
Source

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 HasSize for Dialog

Source§

fn size(&self) -> Size

Source§

impl Widget for Dialog

Source§

fn draw(&mut self, parent: &mut dyn CellAccessor)

Draws the widget to the valid CellAccessor passed
Source§

fn pack( &mut self, parent: &dyn HasSize, halign: HorizontalAlign, valign: VerticalAlign, margin: (usize, usize), )

Aligns the widget with the parent as reference
Source§

fn draw_box(&mut self)

Expose the painter trait draw_box for all widgets, which outlines the space enclosed within the widget
Source§

fn resize(&mut self, new_size: Size)

Resize the given widget to new dimensions given by Size
Source§

fn frame(&self) -> &Frame

Return a reference the renderer, Base in general cases
Source§

fn frame_mut(&mut self) -> &mut Frame

Return a mutable reference to the renderer, Base in general cases

Auto Trait Implementations§

§

impl Freeze for Dialog

§

impl !RefUnwindSafe for Dialog

§

impl !Send for Dialog

§

impl !Sync for Dialog

§

impl Unpin for Dialog

§

impl !UnwindSafe for Dialog

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.