2021-08-01 08:08:27 +00:00
|
|
|
|
//! The main API entry point is the `Modal` struct. Click into the struct for more details.
|
2021-07-21 19:04:16 +00:00
|
|
|
|
|
2021-08-21 16:29:42 +00:00
|
|
|
|
mod textentry;
|
|
|
|
|
|
pub use textentry::*;
|
|
|
|
|
|
mod radiobuttons;
|
|
|
|
|
|
pub use radiobuttons::*;
|
|
|
|
|
|
mod checkboxes;
|
|
|
|
|
|
pub use checkboxes::*;
|
|
|
|
|
|
mod notification;
|
|
|
|
|
|
pub use notification::*;
|
|
|
|
|
|
mod slider;
|
|
|
|
|
|
pub use slider::*;
|
|
|
|
|
|
mod progressbar;
|
|
|
|
|
|
pub use progressbar::*;
|
|
|
|
|
|
mod consoleinput;
|
|
|
|
|
|
pub use consoleinput::*;
|
2022-04-08 04:16:15 +00:00
|
|
|
|
mod qrcode;
|
|
|
|
|
|
pub use self::qrcode::*;
|
2021-08-21 16:29:42 +00:00
|
|
|
|
|
2021-07-25 16:51:22 +00:00
|
|
|
|
use enum_dispatch::enum_dispatch;
|
2021-07-21 19:04:16 +00:00
|
|
|
|
|
|
|
|
|
|
use crate::api::*;
|
|
|
|
|
|
use crate::Gam;
|
2021-08-21 16:37:53 +00:00
|
|
|
|
use crate::MsgForwarder;
|
2021-07-21 19:04:16 +00:00
|
|
|
|
|
2021-07-28 15:58:15 +00:00
|
|
|
|
use graphics_server::api::*;
|
2022-01-21 07:01:56 +00:00
|
|
|
|
pub use graphics_server::api::GlyphStyle;
|
2021-07-21 19:04:16 +00:00
|
|
|
|
|
|
|
|
|
|
use xous_ipc::{String, Buffer};
|
|
|
|
|
|
use num_traits::*;
|
2021-07-26 20:40:12 +00:00
|
|
|
|
use core::fmt::Write;
|
|
|
|
|
|
|
2021-07-27 20:27:14 +00:00
|
|
|
|
pub const MAX_ITEMS: usize = 8;
|
2021-07-21 19:04:16 +00:00
|
|
|
|
|
2021-08-21 16:37:53 +00:00
|
|
|
|
#[enum_dispatch(ActionApi)]
|
|
|
|
|
|
pub enum ActionType {
|
|
|
|
|
|
TextEntry,
|
|
|
|
|
|
RadioButtons,
|
|
|
|
|
|
CheckBoxes,
|
|
|
|
|
|
Slider,
|
|
|
|
|
|
Notification,
|
2022-04-08 04:16:15 +00:00
|
|
|
|
Qrcode,
|
2021-08-21 16:37:53 +00:00
|
|
|
|
ConsoleInput
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[enum_dispatch]
|
|
|
|
|
|
pub trait ActionApi {
|
|
|
|
|
|
fn height(&self, glyph_height: i16, margin: i16) -> i16 {glyph_height + margin * 2}
|
|
|
|
|
|
fn redraw(&self, _at_height: i16, _modal: &Modal) { unimplemented!() }
|
|
|
|
|
|
fn close(&mut self) {}
|
|
|
|
|
|
fn is_password(&self) -> bool { false }
|
|
|
|
|
|
/// navigation is one of '∴' | '←' | '→' | '↑' | '↓'
|
2021-12-15 05:53:53 +00:00
|
|
|
|
fn key_action(&mut self, _key: char) -> (Option<ValidatorErr>, bool) {(None, true)}
|
2021-08-21 16:37:53 +00:00
|
|
|
|
fn set_action_opcode(&mut self, _op: u32) {}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
|
|
|
|
|
pub enum ModalOpcode { // if changes are made here, also update MenuOpcode
|
|
|
|
|
|
Redraw = 0x4000_0000, // set the high bit so that "standard" enums don't conflict with the Modal-specific opcodes
|
|
|
|
|
|
Rawkeys,
|
|
|
|
|
|
Quit,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-01 08:08:27 +00:00
|
|
|
|
/// We use a new type for item names, so that it's easy to resize this as needed.
|
2021-07-28 09:35:25 +00:00
|
|
|
|
#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
2021-07-25 16:51:22 +00:00
|
|
|
|
pub struct ItemName(String::<64>);
|
2021-07-27 20:27:14 +00:00
|
|
|
|
impl ItemName {
|
|
|
|
|
|
pub fn new(name: &str) -> Self {
|
|
|
|
|
|
ItemName(String::<64>::from_str(name))
|
|
|
|
|
|
}
|
2021-07-28 09:35:25 +00:00
|
|
|
|
pub fn as_str(&self) -> &str {
|
|
|
|
|
|
self.0.as_str().expect("couldn't convert item into string")
|
|
|
|
|
|
}
|
2021-07-27 20:27:14 +00:00
|
|
|
|
}
|
2021-08-01 08:08:27 +00:00
|
|
|
|
|
2021-07-27 09:30:37 +00:00
|
|
|
|
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone, Eq, PartialEq)]
|
2021-07-28 19:30:03 +00:00
|
|
|
|
pub struct TextEntryPayload(pub String::<256>);
|
2021-07-26 20:40:12 +00:00
|
|
|
|
impl TextEntryPayload {
|
|
|
|
|
|
pub fn new() -> Self {
|
|
|
|
|
|
TextEntryPayload(String::<256>::new())
|
|
|
|
|
|
}
|
2021-08-01 08:08:27 +00:00
|
|
|
|
/// Ensures that 0's are written to the storage of this struct, and not optimized out; important for password fields.
|
2021-07-27 09:30:37 +00:00
|
|
|
|
pub fn volatile_clear(&mut self) {
|
2021-08-01 08:08:27 +00:00
|
|
|
|
self.0.volatile_clear();
|
2021-07-26 20:40:12 +00:00
|
|
|
|
}
|
2021-07-27 09:30:37 +00:00
|
|
|
|
pub fn as_str(&self) -> &str {
|
2021-07-28 09:35:25 +00:00
|
|
|
|
self.0.as_str().expect("couldn't convert textentry string")
|
2021-07-27 09:30:37 +00:00
|
|
|
|
}
|
2021-07-26 20:40:12 +00:00
|
|
|
|
}
|
2021-07-27 09:30:37 +00:00
|
|
|
|
|
2021-07-28 09:35:25 +00:00
|
|
|
|
#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
2021-12-16 16:32:44 +00:00
|
|
|
|
pub struct RadioButtonPayload(pub ItemName); // returns the name of the item corresponding to the radio button selection
|
2021-07-27 20:27:14 +00:00
|
|
|
|
impl RadioButtonPayload {
|
2021-07-28 15:00:25 +00:00
|
|
|
|
pub fn new(name: &str) -> Self {
|
|
|
|
|
|
RadioButtonPayload(ItemName::new(name))
|
2021-07-27 20:27:14 +00:00
|
|
|
|
}
|
2021-07-28 09:35:25 +00:00
|
|
|
|
pub fn as_str(&self) -> &str {
|
|
|
|
|
|
self.0.as_str()
|
|
|
|
|
|
}
|
2021-12-16 15:16:21 +00:00
|
|
|
|
pub fn clear(&mut self) {
|
|
|
|
|
|
self.0.0.clear();
|
|
|
|
|
|
}
|
2021-07-27 20:27:14 +00:00
|
|
|
|
}
|
2021-07-28 09:35:25 +00:00
|
|
|
|
#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
2021-12-16 16:32:44 +00:00
|
|
|
|
pub struct CheckBoxPayload(pub [Option<ItemName>; MAX_ITEMS]); // returns a list of potential items that could be selected
|
2021-07-27 20:27:14 +00:00
|
|
|
|
impl CheckBoxPayload {
|
|
|
|
|
|
pub fn new() -> Self {
|
|
|
|
|
|
CheckBoxPayload([None; MAX_ITEMS])
|
|
|
|
|
|
}
|
2021-07-28 09:35:25 +00:00
|
|
|
|
pub fn payload(&self) -> [Option<ItemName>; MAX_ITEMS] {
|
|
|
|
|
|
self.0
|
|
|
|
|
|
}
|
2021-07-28 15:00:25 +00:00
|
|
|
|
pub fn contains(&self, name: &str) -> bool {
|
|
|
|
|
|
for maybe_item in self.0.iter() {
|
|
|
|
|
|
if let Some(item) = maybe_item {
|
|
|
|
|
|
if item.as_str() == name {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
false
|
|
|
|
|
|
}
|
|
|
|
|
|
pub fn add(&mut self, name: &str) -> bool {
|
|
|
|
|
|
if self.contains(name) {
|
|
|
|
|
|
return true
|
|
|
|
|
|
}
|
|
|
|
|
|
for maybe_item in self.0.iter_mut() {
|
|
|
|
|
|
if maybe_item.is_none() {
|
|
|
|
|
|
*maybe_item = Some(ItemName::new(name));
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
false
|
|
|
|
|
|
}
|
|
|
|
|
|
pub fn remove(&mut self, name: &str) -> bool {
|
|
|
|
|
|
for maybe_item in self.0.iter_mut() {
|
|
|
|
|
|
if let Some(item) = maybe_item {
|
|
|
|
|
|
if item.as_str() == name {
|
|
|
|
|
|
*maybe_item = None;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
false
|
|
|
|
|
|
}
|
2021-07-27 20:27:14 +00:00
|
|
|
|
}
|
2021-07-25 16:51:22 +00:00
|
|
|
|
|
2021-07-27 17:01:39 +00:00
|
|
|
|
//#[derive(Debug)]
|
2021-07-28 09:35:25 +00:00
|
|
|
|
pub struct Modal<'a> {
|
2021-07-21 19:04:16 +00:00
|
|
|
|
pub sid: xous::SID,
|
|
|
|
|
|
pub gam: Gam,
|
|
|
|
|
|
pub xns: xous_names::XousNames,
|
2021-07-25 16:51:22 +00:00
|
|
|
|
pub top_text: Option<TextView>,
|
|
|
|
|
|
pub bot_text: Option<TextView>,
|
|
|
|
|
|
pub action: ActionType,
|
|
|
|
|
|
|
|
|
|
|
|
//pub index: usize, // currently selected item
|
2021-07-21 19:04:16 +00:00
|
|
|
|
pub canvas: Gid,
|
|
|
|
|
|
pub authtoken: [u32; 4],
|
|
|
|
|
|
pub margin: i16,
|
|
|
|
|
|
pub line_height: i16,
|
2021-07-26 20:40:12 +00:00
|
|
|
|
pub canvas_width: i16,
|
|
|
|
|
|
pub inverted: bool,
|
|
|
|
|
|
pub style: GlyphStyle,
|
2021-07-28 09:35:25 +00:00
|
|
|
|
pub helper_data: Option<Buffer<'a>>,
|
2021-07-28 19:30:03 +00:00
|
|
|
|
pub name: String::<128>,
|
2021-07-31 20:02:15 +00:00
|
|
|
|
|
|
|
|
|
|
// optimize draw time
|
|
|
|
|
|
top_dirty: bool,
|
|
|
|
|
|
top_memoized_height: Option<i16>,
|
|
|
|
|
|
bot_dirty: bool,
|
|
|
|
|
|
bot_memoized_height: Option<i16>,
|
2021-07-21 19:04:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-16 15:16:21 +00:00
|
|
|
|
fn recompute_canvas(modal: &mut Modal, top_text: Option<&str>, bot_text: Option<&str>, style: GlyphStyle) {
|
2021-07-28 15:00:25 +00:00
|
|
|
|
// we need to set a "max" size to our modal box, so that the text computations don't fail later on
|
|
|
|
|
|
let current_bounds = modal.gam.get_canvas_bounds(modal.canvas).expect("couldn't get current bounds");
|
|
|
|
|
|
|
2021-07-27 17:01:39 +00:00
|
|
|
|
// method:
|
|
|
|
|
|
// - we assume the GAM gives us an initial modal with a "maximum" height setting
|
|
|
|
|
|
// - items are populated within this maximal canvas setting, and then the actual height needed is computed
|
|
|
|
|
|
// - the canvas is resized to this actual height
|
|
|
|
|
|
// problems:
|
|
|
|
|
|
// - there is no sanity check on the size of the text boxes. So if you give the UX element a top_text box that's
|
|
|
|
|
|
// huge, it will just overflow the canvas size and nothing else will get drawn.
|
|
|
|
|
|
|
|
|
|
|
|
let mut total_height = modal.margin;
|
|
|
|
|
|
log::trace!("step 0 total_height: {}", total_height);
|
|
|
|
|
|
// compute height of top_text, if any
|
|
|
|
|
|
if let Some(top_str) = top_text {
|
|
|
|
|
|
let mut top_tv = TextView::new(modal.canvas,
|
|
|
|
|
|
TextBounds::GrowableFromTl(
|
2021-08-12 22:00:21 +00:00
|
|
|
|
Point::new(modal.margin, modal.margin),
|
2021-07-27 17:01:39 +00:00
|
|
|
|
(modal.canvas_width - modal.margin * 2) as u16
|
|
|
|
|
|
));
|
|
|
|
|
|
top_tv.draw_border = false;
|
|
|
|
|
|
top_tv.style = style;
|
|
|
|
|
|
top_tv.margin = Point::new(0, 0,); // all margin already accounted for in the raw bounds of the text drawing
|
|
|
|
|
|
top_tv.ellipsis = false;
|
|
|
|
|
|
top_tv.invert = modal.inverted;
|
light refactor to the GAM to solve a deadlock issue
This is a "no good choice" situation but there is a problem with
progress bars.
You want progress bars to update quickly, and you don't want
to have to context switch out for the entire graphics stack to
come back to you to approve the drawing of your progress bar update.
On the other hand, you don't want to short-circuit all the checks
on drawing stuff to the screen for the sake of progress bars --
right now, there are a number of checks in place to make sure you
can't draw stuff on parts of the screen you shouldn't, to avoid
fake messages and dialog boxes.
I had managed to work out a way to get a dialog box to redraw without
violating the security rules -- each redraw is checked by the defacing
routine -- however, due to the way I was computing the height of
the modal I was causing the dialog box to be resized to its largest
size and then shrunk again to fit the text every iteration. This
in essence also caused the defacement routine to run repeatedly,
which caused the GAM to also issue repeated redraw requests to
the main loop.
These redraw requests can't be serviced until the task being tracked
by the progress bar is completed. As the progress bar gets redrawn
almost a hundred times as part of the task, roughly a hundred messages
arrive in the server's queue before it can handle a single one.
This results in a deadlock situation on completion of the progress
bar, because we want to fire off a message to ourselves to go to
the next state in the Ux routine.
There are a few possible solutions to this:
1. Multi thread the heck out of the routine doing the progress bar,
so the dialog box and the slider are each in their own threads
with their own responders and then the thing doing the computation
is doing some Mutex-guarded-Arc thing.
2. Do some very unsafe bodge to allow sliders to do direct draws
that are unchecked
3. Add a check so that if the size of the dialog box doesn't change,
defacement isn't recomputed and thus redraw messages aren't sent back.
(1) doesn't work for a number of reasons -- in a general case, it's
probably OK, but it does cause a lot more memory usage (and we are
lean on memory); but more importantly, for this use case, our routine
is interacting with CSRs and those don't implement Send so you can't
pass them into a thread via a closure. You could maybe put the dialog
boxes themselves into an Arc Mutex thing but because this routine
was heavily coded to re-use the heavyweight Ux resources this becomes
a bit cumersome to code.
(2) is terrible
(3) ended up working and what is in this commit. I think it's OK
because a progress bar generally doesn't require changing the
size of a window to update its state; therefore the redraw is
deface-safe (since you aren't changing the bounds of what you were
already approved to draw in). Of course, if you have some sort
of a progress bar implementation that changes the size of the messages
reported up top so that the dialog box has to change size over and
over again, you still end up in the deadlock situation!
2021-08-11 17:25:35 +00:00
|
|
|
|
// specify a clip rect that's the biggest possible allowed. If we don't do this, the current canvas
|
|
|
|
|
|
// bounds are used, and the operation will fail if the text has to get bigger.
|
2021-08-12 22:00:21 +00:00
|
|
|
|
top_tv.clip_rect = Some(Rectangle::new(Point::new(0, 0), Point::new(current_bounds.x, crate::api::MODAL_Y_MAX - 2 * modal.line_height)));
|
2021-07-28 15:58:15 +00:00
|
|
|
|
write!(top_tv.text, "{}", top_str).unwrap();
|
2021-07-27 17:01:39 +00:00
|
|
|
|
|
|
|
|
|
|
log::trace!("posting top tv: {:?}", top_tv);
|
|
|
|
|
|
modal.gam.bounds_compute_textview(&mut top_tv).expect("couldn't simulate top text size");
|
|
|
|
|
|
if let Some(bounds) = top_tv.bounds_computed {
|
2021-08-12 22:00:21 +00:00
|
|
|
|
log::trace!("top_tv bounds computed {}", bounds.br.y - bounds.tl.y);
|
2021-07-27 17:01:39 +00:00
|
|
|
|
total_height += bounds.br.y - bounds.tl.y;
|
|
|
|
|
|
} else {
|
2021-08-12 22:00:21 +00:00
|
|
|
|
log::warn!("couldn't compute height for modal top_text: {:?}", top_tv);
|
|
|
|
|
|
// probably should find a better way to deal with this.
|
|
|
|
|
|
total_height += crate::api::MODAL_Y_MAX - (modal.line_height * 2);
|
2021-07-27 17:01:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
modal.top_text = Some(top_tv);
|
|
|
|
|
|
}
|
|
|
|
|
|
total_height += modal.margin;
|
|
|
|
|
|
|
|
|
|
|
|
// compute height of action item
|
|
|
|
|
|
log::trace!("step 1 total_height: {}", total_height);
|
2021-12-16 15:16:21 +00:00
|
|
|
|
total_height += modal.action.height(modal.line_height, modal.margin);
|
2021-07-27 17:01:39 +00:00
|
|
|
|
total_height += modal.margin;
|
|
|
|
|
|
|
|
|
|
|
|
// compute height of bot_text, if any
|
|
|
|
|
|
log::trace!("step 2 total_height: {}", total_height);
|
|
|
|
|
|
if let Some(bot_str) = bot_text {
|
|
|
|
|
|
let mut bot_tv = TextView::new(modal.canvas,
|
|
|
|
|
|
TextBounds::GrowableFromTl(
|
|
|
|
|
|
Point::new(modal.margin, total_height),
|
|
|
|
|
|
(modal.canvas_width - modal.margin * 2) as u16
|
|
|
|
|
|
));
|
|
|
|
|
|
bot_tv.draw_border = false;
|
|
|
|
|
|
bot_tv.style = style;
|
|
|
|
|
|
bot_tv.margin = Point::new(0, 0,); // all margin already accounted for in the raw bounds of the text drawing
|
|
|
|
|
|
bot_tv.ellipsis = false;
|
|
|
|
|
|
bot_tv.invert = modal.inverted;
|
light refactor to the GAM to solve a deadlock issue
This is a "no good choice" situation but there is a problem with
progress bars.
You want progress bars to update quickly, and you don't want
to have to context switch out for the entire graphics stack to
come back to you to approve the drawing of your progress bar update.
On the other hand, you don't want to short-circuit all the checks
on drawing stuff to the screen for the sake of progress bars --
right now, there are a number of checks in place to make sure you
can't draw stuff on parts of the screen you shouldn't, to avoid
fake messages and dialog boxes.
I had managed to work out a way to get a dialog box to redraw without
violating the security rules -- each redraw is checked by the defacing
routine -- however, due to the way I was computing the height of
the modal I was causing the dialog box to be resized to its largest
size and then shrunk again to fit the text every iteration. This
in essence also caused the defacement routine to run repeatedly,
which caused the GAM to also issue repeated redraw requests to
the main loop.
These redraw requests can't be serviced until the task being tracked
by the progress bar is completed. As the progress bar gets redrawn
almost a hundred times as part of the task, roughly a hundred messages
arrive in the server's queue before it can handle a single one.
This results in a deadlock situation on completion of the progress
bar, because we want to fire off a message to ourselves to go to
the next state in the Ux routine.
There are a few possible solutions to this:
1. Multi thread the heck out of the routine doing the progress bar,
so the dialog box and the slider are each in their own threads
with their own responders and then the thing doing the computation
is doing some Mutex-guarded-Arc thing.
2. Do some very unsafe bodge to allow sliders to do direct draws
that are unchecked
3. Add a check so that if the size of the dialog box doesn't change,
defacement isn't recomputed and thus redraw messages aren't sent back.
(1) doesn't work for a number of reasons -- in a general case, it's
probably OK, but it does cause a lot more memory usage (and we are
lean on memory); but more importantly, for this use case, our routine
is interacting with CSRs and those don't implement Send so you can't
pass them into a thread via a closure. You could maybe put the dialog
boxes themselves into an Arc Mutex thing but because this routine
was heavily coded to re-use the heavyweight Ux resources this becomes
a bit cumersome to code.
(2) is terrible
(3) ended up working and what is in this commit. I think it's OK
because a progress bar generally doesn't require changing the
size of a window to update its state; therefore the redraw is
deface-safe (since you aren't changing the bounds of what you were
already approved to draw in). Of course, if you have some sort
of a progress bar implementation that changes the size of the messages
reported up top so that the dialog box has to change size over and
over again, you still end up in the deadlock situation!
2021-08-11 17:25:35 +00:00
|
|
|
|
// specify a clip rect that's the biggest possible allowed. If we don't do this, the current canvas
|
|
|
|
|
|
// bounds are used, and the operation will fail if the text has to get bigger.
|
2021-08-12 22:00:21 +00:00
|
|
|
|
bot_tv.clip_rect = Some(Rectangle::new(Point::new(0, 0), Point::new(current_bounds.x, crate::api::MODAL_Y_MAX - 2 * modal.line_height)));
|
2021-07-28 15:58:15 +00:00
|
|
|
|
write!(bot_tv.text, "{}", bot_str).unwrap();
|
2021-07-27 17:01:39 +00:00
|
|
|
|
|
2021-07-28 15:00:25 +00:00
|
|
|
|
log::trace!("posting bot tv: {:?}", bot_tv);
|
2021-07-27 17:01:39 +00:00
|
|
|
|
modal.gam.bounds_compute_textview(&mut bot_tv).expect("couldn't simulate bot text size");
|
|
|
|
|
|
if let Some(bounds) = bot_tv.bounds_computed {
|
|
|
|
|
|
total_height += bounds.br.y - bounds.tl.y;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
log::error!("couldn't compute height for modal bot_text: {:?}", bot_tv);
|
|
|
|
|
|
panic!("couldn't compute height for modal bot_text");
|
|
|
|
|
|
}
|
|
|
|
|
|
modal.bot_text = Some(bot_tv);
|
|
|
|
|
|
total_height += modal.margin;
|
|
|
|
|
|
}
|
|
|
|
|
|
log::trace!("step 3 total_height: {}", total_height);
|
|
|
|
|
|
|
|
|
|
|
|
let current_bounds = modal.gam.get_canvas_bounds(modal.canvas).expect("couldn't get current bounds");
|
|
|
|
|
|
let mut new_bounds = SetCanvasBoundsRequest {
|
|
|
|
|
|
requested: Point::new(current_bounds.x, total_height),
|
|
|
|
|
|
granted: None,
|
|
|
|
|
|
token_type: TokenType::App,
|
|
|
|
|
|
token: modal.authtoken,
|
|
|
|
|
|
};
|
light refactor to the GAM to solve a deadlock issue
This is a "no good choice" situation but there is a problem with
progress bars.
You want progress bars to update quickly, and you don't want
to have to context switch out for the entire graphics stack to
come back to you to approve the drawing of your progress bar update.
On the other hand, you don't want to short-circuit all the checks
on drawing stuff to the screen for the sake of progress bars --
right now, there are a number of checks in place to make sure you
can't draw stuff on parts of the screen you shouldn't, to avoid
fake messages and dialog boxes.
I had managed to work out a way to get a dialog box to redraw without
violating the security rules -- each redraw is checked by the defacing
routine -- however, due to the way I was computing the height of
the modal I was causing the dialog box to be resized to its largest
size and then shrunk again to fit the text every iteration. This
in essence also caused the defacement routine to run repeatedly,
which caused the GAM to also issue repeated redraw requests to
the main loop.
These redraw requests can't be serviced until the task being tracked
by the progress bar is completed. As the progress bar gets redrawn
almost a hundred times as part of the task, roughly a hundred messages
arrive in the server's queue before it can handle a single one.
This results in a deadlock situation on completion of the progress
bar, because we want to fire off a message to ourselves to go to
the next state in the Ux routine.
There are a few possible solutions to this:
1. Multi thread the heck out of the routine doing the progress bar,
so the dialog box and the slider are each in their own threads
with their own responders and then the thing doing the computation
is doing some Mutex-guarded-Arc thing.
2. Do some very unsafe bodge to allow sliders to do direct draws
that are unchecked
3. Add a check so that if the size of the dialog box doesn't change,
defacement isn't recomputed and thus redraw messages aren't sent back.
(1) doesn't work for a number of reasons -- in a general case, it's
probably OK, but it does cause a lot more memory usage (and we are
lean on memory); but more importantly, for this use case, our routine
is interacting with CSRs and those don't implement Send so you can't
pass them into a thread via a closure. You could maybe put the dialog
boxes themselves into an Arc Mutex thing but because this routine
was heavily coded to re-use the heavyweight Ux resources this becomes
a bit cumersome to code.
(2) is terrible
(3) ended up working and what is in this commit. I think it's OK
because a progress bar generally doesn't require changing the
size of a window to update its state; therefore the redraw is
deface-safe (since you aren't changing the bounds of what you were
already approved to draw in). Of course, if you have some sort
of a progress bar implementation that changes the size of the messages
reported up top so that the dialog box has to change size over and
over again, you still end up in the deadlock situation!
2021-08-11 17:25:35 +00:00
|
|
|
|
// don't send the request if there is no change in the size of things. This is because the request is expensive -- it will
|
|
|
|
|
|
// result in a redraw of everything, plus defacement, etc.
|
|
|
|
|
|
if new_bounds.requested != current_bounds {
|
|
|
|
|
|
log::debug!("applying recomputed bounds of {:?}", new_bounds);
|
|
|
|
|
|
modal.gam.set_canvas_bounds_request(&mut new_bounds).expect("couldn't call set bounds");
|
|
|
|
|
|
}
|
2021-07-27 17:01:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-28 09:35:25 +00:00
|
|
|
|
impl<'a> Modal<'a> {
|
|
|
|
|
|
pub fn new(name: &str, action: ActionType, top_text: Option<&str>, bot_text: Option<&str>, style: GlyphStyle, margin: i16) -> Modal<'a> {
|
2021-07-21 19:04:16 +00:00
|
|
|
|
let xns = xous_names::XousNames::new().unwrap();
|
|
|
|
|
|
let sid = xous::create_server().expect("can't create private modal message server");
|
|
|
|
|
|
let gam = Gam::new(&xns).expect("can't connect to GAM");
|
|
|
|
|
|
let authtoken = gam.register_ux(
|
|
|
|
|
|
UxRegistration {
|
|
|
|
|
|
app_name: String::<128>::from_str(name),
|
|
|
|
|
|
ux_type: UxType::Modal,
|
|
|
|
|
|
predictor: None,
|
|
|
|
|
|
listener: sid.to_array(),
|
|
|
|
|
|
redraw_id: ModalOpcode::Redraw.to_u32().unwrap(),
|
|
|
|
|
|
gotinput_id: None,
|
|
|
|
|
|
audioframe_id: None,
|
2022-04-01 14:54:33 +00:00
|
|
|
|
focuschange_id: None, // should always be none because we're not an app
|
2021-07-21 19:04:16 +00:00
|
|
|
|
rawkeys_id: Some(ModalOpcode::Rawkeys.to_u32().unwrap()),
|
|
|
|
|
|
}
|
|
|
|
|
|
).expect("couldn't register my Ux element with GAM");
|
|
|
|
|
|
assert!(authtoken.is_some(), "Couldn't register modal. Did you remember to add the app_name to the tokens.rs expected boot contexts list?");
|
|
|
|
|
|
log::debug!("requesting content canvas for modal");
|
|
|
|
|
|
let canvas = gam.request_content_canvas(authtoken.unwrap()).expect("couldn't get my content canvas from GAM");
|
2021-07-28 15:00:25 +00:00
|
|
|
|
let line_height = if xous::LANG == "zh" {
|
|
|
|
|
|
// zh has no "small" style
|
|
|
|
|
|
gam.glyph_height_hint(GlyphStyle::Regular).expect("couldn't get glyph height hint") as i16
|
|
|
|
|
|
} else {
|
|
|
|
|
|
gam.glyph_height_hint(style).expect("couldn't get glyph height hint") as i16
|
|
|
|
|
|
};
|
2021-07-26 20:40:12 +00:00
|
|
|
|
let canvas_bounds = gam.get_canvas_bounds(canvas).expect("couldn't get starting canvas bounds");
|
|
|
|
|
|
|
2021-07-27 17:01:39 +00:00
|
|
|
|
log::trace!("initializing Modal structure");
|
2021-07-26 20:40:12 +00:00
|
|
|
|
// check to see if this is a password field or not
|
|
|
|
|
|
// note: if a modal claims it's a password field but lacks sufficient trust level, the GAM will refuse
|
|
|
|
|
|
// to render the element.
|
|
|
|
|
|
let inverted = match action {
|
|
|
|
|
|
ActionType::TextEntry(_) => action.is_password(),
|
|
|
|
|
|
_ => false
|
|
|
|
|
|
};
|
2021-07-25 16:51:22 +00:00
|
|
|
|
|
|
|
|
|
|
// we now have a canvas that is some minimal height, but with the final width as allowed by the GAM.
|
|
|
|
|
|
// compute the final height based upon the contents within.
|
|
|
|
|
|
let mut modal = Modal {
|
2021-07-21 19:04:16 +00:00
|
|
|
|
sid,
|
|
|
|
|
|
gam,
|
|
|
|
|
|
xns,
|
2021-07-26 20:40:12 +00:00
|
|
|
|
top_text: None,
|
|
|
|
|
|
bot_text: None,
|
2021-07-25 16:51:22 +00:00
|
|
|
|
action,
|
2021-07-21 19:04:16 +00:00
|
|
|
|
canvas,
|
|
|
|
|
|
authtoken: authtoken.unwrap(),
|
2021-07-28 09:35:25 +00:00
|
|
|
|
margin,
|
2021-07-21 19:04:16 +00:00
|
|
|
|
line_height,
|
2021-07-26 20:40:12 +00:00
|
|
|
|
canvas_width: canvas_bounds.x, // memoize this, it shouldn't change
|
|
|
|
|
|
inverted,
|
|
|
|
|
|
style,
|
2021-07-28 09:35:25 +00:00
|
|
|
|
helper_data: None,
|
2021-07-28 19:30:03 +00:00
|
|
|
|
name: String::<128>::from_str(name),
|
2021-07-31 20:02:15 +00:00
|
|
|
|
top_dirty: true,
|
|
|
|
|
|
bot_dirty: true,
|
|
|
|
|
|
top_memoized_height: None,
|
|
|
|
|
|
bot_memoized_height: None,
|
2021-07-25 16:51:22 +00:00
|
|
|
|
};
|
2021-12-16 15:16:21 +00:00
|
|
|
|
recompute_canvas(&mut modal, top_text, bot_text, style);
|
2021-07-25 16:51:22 +00:00
|
|
|
|
modal
|
2021-07-21 19:04:16 +00:00
|
|
|
|
}
|
2021-07-28 19:30:03 +00:00
|
|
|
|
pub fn activate(&self) {
|
2022-02-04 18:03:56 +00:00
|
|
|
|
const POLL_DELAY_MS: usize = 857;
|
|
|
|
|
|
match self.gam.raise_modal(self.name.to_str()) {
|
|
|
|
|
|
Ok(_) => (),
|
|
|
|
|
|
Err(_) => {
|
|
|
|
|
|
std::thread::spawn({
|
|
|
|
|
|
let name = self.name.clone();
|
|
|
|
|
|
move || {
|
|
|
|
|
|
let xns = xous_names::XousNames::new().unwrap();
|
|
|
|
|
|
let ticktimer = ticktimer_server::Ticktimer::new().unwrap();
|
|
|
|
|
|
ticktimer.sleep_ms(POLL_DELAY_MS).unwrap();
|
|
|
|
|
|
let gam = crate::Gam::new(&xns).unwrap();
|
|
|
|
|
|
while gam.raise_modal(name.to_str()).is_err() {
|
|
|
|
|
|
log::info!("Couldn't raise {}; retrying...", name);
|
|
|
|
|
|
ticktimer.sleep_ms(POLL_DELAY_MS).unwrap();
|
|
|
|
|
|
}
|
|
|
|
|
|
log::info!("Success! exiting polling thread.");
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2022-02-04 15:59:20 +00:00
|
|
|
|
}
|
2021-07-28 19:30:03 +00:00
|
|
|
|
}
|
2021-07-25 16:51:22 +00:00
|
|
|
|
|
2021-07-28 09:35:25 +00:00
|
|
|
|
/// this function spawns a client-side thread to forward redraw and key event
|
|
|
|
|
|
/// messages on to a local server. The goal is to keep the local server's SID
|
|
|
|
|
|
/// a secret. The GAM only knows the single-use SID for redraw commands; this
|
|
|
|
|
|
/// isolates a server's private command set from the GAM.
|
|
|
|
|
|
pub fn spawn_helper(&mut self, private_sid: xous::SID, public_sid: xous::SID, redraw_op: u32, rawkeys_op: u32, drop_op: u32) {
|
|
|
|
|
|
let helper_data = MsgForwarder {
|
|
|
|
|
|
private_sid: private_sid.to_array(),
|
|
|
|
|
|
public_sid: public_sid.to_array(),
|
|
|
|
|
|
redraw_op,
|
|
|
|
|
|
rawkeys_op,
|
|
|
|
|
|
drop_op
|
|
|
|
|
|
};
|
2021-07-28 15:58:15 +00:00
|
|
|
|
let buf = Buffer::into_buf(helper_data).expect("couldn't allocate helper data for helper thread");
|
2021-07-28 09:35:25 +00:00
|
|
|
|
let (addr, size, offset) = unsafe{buf.to_raw_parts()};
|
|
|
|
|
|
self.helper_data = Some(buf);
|
|
|
|
|
|
xous::create_thread_3(crate::forwarding_thread, addr, size, offset).expect("couldn't spawn a helper thread");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
light refactor to the GAM to solve a deadlock issue
This is a "no good choice" situation but there is a problem with
progress bars.
You want progress bars to update quickly, and you don't want
to have to context switch out for the entire graphics stack to
come back to you to approve the drawing of your progress bar update.
On the other hand, you don't want to short-circuit all the checks
on drawing stuff to the screen for the sake of progress bars --
right now, there are a number of checks in place to make sure you
can't draw stuff on parts of the screen you shouldn't, to avoid
fake messages and dialog boxes.
I had managed to work out a way to get a dialog box to redraw without
violating the security rules -- each redraw is checked by the defacing
routine -- however, due to the way I was computing the height of
the modal I was causing the dialog box to be resized to its largest
size and then shrunk again to fit the text every iteration. This
in essence also caused the defacement routine to run repeatedly,
which caused the GAM to also issue repeated redraw requests to
the main loop.
These redraw requests can't be serviced until the task being tracked
by the progress bar is completed. As the progress bar gets redrawn
almost a hundred times as part of the task, roughly a hundred messages
arrive in the server's queue before it can handle a single one.
This results in a deadlock situation on completion of the progress
bar, because we want to fire off a message to ourselves to go to
the next state in the Ux routine.
There are a few possible solutions to this:
1. Multi thread the heck out of the routine doing the progress bar,
so the dialog box and the slider are each in their own threads
with their own responders and then the thing doing the computation
is doing some Mutex-guarded-Arc thing.
2. Do some very unsafe bodge to allow sliders to do direct draws
that are unchecked
3. Add a check so that if the size of the dialog box doesn't change,
defacement isn't recomputed and thus redraw messages aren't sent back.
(1) doesn't work for a number of reasons -- in a general case, it's
probably OK, but it does cause a lot more memory usage (and we are
lean on memory); but more importantly, for this use case, our routine
is interacting with CSRs and those don't implement Send so you can't
pass them into a thread via a closure. You could maybe put the dialog
boxes themselves into an Arc Mutex thing but because this routine
was heavily coded to re-use the heavyweight Ux resources this becomes
a bit cumersome to code.
(2) is terrible
(3) ended up working and what is in this commit. I think it's OK
because a progress bar generally doesn't require changing the
size of a window to update its state; therefore the redraw is
deface-safe (since you aren't changing the bounds of what you were
already approved to draw in). Of course, if you have some sort
of a progress bar implementation that changes the size of the messages
reported up top so that the dialog box has to change size over and
over again, you still end up in the deadlock situation!
2021-08-11 17:25:35 +00:00
|
|
|
|
pub fn redraw(&mut self) {
|
2021-08-21 18:18:02 +00:00
|
|
|
|
const BORDER_WIDTH: i16 = 3;
|
2021-07-25 16:51:22 +00:00
|
|
|
|
log::debug!("modal redraw");
|
2021-07-21 19:04:16 +00:00
|
|
|
|
let canvas_size = self.gam.get_canvas_bounds(self.canvas).unwrap();
|
2022-02-05 15:20:41 +00:00
|
|
|
|
let do_redraw = self.top_dirty || self.bot_dirty || self.inverted;
|
2021-07-21 19:04:16 +00:00
|
|
|
|
// draw the outer border
|
2021-07-31 20:02:15 +00:00
|
|
|
|
if do_redraw {
|
|
|
|
|
|
self.gam.draw_rounded_rectangle(self.canvas,
|
|
|
|
|
|
RoundedRectangle::new(
|
|
|
|
|
|
Rectangle::new_with_style(Point::new(0, 0), canvas_size,
|
2021-08-21 18:18:02 +00:00
|
|
|
|
DrawStyle::new(if self.inverted{PixelColor::Dark} else {PixelColor::Light}, PixelColor::Dark, BORDER_WIDTH)
|
2021-07-31 20:02:15 +00:00
|
|
|
|
), 5
|
|
|
|
|
|
)).unwrap();
|
|
|
|
|
|
}
|
2021-07-21 19:04:16 +00:00
|
|
|
|
|
2021-07-26 20:40:12 +00:00
|
|
|
|
let mut cur_height = self.margin;
|
|
|
|
|
|
if let Some(mut tv) = self.top_text {
|
2021-07-31 20:02:15 +00:00
|
|
|
|
if do_redraw {
|
|
|
|
|
|
self.gam.post_textview(&mut tv).expect("couldn't draw text");
|
|
|
|
|
|
if let Some(bounds) = tv.bounds_computed {
|
2021-08-12 22:00:21 +00:00
|
|
|
|
let y = bounds.br.y - bounds.tl.y;
|
|
|
|
|
|
let y_clip = if y > MODAL_Y_MAX - self.line_height * 3 {
|
|
|
|
|
|
log::warn!("overside text, clipping back {}", MODAL_Y_MAX - (self.line_height * 2));
|
|
|
|
|
|
MODAL_Y_MAX - (self.line_height * 2)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
y
|
|
|
|
|
|
};
|
|
|
|
|
|
cur_height += y_clip;
|
|
|
|
|
|
log::trace!("top_tv height: {}", y_clip);
|
|
|
|
|
|
self.top_memoized_height = Some(y_clip);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
log::warn!("text bounds didn't compute setting to max");
|
|
|
|
|
|
self.top_memoized_height = Some(MODAL_Y_MAX - (self.line_height * 2));
|
2021-07-31 20:02:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
self.top_dirty = false;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
cur_height += self.top_memoized_height.expect("internal error: memoization didn't work correctly");
|
2021-07-21 19:04:16 +00:00
|
|
|
|
}
|
2021-07-31 20:02:15 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
self.top_dirty = false;
|
2021-07-21 19:04:16 +00:00
|
|
|
|
}
|
2021-07-26 20:40:12 +00:00
|
|
|
|
|
2021-07-31 20:02:15 +00:00
|
|
|
|
let action_height = self.action.height(self.line_height, self.margin);
|
|
|
|
|
|
if !do_redraw {
|
|
|
|
|
|
// the action area wasn't blanked, so blank it as prep for the action redraw
|
|
|
|
|
|
self.gam.draw_rectangle(self.canvas,
|
2021-08-21 18:18:02 +00:00
|
|
|
|
Rectangle::new_with_style(Point::new(BORDER_WIDTH, cur_height), Point::new(canvas_size.x - BORDER_WIDTH, cur_height + action_height),
|
|
|
|
|
|
DrawStyle::new(
|
|
|
|
|
|
if self.inverted{PixelColor::Dark} else {PixelColor::Light},
|
|
|
|
|
|
if self.inverted{PixelColor::Dark} else {PixelColor::Light}, 0)
|
2021-07-31 20:02:15 +00:00
|
|
|
|
)).unwrap();
|
|
|
|
|
|
}
|
2021-07-26 20:40:12 +00:00
|
|
|
|
self.action.redraw(cur_height, &self);
|
2021-07-31 20:02:15 +00:00
|
|
|
|
cur_height += action_height;
|
2021-07-26 20:40:12 +00:00
|
|
|
|
|
|
|
|
|
|
if let Some(mut tv) = self.bot_text {
|
2021-07-31 20:02:15 +00:00
|
|
|
|
if do_redraw {
|
|
|
|
|
|
self.gam.post_textview(&mut tv).expect("couldn't draw text");
|
|
|
|
|
|
if let Some(bounds) = tv.bounds_computed {
|
|
|
|
|
|
cur_height += bounds.br.y - bounds.tl.y;
|
|
|
|
|
|
self.bot_memoized_height = Some(bounds.br.y - bounds.tl.y);
|
|
|
|
|
|
}
|
|
|
|
|
|
self.bot_dirty = false;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
cur_height += self.bot_memoized_height.expect("internal error: memoization didn't work correctly");
|
2021-07-26 20:40:12 +00:00
|
|
|
|
}
|
2021-07-31 20:02:15 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
self.bot_dirty = false;
|
2021-07-26 20:40:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
log::trace!("total height: {}", cur_height);
|
2022-02-05 10:55:46 +00:00
|
|
|
|
log::trace!("modal redraw##");
|
2021-07-21 19:04:16 +00:00
|
|
|
|
self.gam.redraw().unwrap();
|
|
|
|
|
|
}
|
2021-07-25 16:51:22 +00:00
|
|
|
|
|
2021-07-21 19:04:16 +00:00
|
|
|
|
pub fn key_event(&mut self, keys: [char; 4]) {
|
|
|
|
|
|
for &k in keys.iter() {
|
2021-07-27 09:30:37 +00:00
|
|
|
|
if k != '\u{0}' {
|
|
|
|
|
|
log::debug!("got key '{}'", k);
|
2021-07-28 15:00:25 +00:00
|
|
|
|
let (err, close) = self.action.key_action(k);
|
|
|
|
|
|
if let Some(err_msg) = err {
|
|
|
|
|
|
self.modify(None, None, false, Some(err_msg.to_str()), false, None);
|
2021-07-27 17:01:39 +00:00
|
|
|
|
} else {
|
2021-07-28 15:00:25 +00:00
|
|
|
|
if close {
|
2021-07-28 19:30:03 +00:00
|
|
|
|
log::debug!("closing modal");
|
2021-07-28 15:00:25 +00:00
|
|
|
|
// if it's a "close" button, invoke the GAM to put our box away
|
|
|
|
|
|
self.gam.relinquish_focus().unwrap();
|
2022-02-04 09:11:24 +00:00
|
|
|
|
break; // don't process any more keys after a close message
|
2021-07-21 19:04:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-07-27 09:30:37 +00:00
|
|
|
|
self.redraw();
|
2021-07-21 19:04:16 +00:00
|
|
|
|
}
|
2021-07-27 17:01:39 +00:00
|
|
|
|
|
|
|
|
|
|
/// this function will modify UX elements if any of the arguments are Some()
|
2021-07-28 15:00:25 +00:00
|
|
|
|
/// if None, the element is unchanged.
|
|
|
|
|
|
/// If a text section is set to remove, but Some() is given for the update, the text is not removed, and instead replaced with the updated text.
|
|
|
|
|
|
pub fn modify(&mut self, update_action: Option<ActionType>,
|
|
|
|
|
|
update_top_text: Option<&str>, remove_top: bool,
|
|
|
|
|
|
update_bot_text: Option<&str>, remove_bot: bool,
|
|
|
|
|
|
update_style: Option<GlyphStyle>) {
|
2021-12-16 15:16:21 +00:00
|
|
|
|
if let Some(action) = update_action {
|
2021-07-28 15:00:25 +00:00
|
|
|
|
self.action = action;
|
2021-07-27 17:01:39 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
2021-07-28 15:00:25 +00:00
|
|
|
|
if remove_top {
|
2021-07-31 20:02:15 +00:00
|
|
|
|
self.top_dirty = true;
|
2021-07-28 15:00:25 +00:00
|
|
|
|
self.top_text = None;
|
|
|
|
|
|
}
|
|
|
|
|
|
if remove_bot {
|
2021-07-31 20:02:15 +00:00
|
|
|
|
self.bot_dirty = true;
|
2021-07-28 15:00:25 +00:00
|
|
|
|
self.bot_text = None;
|
|
|
|
|
|
}
|
2021-07-31 20:02:15 +00:00
|
|
|
|
if update_top_text.is_some() {
|
|
|
|
|
|
self.top_dirty = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if update_bot_text.is_some() {
|
|
|
|
|
|
self.bot_dirty = true;
|
|
|
|
|
|
}
|
2021-07-28 15:00:25 +00:00
|
|
|
|
|
2021-07-27 17:01:39 +00:00
|
|
|
|
let mut top_tv_temp = String::<3072>::new(); // size matches that used in TextView
|
|
|
|
|
|
if let Some(top_text) = update_top_text {
|
|
|
|
|
|
write!(top_tv_temp, "{}", top_text).unwrap();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if let Some(top_text) = self.top_text {
|
|
|
|
|
|
write!(top_tv_temp, "{}", top_text).unwrap();
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
let top_text = if self.top_text.is_none() && update_top_text.is_none() {
|
|
|
|
|
|
None
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Some(top_tv_temp.to_str())
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let mut bot_tv_temp = String::<3072>::new(); // size matches that used in TextView
|
|
|
|
|
|
if let Some(bot_text) = update_bot_text {
|
|
|
|
|
|
write!(bot_tv_temp, "{}", bot_text).unwrap();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if let Some(bot_text) = self.bot_text {
|
|
|
|
|
|
write!(bot_tv_temp, "{}", bot_text).unwrap();
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
let bot_text = if self.bot_text.is_none() && update_bot_text.is_none() {
|
|
|
|
|
|
None
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Some(bot_tv_temp.to_str())
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let style = if let Some(style) = update_style {
|
2021-08-11 15:22:15 +00:00
|
|
|
|
self.top_dirty = true;
|
|
|
|
|
|
self.bot_dirty = true;
|
2021-07-27 17:01:39 +00:00
|
|
|
|
style
|
|
|
|
|
|
} else {
|
|
|
|
|
|
self.style
|
|
|
|
|
|
};
|
2021-12-16 15:16:21 +00:00
|
|
|
|
recompute_canvas(self, top_text, bot_text, style);
|
2021-07-27 17:01:39 +00:00
|
|
|
|
}
|
2021-08-08 19:27:43 +00:00
|
|
|
|
}
|
2021-08-21 16:37:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
old notes to remind myself of how I got here.
|
|
|
|
|
|
|
|
|
|
|
|
design ideas
|
|
|
|
|
|
|
|
|
|
|
|
Modal for password request:
|
|
|
|
|
|
---------------------
|
|
|
|
|
|
| Password Type: Updater
|
|
|
|
|
|
| Requester: RootKeys
|
|
|
|
|
|
| Reason: The updater modal has not been set.
|
|
|
|
|
|
| Security Level: Critical
|
|
|
|
|
|
|
|
|
|
|
|
|
| *****4f_
|
|
|
|
|
|
|
|
|
|
|
|
|
| ← 👁️ 🕶️ * →
|
|
|
|
|
|
|--------------------
|
|
|
|
|
|
|
|
|
|
|
|
Item primitives:
|
|
|
|
|
|
- text bubble
|
|
|
|
|
|
- text entry field (with confidentiality option)
|
|
|
|
|
|
- left/right radio select
|
|
|
|
|
|
- up/down radio select
|
|
|
|
|
|
|
|
|
|
|
|
Then simple menu prompt after password entry:
|
|
|
|
|
|
---------------------
|
|
|
|
|
|
| [x] Persist until reboot
|
|
|
|
|
|
| [ ] Persist until suspend
|
|
|
|
|
|
| [ ] Use once
|
|
|
|
|
|
---------------------
|
|
|
|
|
|
|
|
|
|
|
|
General form for modals:
|
|
|
|
|
|
|
|
|
|
|
|
[top text]
|
|
|
|
|
|
|
|
|
|
|
|
[action form]
|
|
|
|
|
|
|
|
|
|
|
|
[bottom text]
|
|
|
|
|
|
|
|
|
|
|
|
- "top text" is an optional TextArea
|
|
|
|
|
|
- "action form" is a mandatory field that handles interactions
|
|
|
|
|
|
- "bottom text" is an optional TextArea
|
|
|
|
|
|
|
|
|
|
|
|
Action form can be exactly one of the following:
|
|
|
|
|
|
- password text field - enter closes the form, has visibility options as left/right arrows; entered text wraps
|
|
|
|
|
|
- regular text field - enter closes the form, visibility is always visible; entered text wraps
|
|
|
|
|
|
- radio buttons - has an explicit "okay" button to close the modal; up/down arrows + select/enter pick the radio
|
|
|
|
|
|
- check boxes - has an explicit "okay" button to close the modal; up/down arrows + select/enter checks boxes
|
|
|
|
|
|
- slider - left/right moves the slider, enter/select closes the modal
|
2022-04-08 04:16:15 +00:00
|
|
|
|
*/
|