fltk-rs/fltk-form

Other kinds of inputs

Closed this issue · 1 comments

Hello, and what about of other kind of inputs?
Like SecretInput for example.

You can impl FltkForm for whatever struct you might need:

#[derive(Debug, Clone)]
pub struct Secret(pub String);

impl FltkForm for Secret {

fn generate(&self) -> Box<dyn WidgetExt> {
        let mut i = input::SecretInput::default();
        i.set_value(&self.0);
        unsafe {
            i.set_raw_user_data(transmute(1_usize));
        }
        Box::new(i)
    }
    fn view(&self) -> Box<dyn WidgetExt> {
        let mut i = input::SecretInput::default();
        i.set_readonly(true);
        i.set_value(&self.0);
        unsafe {
            i.set_raw_user_data(transmute(1_usize));
        }
        Box::new(i)
    }
}

It’s difficult to determine what a good default for secret input, so such structs are left to the user. You might want to show the password in the view trait method, so you would use an Output widget.