mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
modify textentry behavior: default text changes
at the moment, default text will always come back if you remove the text so there is no text in the field (for example, you start typing, and then you decide you want to start over, the suggested text re-appears). this change makes it so that once you start typing, the suggested text does not return. Furthermore, it counts the initial backspace as a key that's hit, so you can clear the suggested text by just hitting backspace.
This commit is contained in:
parent
ad92cbe1cb
commit
b777714435
1 changed files with 15 additions and 2 deletions
|
|
@ -52,6 +52,9 @@ pub struct TextEntry {
|
|||
max_field_amount: u32,
|
||||
selected_field: i16,
|
||||
field_height: Cell::<i16>,
|
||||
/// track if keys were hit since initialized: this allows us to clear the default text,
|
||||
/// instead of having it re-appear every time the text area is cleared
|
||||
keys_hit: bool,
|
||||
}
|
||||
|
||||
impl Default for TextEntry {
|
||||
|
|
@ -66,6 +69,7 @@ impl Default for TextEntry {
|
|||
action_payloads: Default::default(),
|
||||
max_field_amount: 0,
|
||||
field_height: Cell::new(0),
|
||||
keys_hit: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -105,6 +109,7 @@ impl TextEntry {
|
|||
|
||||
self.action_payloads = payload;
|
||||
self.max_field_amount = fields;
|
||||
self.keys_hit = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -194,7 +199,7 @@ impl ActionApi for TextEntry {
|
|||
tv.style = if self.is_password {
|
||||
GlyphStyle::Monospace
|
||||
} else {
|
||||
if payload.placeholder.is_some() && payload.content.len().is_zero() {
|
||||
if payload.placeholder.is_some() && payload.content.len().is_zero() && self.keys_hit {
|
||||
// note: this is just a "recommendation" - if there is an emoji or chinese character in this string, the height revers to modal.style's height
|
||||
GlyphStyle::Small
|
||||
} else {
|
||||
|
|
@ -210,7 +215,7 @@ impl ActionApi for TextEntry {
|
|||
match self.visibility {
|
||||
TextEntryVisibility::Visible => {
|
||||
let content = {
|
||||
if payload.placeholder.is_some() && payload.content.len().is_zero() {
|
||||
if payload.placeholder.is_some() && payload.content.len().is_zero() && !self.keys_hit {
|
||||
let placeholder_content = payload.placeholder.unwrap();
|
||||
placeholder_content.to_string()
|
||||
} else {
|
||||
|
|
@ -389,6 +394,11 @@ impl ActionApi for TextEntry {
|
|||
}
|
||||
},
|
||||
'∴' | '\u{d}' => {
|
||||
if payload.content.len() == 0 && !self.keys_hit {
|
||||
if let Some(placeholder) = payload.placeholder {
|
||||
payload.content.append(placeholder.to_str()).ok();
|
||||
}
|
||||
}
|
||||
if let Some(validator) = self.validator {
|
||||
if let Some(err_msg) = validator(*payload, self.action_opcode) {
|
||||
payload.content.clear(); // reset the input field
|
||||
|
|
@ -405,6 +415,7 @@ impl ActionApi for TextEntry {
|
|||
for payload in self.action_payloads.iter_mut() {
|
||||
payload.volatile_clear();
|
||||
}
|
||||
self.keys_hit = false;
|
||||
|
||||
return (None, true)
|
||||
}
|
||||
|
|
@ -422,6 +433,7 @@ impl ActionApi for TextEntry {
|
|||
// ignore null messages
|
||||
}
|
||||
'\u{8}' => { // backspace
|
||||
self.keys_hit = true;
|
||||
#[cfg(feature="tts")]
|
||||
{
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
|
|
@ -441,6 +453,7 @@ impl ActionApi for TextEntry {
|
|||
}
|
||||
}
|
||||
_ => { // text entry
|
||||
self.keys_hit = true;
|
||||
#[cfg(feature="tts")]
|
||||
{
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
|
|
|
|||
Loading…
Reference in a new issue