mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
refactor: send response packet after context has been switched
This refactor (at least partially) fixes a "mystery delay" sometimes required after a dialog box swaps out. The previous implementation would send the response, and then swap the contexts. This would often cause the recipient to start drawing its UX before the calling app was foregrounded, causing elements to go missing. This refactor puts the response after the context swap. The main downside is it requires every type of modal to have a GAM handle to issue the redraw call, and is especially complicated by the fact that GAM is not clone-friendly. However, the trade-offs of either creating a handle dynamically or storing one in the object is probably worth the benefit of removing an open-loop delay.
This commit is contained in:
parent
b0f443be48
commit
ffa8385e7c
9 changed files with 99 additions and 38 deletions
|
|
@ -56,7 +56,7 @@ pub trait ActionApi {
|
||||||
fn close(&mut self) {}
|
fn close(&mut self) {}
|
||||||
fn is_password(&self) -> bool { false }
|
fn is_password(&self) -> bool { false }
|
||||||
/// navigation is one of '∴' | '←' | '→' | '↑' | '↓'
|
/// navigation is one of '∴' | '←' | '→' | '↑' | '↓'
|
||||||
fn key_action(&mut self, _key: char) -> (Option<ValidatorErr>, bool) {(None, true)}
|
fn key_action(&mut self, _key: char) -> Option<ValidatorErr> {None}
|
||||||
fn set_action_opcode(&mut self, _op: u32) {}
|
fn set_action_opcode(&mut self, _op: u32) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -478,16 +478,9 @@ impl<'a> Modal<'a> {
|
||||||
for &k in keys.iter() {
|
for &k in keys.iter() {
|
||||||
if k != '\u{0}' {
|
if k != '\u{0}' {
|
||||||
log::debug!("got key '{}'", k);
|
log::debug!("got key '{}'", k);
|
||||||
let (err, close) = self.action.key_action(k);
|
let err = self.action.key_action(k);
|
||||||
if let Some(err_msg) = err {
|
if let Some(err_msg) = err {
|
||||||
self.modify(None, None, false, Some(err_msg.to_str()), false, None);
|
self.modify(None, None, false, Some(err_msg.to_str()), false, None);
|
||||||
} else {
|
|
||||||
if close {
|
|
||||||
// if it's a "close" button, invoke the GAM to put our box away
|
|
||||||
self.gam.relinquish_focus().unwrap();
|
|
||||||
xous::yield_slice();
|
|
||||||
break; // don't process any more keys after a close message
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -298,7 +298,7 @@ impl ActionApi for Bip39Entry {
|
||||||
modal.gam.post_textview(&mut tv).expect("couldn't post tv");
|
modal.gam.post_textview(&mut tv).expect("couldn't post tv");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn key_action(&mut self, k: char) -> (Option<ValidatorErr>, bool) {
|
fn key_action(&mut self, k: char) -> Option<ValidatorErr> {
|
||||||
let can_move_downwards = !(self.suggestion_index.get() + 1 == NUM_RECCOS);
|
let can_move_downwards = !(self.suggestion_index.get() + 1 == NUM_RECCOS);
|
||||||
let can_move_upwards = !(self.suggestion_index.get() - 1 < 0);
|
let can_move_upwards = !(self.suggestion_index.get() - 1 < 0);
|
||||||
|
|
||||||
|
|
@ -310,9 +310,13 @@ impl ActionApi for Bip39Entry {
|
||||||
let mut ret = Bip39EntryPayload::default();
|
let mut ret = Bip39EntryPayload::default();
|
||||||
ret.data[..data.len()].copy_from_slice(&data);
|
ret.data[..data.len()].copy_from_slice(&data);
|
||||||
ret.len = data.len() as u32;
|
ret.len = data.len() as u32;
|
||||||
|
|
||||||
|
// relinquish focus before returning the result
|
||||||
|
self.gam.relinquish_focus().unwrap();
|
||||||
|
xous::yield_slice();
|
||||||
|
|
||||||
let buf = Buffer::into_buf(ret).expect("couldn't convert message to payload");
|
let buf = Buffer::into_buf(ret).expect("couldn't convert message to payload");
|
||||||
buf.send(self.action_conn, self.action_opcode).map(|_| ()).expect("couldn't send action message");
|
buf.send(self.action_conn, self.action_opcode).map(|_| ()).expect("couldn't send action message");
|
||||||
return (None, true)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if self.suggested_words.len() > 0 {
|
if self.suggested_words.len() > 0 {
|
||||||
|
|
@ -345,10 +349,14 @@ impl ActionApi for Bip39Entry {
|
||||||
// ignore null messages
|
// ignore null messages
|
||||||
}
|
}
|
||||||
'\u{14}' => { // F4
|
'\u{14}' => { // F4
|
||||||
|
// relinquish focus before returning the result
|
||||||
|
self.gam.relinquish_focus().unwrap();
|
||||||
|
xous::yield_slice();
|
||||||
|
|
||||||
let ret = Bip39EntryPayload::default(); // return a 0-length entry
|
let ret = Bip39EntryPayload::default(); // return a 0-length entry
|
||||||
let buf = Buffer::into_buf(ret).expect("couldn't convert message to payload");
|
let buf = Buffer::into_buf(ret).expect("couldn't convert message to payload");
|
||||||
buf.send(self.action_conn, self.action_opcode).map(|_| ()).expect("couldn't send action message");
|
buf.send(self.action_conn, self.action_opcode).map(|_| ()).expect("couldn't send action message");
|
||||||
return (None, true)
|
return None;
|
||||||
}
|
}
|
||||||
'\u{8}' => { // backspace
|
'\u{8}' => { // backspace
|
||||||
#[cfg(feature="tts")]
|
#[cfg(feature="tts")]
|
||||||
|
|
@ -397,6 +405,6 @@ impl ActionApi for Bip39Entry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(None, false)
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -16,6 +16,7 @@ pub struct CheckBoxes {
|
||||||
pub action_opcode: u32,
|
pub action_opcode: u32,
|
||||||
pub action_payload: CheckBoxPayload,
|
pub action_payload: CheckBoxPayload,
|
||||||
pub select_index: i16,
|
pub select_index: i16,
|
||||||
|
gam: crate::Gam,
|
||||||
#[cfg(feature = "tts")]
|
#[cfg(feature = "tts")]
|
||||||
pub tts: TtsFrontend,
|
pub tts: TtsFrontend,
|
||||||
}
|
}
|
||||||
|
|
@ -29,6 +30,7 @@ impl CheckBoxes {
|
||||||
action_opcode,
|
action_opcode,
|
||||||
action_payload: CheckBoxPayload::new(),
|
action_payload: CheckBoxPayload::new(),
|
||||||
select_index: 0,
|
select_index: 0,
|
||||||
|
gam: crate::Gam::new(&xous_names::XousNames::new().unwrap()).unwrap(),
|
||||||
#[cfg(feature="tts")]
|
#[cfg(feature="tts")]
|
||||||
tts,
|
tts,
|
||||||
}
|
}
|
||||||
|
|
@ -141,7 +143,7 @@ impl ActionApi for CheckBoxes {
|
||||||
DrawStyle::new(PixelColor::Dark, PixelColor::Dark, 1))
|
DrawStyle::new(PixelColor::Dark, PixelColor::Dark, 1))
|
||||||
).expect("couldn't draw entry line");
|
).expect("couldn't draw entry line");
|
||||||
}
|
}
|
||||||
fn key_action(&mut self, k: char) -> (Option<ValidatorErr>, bool) {
|
fn key_action(&mut self, k: char) -> Option<ValidatorErr> {
|
||||||
log::trace!("key_action: {}", k);
|
log::trace!("key_action: {}", k);
|
||||||
match k {
|
match k {
|
||||||
'←' | '→' => {
|
'←' | '→' => {
|
||||||
|
|
@ -180,9 +182,13 @@ impl ActionApi for CheckBoxes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { // the OK button select
|
} else { // the OK button select
|
||||||
|
// relinquish focus before returning the result
|
||||||
|
self.gam.relinquish_focus().unwrap();
|
||||||
|
xous::yield_slice();
|
||||||
|
|
||||||
let buf = Buffer::into_buf(self.action_payload).expect("couldn't convert message to payload");
|
let buf = Buffer::into_buf(self.action_payload).expect("couldn't convert message to payload");
|
||||||
buf.send(self.action_conn, self.action_opcode).map(|_| ()).expect("couldn't send action message");
|
buf.send(self.action_conn, self.action_opcode).map(|_| ()).expect("couldn't send action message");
|
||||||
return (None, true)
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'\u{0}' => {
|
'\u{0}' => {
|
||||||
|
|
@ -192,6 +198,6 @@ impl ActionApi for CheckBoxes {
|
||||||
// ignore text entry
|
// ignore text entry
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(None, false)
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,22 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
/// This is a specialty structure that takes input from the serial console and records it to a string.
|
/// This is a specialty structure that takes input from the serial console and records it to a string.
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug)]
|
||||||
pub struct ConsoleInput {
|
pub struct ConsoleInput {
|
||||||
pub action_conn: xous::CID,
|
pub action_conn: xous::CID,
|
||||||
pub action_opcode: u32,
|
pub action_opcode: u32,
|
||||||
pub action_payload: TextEntryPayload,
|
pub action_payload: TextEntryPayload,
|
||||||
|
gam: Gam,
|
||||||
|
}
|
||||||
|
impl Clone for ConsoleInput {
|
||||||
|
fn clone(&self) -> Self {
|
||||||
|
ConsoleInput {
|
||||||
|
action_conn: self.action_conn,
|
||||||
|
action_opcode: self.action_opcode,
|
||||||
|
action_payload: self.action_payload,
|
||||||
|
gam: crate::Gam::new(&xous_names::XousNames::new().unwrap()).unwrap(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
impl ConsoleInput {
|
impl ConsoleInput {
|
||||||
pub fn new(action_conn: xous::CID, action_opcode: u32) -> Self {
|
pub fn new(action_conn: xous::CID, action_opcode: u32) -> Self {
|
||||||
|
|
@ -13,6 +24,7 @@ impl ConsoleInput {
|
||||||
action_conn,
|
action_conn,
|
||||||
action_opcode,
|
action_opcode,
|
||||||
action_payload: TextEntryPayload::new(),
|
action_payload: TextEntryPayload::new(),
|
||||||
|
gam: crate::Gam::new(&xous_names::XousNames::new().unwrap()).unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -24,22 +36,26 @@ impl ActionApi for ConsoleInput {
|
||||||
fn redraw(&self, _at_height: i16, _modal: &Modal) {
|
fn redraw(&self, _at_height: i16, _modal: &Modal) {
|
||||||
// has nothing
|
// has nothing
|
||||||
}
|
}
|
||||||
fn key_action(&mut self, k: char) -> (Option<ValidatorErr>, bool) {
|
fn key_action(&mut self, k: char) -> Option<ValidatorErr> {
|
||||||
log::trace!("key_action: {}", k);
|
log::trace!("key_action: {}", k);
|
||||||
match k {
|
match k {
|
||||||
'\u{0}' => {
|
'\u{0}' => {
|
||||||
// ignore null messages
|
// ignore null messages
|
||||||
}
|
}
|
||||||
'∴' | '\u{d}' => {
|
'∴' | '\u{d}' => {
|
||||||
|
// relinquish focus before returning the result
|
||||||
|
self.gam.relinquish_focus().unwrap();
|
||||||
|
xous::yield_slice();
|
||||||
|
|
||||||
let buf = Buffer::into_buf(self.action_payload).expect("couldn't convert message to payload");
|
let buf = Buffer::into_buf(self.action_payload).expect("couldn't convert message to payload");
|
||||||
buf.send(self.action_conn, self.action_opcode).map(|_| ()).expect("couldn't send action message");
|
buf.send(self.action_conn, self.action_opcode).map(|_| ()).expect("couldn't send action message");
|
||||||
return (None, true)
|
return None;
|
||||||
}
|
}
|
||||||
_ => { // text entry
|
_ => { // text entry
|
||||||
self.action_payload.content.push(k).expect("ran out of space storing password");
|
self.action_payload.content.push(k).expect("ran out of space storing password");
|
||||||
log::trace!("****update payload: {}", self.action_payload.content);
|
log::trace!("****update payload: {}", self.action_payload.content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(None, false)
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -7,6 +7,7 @@ pub struct Image {
|
||||||
pub action_conn: xous::CID,
|
pub action_conn: xous::CID,
|
||||||
pub action_opcode: u32,
|
pub action_opcode: u32,
|
||||||
pub bitmap: Option<Bitmap>,
|
pub bitmap: Option<Bitmap>,
|
||||||
|
gam: crate::Gam,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Image {
|
impl Image {
|
||||||
|
|
@ -15,6 +16,7 @@ impl Image {
|
||||||
action_conn,
|
action_conn,
|
||||||
action_opcode,
|
action_opcode,
|
||||||
bitmap: None,
|
bitmap: None,
|
||||||
|
gam: crate::Gam::new(&xous_names::XousNames::new().unwrap()).unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn set_bitmap(&mut self, setting: Option<Bitmap>) {
|
pub fn set_bitmap(&mut self, setting: Option<Bitmap>) {
|
||||||
|
|
@ -48,21 +50,25 @@ impl ActionApi for Image {
|
||||||
.expect("couldn't draw bitmap");
|
.expect("couldn't draw bitmap");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn key_action(&mut self, k: char) -> (Option<ValidatorErr>, bool) {
|
fn key_action(&mut self, k: char) -> Option<ValidatorErr> {
|
||||||
log::trace!("key_action: {}", k);
|
log::trace!("key_action: {}", k);
|
||||||
match k {
|
match k {
|
||||||
'\u{0}' => {
|
'\u{0}' => {
|
||||||
// ignore null messages
|
// ignore null messages
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
// relinquish focus before returning the result
|
||||||
|
self.gam.relinquish_focus().unwrap();
|
||||||
|
xous::yield_slice();
|
||||||
|
|
||||||
send_message(
|
send_message(
|
||||||
self.action_conn,
|
self.action_conn,
|
||||||
xous::Message::new_scalar(self.action_opcode as usize, 0, 0, 0, 0),
|
xous::Message::new_scalar(self.action_opcode as usize, 0, 0, 0, 0),
|
||||||
)
|
)
|
||||||
.expect("couldn't pass on dismissal");
|
.expect("couldn't pass on dismissal");
|
||||||
return (None, true);
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(None, false)
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ pub struct Notification {
|
||||||
pub manual_dismiss: bool,
|
pub manual_dismiss: bool,
|
||||||
pub qrcode: Vec<bool>,
|
pub qrcode: Vec<bool>,
|
||||||
pub qrwidth: usize,
|
pub qrwidth: usize,
|
||||||
|
gam: crate::Gam,
|
||||||
}
|
}
|
||||||
impl Notification {
|
impl Notification {
|
||||||
pub fn new(action_conn: xous::CID, action_opcode: u32) -> Self {
|
pub fn new(action_conn: xous::CID, action_opcode: u32) -> Self {
|
||||||
|
|
@ -28,6 +29,7 @@ impl Notification {
|
||||||
manual_dismiss: true,
|
manual_dismiss: true,
|
||||||
qrcode: Vec::new(),
|
qrcode: Vec::new(),
|
||||||
qrwidth: 0,
|
qrwidth: 0,
|
||||||
|
gam: crate::Gam::new(&xous_names::XousNames::new().unwrap()).unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn set_is_password(&mut self, setting: bool) {
|
pub fn set_is_password(&mut self, setting: bool) {
|
||||||
|
|
@ -184,23 +186,27 @@ impl ActionApi for Notification {
|
||||||
)
|
)
|
||||||
.expect("couldn't draw entry line");
|
.expect("couldn't draw entry line");
|
||||||
}
|
}
|
||||||
fn key_action(&mut self, k: char) -> (Option<ValidatorErr>, bool) {
|
fn key_action(&mut self, k: char) -> Option<ValidatorErr> {
|
||||||
log::trace!("key_action: {}", k);
|
log::trace!("key_action: {}", k);
|
||||||
match k {
|
match k {
|
||||||
'\u{0}' => {
|
'\u{0}' => {
|
||||||
// ignore null messages
|
// ignore null messages
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
// relinquish focus before returning the result
|
||||||
|
self.gam.relinquish_focus().unwrap();
|
||||||
|
xous::yield_slice();
|
||||||
|
|
||||||
send_message(
|
send_message(
|
||||||
self.action_conn,
|
self.action_conn,
|
||||||
xous::Message::new_scalar(self.action_opcode as usize, k as u32 as usize, 0, 0, 0),
|
xous::Message::new_scalar(self.action_opcode as usize, k as u32 as usize, 0, 0, 0),
|
||||||
)
|
)
|
||||||
.expect("couldn't pass on dismissal");
|
.expect("couldn't pass on dismissal");
|
||||||
if self.manual_dismiss {
|
if self.manual_dismiss {
|
||||||
return (None, true);
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(None, false)
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ pub struct RadioButtons {
|
||||||
pub action_payload: RadioButtonPayload, // the current "radio button" selection
|
pub action_payload: RadioButtonPayload, // the current "radio button" selection
|
||||||
pub select_index: i16, // the current candidate to be selected
|
pub select_index: i16, // the current candidate to be selected
|
||||||
pub is_password: bool,
|
pub is_password: bool,
|
||||||
|
gam: crate::Gam,
|
||||||
#[cfg(feature = "tts")]
|
#[cfg(feature = "tts")]
|
||||||
pub tts: TtsFrontend,
|
pub tts: TtsFrontend,
|
||||||
}
|
}
|
||||||
|
|
@ -31,6 +32,7 @@ impl RadioButtons {
|
||||||
action_payload: RadioButtonPayload::new(""),
|
action_payload: RadioButtonPayload::new(""),
|
||||||
select_index: 0,
|
select_index: 0,
|
||||||
is_password: false,
|
is_password: false,
|
||||||
|
gam: crate::Gam::new(&xous_names::XousNames::new().unwrap()).unwrap(),
|
||||||
#[cfg(feature="tts")]
|
#[cfg(feature="tts")]
|
||||||
tts,
|
tts,
|
||||||
}
|
}
|
||||||
|
|
@ -152,7 +154,7 @@ impl ActionApi for RadioButtons {
|
||||||
DrawStyle::new(color, color, 1))
|
DrawStyle::new(color, color, 1))
|
||||||
).expect("couldn't draw entry line");
|
).expect("couldn't draw entry line");
|
||||||
}
|
}
|
||||||
fn key_action(&mut self, k: char) -> (Option<ValidatorErr>, bool) {
|
fn key_action(&mut self, k: char) -> Option<ValidatorErr> {
|
||||||
log::trace!("key_action: {}", k);
|
log::trace!("key_action: {}", k);
|
||||||
match k {
|
match k {
|
||||||
'←' | '→' => {
|
'←' | '→' => {
|
||||||
|
|
@ -177,9 +179,13 @@ impl ActionApi for RadioButtons {
|
||||||
self.tts.tts_simple(self.items[self.select_index as usize].as_str()).unwrap();
|
self.tts.tts_simple(self.items[self.select_index as usize].as_str()).unwrap();
|
||||||
}
|
}
|
||||||
} else { // the OK button select
|
} else { // the OK button select
|
||||||
|
// relinquish focus before returning the result
|
||||||
|
self.gam.relinquish_focus().unwrap();
|
||||||
|
xous::yield_slice();
|
||||||
|
|
||||||
let buf = Buffer::into_buf(self.action_payload).expect("couldn't convert message to payload");
|
let buf = Buffer::into_buf(self.action_payload).expect("couldn't convert message to payload");
|
||||||
buf.send(self.action_conn, self.action_opcode).map(|_| ()).expect("couldn't send action message");
|
buf.send(self.action_conn, self.action_opcode).map(|_| ()).expect("couldn't send action message");
|
||||||
return (None, true)
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'\u{0}' => {
|
'\u{0}' => {
|
||||||
|
|
@ -189,6 +195,6 @@ impl ActionApi for RadioButtons {
|
||||||
// ignore text entry
|
// ignore text entry
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(None, false)
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4,6 +4,10 @@ use graphics_server::api::*;
|
||||||
|
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
|
|
||||||
|
// This structure needs to be "shallow copy capable" so we can use it with
|
||||||
|
// the enum_actions API to update the progress state in an efficient manner.
|
||||||
|
// Thus it does not include its own GAM reference; instead we create one on
|
||||||
|
// the fly when needed.
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub struct Slider {
|
pub struct Slider {
|
||||||
pub min: u32,
|
pub min: u32,
|
||||||
|
|
@ -163,7 +167,7 @@ impl ActionApi for Slider {
|
||||||
draw_list.push(GamObjectType::Rect(inner_rect)).unwrap();
|
draw_list.push(GamObjectType::Rect(inner_rect)).unwrap();
|
||||||
modal.gam.draw_list(draw_list).expect("couldn't execute draw list");
|
modal.gam.draw_list(draw_list).expect("couldn't execute draw list");
|
||||||
}
|
}
|
||||||
fn key_action(&mut self, k: char) -> (Option<ValidatorErr>, bool) {
|
fn key_action(&mut self, k: char) -> Option<ValidatorErr> {
|
||||||
log::trace!("key_action: {}", k);
|
log::trace!("key_action: {}", k);
|
||||||
if !self.is_progressbar {
|
if !self.is_progressbar {
|
||||||
match k {
|
match k {
|
||||||
|
|
@ -185,20 +189,30 @@ impl ActionApi for Slider {
|
||||||
// ignore null messages
|
// ignore null messages
|
||||||
}
|
}
|
||||||
'∴' | '\u{d}' => {
|
'∴' | '\u{d}' => {
|
||||||
|
// relinquish focus before returning the result
|
||||||
|
let gam = crate::Gam::new(&xous_names::XousNames::new().unwrap()).unwrap();
|
||||||
|
gam.relinquish_focus().unwrap();
|
||||||
|
xous::yield_slice();
|
||||||
|
|
||||||
send_message(self.action_conn,
|
send_message(self.action_conn,
|
||||||
xous::Message::new_scalar(self.action_opcode as usize, self.action_payload as usize, 0, 0, 0)).expect("couldn't pass on action payload");
|
xous::Message::new_scalar(self.action_opcode as usize, self.action_payload as usize, 0, 0, 0)).expect("couldn't pass on action payload");
|
||||||
return(None, true)
|
return None;
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
// ignore all other messages
|
// ignore all other messages
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(None, false)
|
None
|
||||||
} else {
|
} else {
|
||||||
if k == '🛑' { // use the "stop" emoji as a signal that we should close the progress bar
|
if k == '🛑' { // use the "stop" emoji as a signal that we should close the progress bar
|
||||||
(None, true)
|
// relinquish focus on stop
|
||||||
|
let gam = crate::Gam::new(&xous_names::XousNames::new().unwrap()).unwrap();
|
||||||
|
gam.relinquish_focus().unwrap();
|
||||||
|
xous::yield_slice();
|
||||||
|
|
||||||
|
None
|
||||||
} else {
|
} else {
|
||||||
(None, false)
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ pub struct TextEntry {
|
||||||
/// track if keys were hit since initialized: this allows us to clear the default text,
|
/// 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
|
/// instead of having it re-appear every time the text area is cleared
|
||||||
keys_hit: [bool; MAX_FIELDS as usize],
|
keys_hit: [bool; MAX_FIELDS as usize],
|
||||||
|
// gam: crate::Gam, // no GAM field because this needs to be a clone-capable structure. We create a GAM handle when we need it.
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for TextEntry {
|
impl Default for TextEntry {
|
||||||
|
|
@ -358,7 +359,7 @@ impl ActionApi for TextEntry {
|
||||||
current_height += self.field_height.get();
|
current_height += self.field_height.get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn key_action(&mut self, k: char) -> (Option<ValidatorErr>, bool) {
|
fn key_action(&mut self, k: char) -> Option<ValidatorErr> {
|
||||||
// needs to be a reference, otherwise we're operating on a copy of the payload!
|
// needs to be a reference, otherwise we're operating on a copy of the payload!
|
||||||
let payload = &mut self.action_payloads[self.selected_field as usize];
|
let payload = &mut self.action_payloads[self.selected_field as usize];
|
||||||
|
|
||||||
|
|
@ -415,7 +416,7 @@ impl ActionApi for TextEntry {
|
||||||
if let Some(validator) = self.validator {
|
if let Some(validator) = self.validator {
|
||||||
if let Some(err_msg) = validator(*payload, self.action_opcode) {
|
if let Some(err_msg) = validator(*payload, self.action_opcode) {
|
||||||
payload.content.clear(); // reset the input field
|
payload.content.clear(); // reset the input field
|
||||||
return (Some(err_msg), false);
|
return Some(err_msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -427,6 +428,11 @@ impl ActionApi for TextEntry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// relinquish focus before returning the result
|
||||||
|
let gam = crate::Gam::new(&xous_names::XousNames::new().unwrap()).unwrap();
|
||||||
|
gam.relinquish_focus().unwrap();
|
||||||
|
xous::yield_slice();
|
||||||
|
|
||||||
let mut payloads: TextEntryPayloads = Default::default();
|
let mut payloads: TextEntryPayloads = Default::default();
|
||||||
payloads.1 = self.max_field_amount as usize;
|
payloads.1 = self.max_field_amount as usize;
|
||||||
payloads.0[..self.max_field_amount as usize].copy_from_slice(&self.action_payloads[..self.max_field_amount as usize]);
|
payloads.0[..self.max_field_amount as usize].copy_from_slice(&self.action_payloads[..self.max_field_amount as usize]);
|
||||||
|
|
@ -438,7 +444,7 @@ impl ActionApi for TextEntry {
|
||||||
}
|
}
|
||||||
self.keys_hit[self.selected_field as usize] = false;
|
self.keys_hit[self.selected_field as usize] = false;
|
||||||
|
|
||||||
return (None, true)
|
return None;
|
||||||
}
|
}
|
||||||
'↑' => {
|
'↑' => {
|
||||||
if can_move_upwards {
|
if can_move_upwards {
|
||||||
|
|
@ -492,6 +498,6 @@ impl ActionApi for TextEntry {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(None, false)
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue