mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
add backspace (derp)
This commit is contained in:
parent
4affdabc73
commit
9b51edfe6c
1 changed files with 59 additions and 12 deletions
|
|
@ -108,6 +108,8 @@ impl ActionApi for TextEntry {
|
||||||
fn is_password(&self) -> bool {
|
fn is_password(&self) -> bool {
|
||||||
self.is_password
|
self.is_password
|
||||||
}
|
}
|
||||||
|
/// The total canvas height is computed with this API call
|
||||||
|
/// The canvas height is not dynamically adjustable for modals.
|
||||||
fn height(&self, glyph_height: i16, margin: i16) -> i16 {
|
fn height(&self, glyph_height: i16, margin: i16) -> i16 {
|
||||||
/*
|
/*
|
||||||
-------------------
|
-------------------
|
||||||
|
|
@ -142,29 +144,63 @@ impl ActionApi for TextEntry {
|
||||||
tv.draw_border = false;
|
tv.draw_border = false;
|
||||||
tv.insertion = Some(self.action_payload.0.len() as i32);
|
tv.insertion = Some(self.action_payload.0.len() as i32);
|
||||||
tv.text.clear(); // make sure this is blank
|
tv.text.clear(); // make sure this is blank
|
||||||
|
let payload_chars = self.action_payload.0.as_str().unwrap().chars().count();
|
||||||
|
// TODO: condense the "above 20" chars length path a bit -- written out "the dumb way" just to reason out the logic a bit
|
||||||
match self.visibility {
|
match self.visibility {
|
||||||
TextEntryVisibility::Visible => {
|
TextEntryVisibility::Visible => {
|
||||||
log::trace!("action payload: {}", self.action_payload.0.as_str().unwrap());
|
log::trace!("action payload: {}", self.action_payload.0.as_str().unwrap());
|
||||||
write!(tv.text, "{}", self.action_payload.0.as_str().unwrap());
|
if payload_chars < 20 {
|
||||||
|
write!(tv.text, "{}", self.action_payload.0.as_str().unwrap());
|
||||||
|
} else {
|
||||||
|
write!(tv.text, "...{}", &self.action_payload.0.as_str().unwrap()[payload_chars-18..]);
|
||||||
|
}
|
||||||
modal.gam.post_textview(&mut tv).expect("couldn't post textview");
|
modal.gam.post_textview(&mut tv).expect("couldn't post textview");
|
||||||
},
|
},
|
||||||
TextEntryVisibility::Hidden => {
|
TextEntryVisibility::Hidden => {
|
||||||
for _char in self.action_payload.0.as_str().unwrap().chars() {
|
if payload_chars < 20 {
|
||||||
tv.text.push('*').expect("text field too long");
|
for _char in self.action_payload.0.as_str().unwrap().chars() {
|
||||||
|
tv.text.push('*').expect("text field too long");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// just render a pure dummy string
|
||||||
|
tv.text.push('.').unwrap();
|
||||||
|
tv.text.push('.').unwrap();
|
||||||
|
tv.text.push('.').unwrap();
|
||||||
|
for _ in 0..18 {
|
||||||
|
tv.text.push('*').expect("text field too long");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
modal.gam.post_textview(&mut tv).expect("couldn't post textview");
|
modal.gam.post_textview(&mut tv).expect("couldn't post textview");
|
||||||
},
|
},
|
||||||
TextEntryVisibility::LastChars => {
|
TextEntryVisibility::LastChars => {
|
||||||
let hide_to = if self.action_payload.0.as_str().unwrap().chars().count() >= 2 {
|
if payload_chars < 20 {
|
||||||
self.action_payload.0.as_str().unwrap().chars().count() - 2
|
let hide_to = if self.action_payload.0.as_str().unwrap().chars().count() >= 2 {
|
||||||
} else {
|
self.action_payload.0.as_str().unwrap().chars().count() - 2
|
||||||
0
|
|
||||||
};
|
|
||||||
for (index, ch) in self.action_payload.0.as_str().unwrap().chars().enumerate() {
|
|
||||||
if index < hide_to {
|
|
||||||
tv.text.push('*').expect("text field too long");
|
|
||||||
} else {
|
} else {
|
||||||
tv.text.push(ch).expect("text field too long");
|
0
|
||||||
|
};
|
||||||
|
for (index, ch) in self.action_payload.0.as_str().unwrap().chars().enumerate() {
|
||||||
|
if index < hide_to {
|
||||||
|
tv.text.push('*').expect("text field too long");
|
||||||
|
} else {
|
||||||
|
tv.text.push(ch).expect("text field too long");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tv.text.push('.').unwrap();
|
||||||
|
tv.text.push('.').unwrap();
|
||||||
|
tv.text.push('.').unwrap();
|
||||||
|
let hide_to = if self.action_payload.0.as_str().unwrap().chars().count() >= 2 {
|
||||||
|
self.action_payload.0.as_str().unwrap().chars().count() - 2
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
};
|
||||||
|
for (index, ch) in self.action_payload.0.as_str().unwrap()[payload_chars-18..].chars().enumerate() {
|
||||||
|
if index + payload_chars-18 < hide_to {
|
||||||
|
tv.text.push('*').expect("text field too long");
|
||||||
|
} else {
|
||||||
|
tv.text.push(ch).expect("text field too long");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
modal.gam.post_textview(&mut tv).expect("couldn't post textview");
|
modal.gam.post_textview(&mut tv).expect("couldn't post textview");
|
||||||
|
|
@ -255,6 +291,17 @@ impl ActionApi for TextEntry {
|
||||||
'\u{0}' => {
|
'\u{0}' => {
|
||||||
// ignore null messages
|
// ignore null messages
|
||||||
}
|
}
|
||||||
|
'\u{8}' => { // backspace
|
||||||
|
// coded in a conservative manner to avoid temporary allocations that can leave the plaintext on the stack
|
||||||
|
let mut temp_str = String::<256>::from_str(self.action_payload.0.as_str().unwrap());
|
||||||
|
let cur_len = temp_str.as_str().unwrap().chars().count();
|
||||||
|
let mut c_iter = temp_str.as_str().unwrap().chars();
|
||||||
|
self.action_payload.0.clear();
|
||||||
|
for _ in 0..cur_len-1 {
|
||||||
|
self.action_payload.0.push(c_iter.next().unwrap());
|
||||||
|
}
|
||||||
|
temp_str.volatile_clear();
|
||||||
|
}
|
||||||
_ => { // text entry
|
_ => { // text entry
|
||||||
self.action_payload.0.push(k).expect("ran out of space storing password");
|
self.action_payload.0.push(k).expect("ran out of space storing password");
|
||||||
log::trace!("****update payload: {}", self.action_payload.0);
|
log::trace!("****update payload: {}", self.action_payload.0);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue