make single-field modals accept a placeholder

This commit is contained in:
Gianguido Sorà 2022-04-05 16:28:58 +02:00
parent ba347f6c79
commit 5c975fdee4
4 changed files with 16 additions and 12 deletions

View file

@ -147,7 +147,7 @@ impl ActionApi for TextEntry {
_ => current_height + at_height,
};
if index as i16 == self.selected_field {
if index as i16 == self.selected_field && payloads.len() > 1 {
// draw the dot
let mut tv = TextView::new(
modal.canvas,
@ -163,7 +163,10 @@ impl ActionApi for TextEntry {
modal.gam.post_textview(&mut tv).expect("couldn't post tv");
}
let left_text_margin = modal.margin + 15;
let left_text_margin = match payloads.len() {
1 => modal.margin,
_ => modal.margin + 15,
};
// draw the currently entered text
let mut tv = TextView::new(

View file

@ -32,8 +32,9 @@ impl Modals {
prompt: &str,
maybe_validator: Option<fn(TextEntryPayload, u32) -> Option<ValidatorErr>>,
maybe_validator_op: Option<u32>,
placeholder: Option<String>
) -> Result<TextEntryPayload, xous::Error> {
match self.get_text_multi(prompt, maybe_validator, maybe_validator_op, 1, None) {
match self.get_text_multi(prompt, maybe_validator, maybe_validator_op, 1, Some(vec![placeholder])) {
Ok(res) => {
return Ok(res.first())
},

View file

@ -81,7 +81,7 @@ pub(crate) fn spawn_test() {
// 2. test the modal dialog box function
log::info!("test text input");
match modals.get_text("Test input", Some(test_validator), None) {
match modals.get_text("Test input", Some(test_validator), None, None) {
Ok(text) => {
log::info!("Input: {}", text.content);
}

View file

@ -471,7 +471,7 @@ pub fn start_time_ux(sid: xous::SID) {
if !tz_set {
let tz = modals.get_text(
t!("rtc.timezone", xous::LANG),
Some(tz_ux_validator), None
Some(tz_ux_validator), None, None
).expect("couldn't get timezone").as_str()
.parse::<f32>().expect("pre-validated input failed to re-parse!");
log::info!("got tz offset {}", tz);
@ -495,42 +495,42 @@ pub fn start_time_ux(sid: xous::SID) {
months = modals.get_text(
t!("rtc.month", xous::LANG),
Some(rtc_ux_validator), Some(ValidatorOp::UxMonth.to_u32().unwrap())
Some(rtc_ux_validator), Some(ValidatorOp::UxMonth.to_u32().unwrap()), None,
).expect("couldn't get month").as_str()
.parse::<u8>().expect("pre-validated input failed to re-parse!");
log::debug!("got months {}", months);
days = modals.get_text(
t!("rtc.day", xous::LANG),
Some(rtc_ux_validator), Some(ValidatorOp::UxDay.to_u32().unwrap())
Some(rtc_ux_validator), Some(ValidatorOp::UxDay.to_u32().unwrap()), None
).expect("couldn't get month").as_str()
.parse::<u8>().expect("pre-validated input failed to re-parse!");
log::debug!("got days {}", days);
years = modals.get_text(
t!("rtc.year", xous::LANG),
Some(rtc_ux_validator), Some(ValidatorOp::UxYear.to_u32().unwrap())
Some(rtc_ux_validator), Some(ValidatorOp::UxYear.to_u32().unwrap()), None
).expect("couldn't get month").as_str()
.parse::<u8>().expect("pre-validated input failed to re-parse!");
log::debug!("got years {}", years);
hours = modals.get_text(
t!("rtc.hour", xous::LANG),
Some(rtc_ux_validator), Some(ValidatorOp::UxHour.to_u32().unwrap())
Some(rtc_ux_validator), Some(ValidatorOp::UxHour.to_u32().unwrap()), None
).expect("couldn't get hour").as_str()
.parse::<u8>().expect("pre-validated input failed to re-parse!");
log::debug!("got hours {}", hours);
mins = modals.get_text(
t!("rtc.minute", xous::LANG),
Some(rtc_ux_validator), Some(ValidatorOp::UxMinute.to_u32().unwrap())
Some(rtc_ux_validator), Some(ValidatorOp::UxMinute.to_u32().unwrap()), None
).expect("couldn't get minutes").as_str()
.parse::<u8>().expect("pre-validated input failed to re-parse!");
log::debug!("got minutes {}", mins);
secs = modals.get_text(
t!("rtc.seconds", xous::LANG),
Some(rtc_ux_validator), Some(ValidatorOp::UxSeconds.to_u32().unwrap())
Some(rtc_ux_validator), Some(ValidatorOp::UxSeconds.to_u32().unwrap()), None
).expect("couldn't get seconds").as_str()
.parse::<u8>().expect("pre-validated input failed to re-parse!");
log::debug!("got seconds {}", secs);
@ -554,7 +554,7 @@ pub fn start_time_ux(sid: xous::SID) {
}
let tz = modals.get_text(
t!("rtc.timezone", xous::LANG),
Some(tz_ux_validator), None
Some(tz_ux_validator), None, None
).expect("couldn't get timezone").as_str()
.parse::<f32>().expect("pre-validated input failed to re-parse!");
log::info!("got tz offset {}", tz);