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

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

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.
  • data - The optional user data to pass to the function.
  • function - The function or closure to associate with the Form.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.