[][src]Struct newt::callbacks::HelpCallback

pub struct HelpCallback<'a, FN, T> where
    FN: FnMut(&Form, Option<&T>), 
{ /* fields omitted */ }

A callback called when F1 is pressed while a Form is running.

A new Form is initalized along with the callback associating the two together. The Form::new_with_help_callback() could also be used in lieu of HelpCallback::new().

Example

extern crate newt;
use newt::prelude::*;

pub fn main() {
    newt::init().unwrap();
    newt::cls();
    newt::centered_window(20, 6, Some("Help Test")).unwrap();

    // Closure that will display a new window when `F1` is pressed.
    let f = |_form: &Form, data: Option<&&str>| {
        let string = data.unwrap_or(&"None");
        let len = string.len();

        let width = (len + 18) as u32;
        newt::centered_window(width, 5, Some("Help")).unwrap();

        let text = format!("Help Text Data: {}", string);
        let label = Label::new(1, 1, &text);

        let pos = (width / 2 - 3) as i32;
        let ok = CompactButton::new(pos, 3, "Ok");

        let mut form = Form::new(None, 0);
        form.add_component(&label).unwrap();
        form.add_component(&ok).unwrap();
        form.run().unwrap();
        newt::pop_window();
    };

    // `Form` is allocated with the callback and both are associated.
    let label = Label::new(1, 1, "Press F1 for help!");
    let ok = CompactButton::new(7, 4, "Ok");

    let (mut form, _cb) =
        Form::new_with_help_callback(None, 0, f, Some("This is help text."));
    form.add_components(&[&label, &ok]).unwrap();

    form.run().unwrap();
    newt::finished();
}

Implementations

impl<'a, FN, T> HelpCallback<'a, FN, T> where
    FN: FnMut(&Form, Option<&T>), 
[src]

pub fn new(
    scrollbar: Option<&VerticalScrollbar>,
    form_flags: i32,
    function: FN,
    data: Option<T>
) -> (Form<'a>, Box<HelpCallback<'a, FN, T>>)
[src]

Initialize a new Form and associate the function or closure function as a HelpCallback. The callback will be executed when F1 is pressed while the Form is running. The new Form and HelpCallback are returned as a tuple pair.

  • scrollbar - A VerticalScrollbar to be attached to the created form.
  • form_flags - The flags the form is to be initialized with.
  • function - The function or closure to associate with the Form.
  • data - The optional user data to pass to the function.

Auto Trait Implementations

impl<'a, FN, T> !RefUnwindSafe for HelpCallback<'a, FN, T>

impl<'a, FN, T> !Send for HelpCallback<'a, FN, T>

impl<'a, FN, T> !Sync for HelpCallback<'a, FN, T>

impl<'a, FN, T> Unpin for HelpCallback<'a, FN, T> where
    FN: Unpin,
    T: Unpin

impl<'a, FN, T> !UnwindSafe for HelpCallback<'a, FN, T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.