Form Field: Prompt for a choice from provided options
(mut self, prompt: &str, choices: &[&str], default: Option<usize>)
| 316 | |
| 317 | /// Form Field: Prompt for a choice from provided options |
| 318 | pub fn choice_field(mut self, prompt: &str, choices: &[&str], default: Option<usize>) -> Self { |
| 319 | let prompt = BnString::new(prompt); |
| 320 | let choices: Vec<BnString> = choices.iter().map(|&s| BnString::new(s)).collect(); |
| 321 | |
| 322 | let mut result = unsafe { std::mem::zeroed::<BNFormInputField>() }; |
| 323 | result.type_ = BNFormInputFieldType::ChoiceFormField; |
| 324 | result.prompt = prompt.as_ref().as_ptr() as *const c_char; |
| 325 | let mut raw_choices: Vec<*const c_char> = choices |
| 326 | .iter() |
| 327 | .map(|c| c.as_ref().as_ptr() as *const c_char) |
| 328 | .collect(); |
| 329 | result.choices = raw_choices.as_mut_ptr(); |
| 330 | result.count = choices.len(); |
| 331 | result.hasDefault = default.is_some(); |
| 332 | if let Some(default) = default { |
| 333 | result.indexDefault = default; |
| 334 | } |
| 335 | self.fields.push(result); |
| 336 | |
| 337 | self.data.push(FormData::Choice { |
| 338 | _prompt: prompt, |
| 339 | _choices: choices, |
| 340 | _raw: raw_choices, |
| 341 | }); |
| 342 | self |
| 343 | } |
| 344 | |
| 345 | /// Form Field: Prompt for file to open |
| 346 | pub fn open_file_field( |