Struct newt::callbacks::HelpCallback
source · [−]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
sourceimpl<'a, FN, T> HelpCallback<'a, FN, T> where
FN: FnMut(&Form<'_>, Option<&T>),
impl<'a, FN, T> HelpCallback<'a, FN, T> where
FN: FnMut(&Form<'_>, Option<&T>),
sourcepub fn new(
scrollbar: Option<&VerticalScrollbar>,
form_flags: i32,
data: Option<T>,
function: FN
) -> (Form<'a>, Box<HelpCallback<'a, FN, T>>)
pub fn new(
scrollbar: Option<&VerticalScrollbar>,
form_flags: i32,
data: Option<T>,
function: FN
) -> (Form<'a>, Box<HelpCallback<'a, FN, T>>)
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
- AVerticalScrollbar
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 theForm
.
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more