light-fingered changes to the modals layer to accommodate ux-api

trying to keep this layer as cross-compatible as possible while
compressing the stack underneath it
This commit is contained in:
bunnie 2025-02-11 16:26:13 +08:00
parent 6e18096247
commit 79e95742b9
4 changed files with 34 additions and 29 deletions

View file

@ -35,9 +35,10 @@ utralib = { version = "0.1.25", optional = true, default-features = false }
[features] [features]
precursor = ["utralib/precursor", "trng", "gam", "tts-frontend"] precursor = ["utralib/precursor", "trng", "gam", "tts-frontend"]
hosted = ["utralib/hosted", "trng", "gam", "tts-frontend"] hosted = ["utralib/hosted", "trng", "gam", "tts-frontend"]
hosted-baosec = ["ux-api"] hosted-baosec = ["ux-api/hosted-baosec"]
renode = ["utralib/renode", "trng", "gam", "tts-frontend"] renode = ["utralib/renode", "trng", "gam", "tts-frontend"]
cramium-soc = ["utralib/cramium-soc", "cram-hal-service"] cramium-soc = ["utralib/cramium-soc", "cram-hal-service"]
board-baosec = ["ux-api/board-baosec"]
tts = [] tts = []
ditherpunk = [] ditherpunk = []

View file

@ -1,8 +1,8 @@
#[cfg(feature = "ditherpunk")] #[cfg(feature = "ditherpunk")]
use gam::Tile; use gam::Tile;
#[cfg(not(any(feature = "hosted-baosec")))] #[cfg(not(any(feature = "hosted-baosec", feature = "cramium-soc")))]
use gam::modal::*; use gam::modal::*;
#[cfg(any(feature = "hosted-baosec"))] #[cfg(any(feature = "hosted-baosec", feature = "cramium-soc"))]
use ux_api::widgets::*; use ux_api::widgets::*;
pub(crate) const SERVER_NAME_MODALS: &str = "_Modal Dialog Server_"; pub(crate) const SERVER_NAME_MODALS: &str = "_Modal Dialog Server_";

View file

@ -12,10 +12,10 @@ use std::cmp::max;
use std::convert::TryInto; use std::convert::TryInto;
use bit_field::BitField; use bit_field::BitField;
#[cfg(not(any(feature = "hosted-baosec")))] #[cfg(not(any(feature = "hosted-baosec", feature = "cramium-soc")))]
use gam::*; use gam::*;
use num_traits::*; use num_traits::*;
#[cfg(any(feature = "hosted-baosec"))] #[cfg(any(feature = "hosted-baosec", feature = "cramium-soc"))]
use ux_api::widgets::*; use ux_api::widgets::*;
use xous::{CID, Message, send_message}; use xous::{CID, Message, send_message};
use xous_ipc::Buffer; use xous_ipc::Buffer;

View file

@ -31,12 +31,14 @@ mod api;
use api::*; use api::*;
#[cfg(feature = "ditherpunk")] #[cfg(feature = "ditherpunk")]
use gam::Bitmap; use gam::Bitmap;
#[cfg(not(any(feature = "hosted-baosec")))] #[cfg(not(any(feature = "hosted-baosec", feature = "cramium-soc")))]
use gam::modal::*; use gam::modal::*;
use locales::t; use locales::t;
#[cfg(feature = "tts")] #[cfg(feature = "tts")]
use tts_frontend::TtsFrontend; use tts_frontend::TtsFrontend;
#[cfg(any(feature = "hosted-baosec"))] #[cfg(any(feature = "hosted-baosec", feature = "cramium-soc"))]
use ux_api::minigfx::*;
#[cfg(any(feature = "hosted-baosec", feature = "cramium-soc"))]
use ux_api::widgets::*; use ux_api::widgets::*;
use xous::{Message, msg_blocking_scalar_unpack, msg_scalar_unpack, send_message}; use xous::{Message, msg_blocking_scalar_unpack, msg_scalar_unpack, send_message};
use xous_ipc::Buffer; use xous_ipc::Buffer;
@ -65,7 +67,10 @@ enum RendererState {
RunImage(ManagedImage), RunImage(ManagedImage),
} }
#[cfg(not(any(feature = "hosted-baosec", feature = "cramium-soc")))]
const DEFAULT_STYLE: GlyphStyle = gam::SYSTEM_STYLE; const DEFAULT_STYLE: GlyphStyle = gam::SYSTEM_STYLE;
#[cfg(any(feature = "hosted-baosec", feature = "cramium-soc"))]
const DEFAULT_STYLE: GlyphStyle = ux_api::SYSTEM_STYLE;
fn main() -> ! { fn main() -> ! {
#[cfg(not(feature = "ditherpunk"))] #[cfg(not(feature = "ditherpunk"))]
@ -129,6 +134,7 @@ fn wrapped_main() -> ! {
DEFAULT_STYLE, DEFAULT_STYLE,
8, 8,
); );
#[cfg(not(any(feature = "hosted-baosec", feature = "cramium-soc")))]
renderer_modal.spawn_helper( renderer_modal.spawn_helper(
modals_sid, modals_sid,
renderer_modal.sid, renderer_modal.sid,
@ -477,10 +483,8 @@ fn wrapped_main() -> ! {
log::debug!("should be active!"); log::debug!("should be active!");
} }
RendererState::RunNotification(config) => { RendererState::RunNotification(config) => {
let mut notification = gam::modal::Notification::new( let mut notification =
renderer_cid, Notification::new(renderer_cid, Opcode::NotificationReturn.to_u32().unwrap());
Opcode::NotificationReturn.to_u32().unwrap(),
);
let text = config.message.as_str(); let text = config.message.as_str();
let tmp: String; let tmp: String;
let qrtext = match &config.qrtext { let qrtext = match &config.qrtext {
@ -504,16 +508,20 @@ fn wrapped_main() -> ! {
renderer_modal.activate(); renderer_modal.activate();
} }
RendererState::RunBip39(config) => { RendererState::RunBip39(config) => {
let notification = gam::modal::Notification::new( let notification =
renderer_cid, Notification::new(renderer_cid, Opcode::NotificationReturn.to_u32().unwrap());
Opcode::NotificationReturn.to_u32().unwrap(),
);
let mut text = String::new(); let mut text = String::new();
if let Some(c) = &config.caption { if let Some(c) = &config.caption {
text.push_str(c.as_str()); text.push_str(c.as_str());
text.push_str("\n\n"); text.push_str("\n\n");
} }
#[cfg(any(feature = "hosted-baosec", feature = "cramium-soc"))]
let phrase = ux_api::widgets::bytes_to_bip39(
&config.bip39_data[..config.bip39_len as usize].to_vec(),
)
.unwrap_or(vec![t!("bip39.invalid_bytes", locales::LANG).to_string()]);
#[cfg(not(any(feature = "hosted-baosec", feature = "cramium-soc")))]
let phrase = renderer_modal let phrase = renderer_modal
.gam .gam
.bytes_to_bip39(&config.bip39_data[..config.bip39_len as usize].to_vec()) .bytes_to_bip39(&config.bip39_data[..config.bip39_len as usize].to_vec())
@ -539,11 +547,8 @@ fn wrapped_main() -> ! {
renderer_modal.activate(); renderer_modal.activate();
} }
RendererState::RunBip39Input(config) => { RendererState::RunBip39Input(config) => {
let b39input = gam::modal::Bip39Entry::new( let b39input =
false, Bip39Entry::new(false, renderer_cid, Opcode::Bip39Return.to_u32().unwrap());
renderer_cid,
Opcode::Bip39Return.to_u32().unwrap(),
);
let mut text = String::new(); let mut text = String::new();
if let Some(c) = &config.caption { if let Some(c) = &config.caption {
text.push_str(c.as_str()); text.push_str(c.as_str());
@ -606,10 +611,8 @@ fn wrapped_main() -> ! {
renderer_modal.activate(); renderer_modal.activate();
} }
RendererState::RunRadio(config) => { RendererState::RunRadio(config) => {
let mut radiobuttons = gam::modal::RadioButtons::new( let mut radiobuttons =
renderer_cid, RadioButtons::new(renderer_cid, Opcode::RadioReturn.to_u32().unwrap());
Opcode::RadioReturn.to_u32().unwrap(),
);
list_hash.clear(); list_hash.clear();
list_selected = 0u32; list_selected = 0u32;
for item in fixed_items.iter() { for item in fixed_items.iter() {
@ -633,10 +636,8 @@ fn wrapped_main() -> ! {
renderer_modal.activate(); renderer_modal.activate();
} }
RendererState::RunCheckBox(config) => { RendererState::RunCheckBox(config) => {
let mut checkbox = gam::modal::CheckBoxes::new( let mut checkbox =
renderer_cid, CheckBoxes::new(renderer_cid, Opcode::CheckBoxReturn.to_u32().unwrap());
Opcode::CheckBoxReturn.to_u32().unwrap(),
);
list_hash.clear(); list_hash.clear();
list_selected = 0u32; list_selected = 0u32;
for item in fixed_items.iter() { for item in fixed_items.iter() {
@ -678,7 +679,7 @@ fn wrapped_main() -> ! {
tts.tts_simple(text.as_str()).unwrap(); tts.tts_simple(text.as_str()).unwrap();
bot_text.push_str(text.as_str()); bot_text.push_str(text.as_str());
} }
let mut gutter = gam::modal::Notification::new( let mut gutter = Notification::new(
renderer_cid, renderer_cid,
Opcode::HandleDynamicNotificationKeyhit.to_u32().unwrap(), Opcode::HandleDynamicNotificationKeyhit.to_u32().unwrap(),
); );
@ -702,6 +703,7 @@ fn wrapped_main() -> ! {
} }
} }
Some(Opcode::FinishProgress) => msg_scalar_unpack!(msg, caller, _, _, _, { Some(Opcode::FinishProgress) => msg_scalar_unpack!(msg, caller, _, _, _, {
#[cfg(not(any(feature = "hosted-baosec", feature = "cramium-soc")))]
renderer_modal.gam.relinquish_focus().unwrap(); renderer_modal.gam.relinquish_focus().unwrap();
op = RendererState::None; op = RendererState::None;
// unblock the caller, which was forwarded on as the first argument // unblock the caller, which was forwarded on as the first argument
@ -736,6 +738,7 @@ fn wrapped_main() -> ! {
config.text.is_none(), config.text.is_none(),
None, None,
); );
#[cfg(not(any(feature = "hosted-baosec", feature = "cramium-soc")))]
log::debug!("UPDATE_DYN gid: {:?}", renderer_modal.canvas); log::debug!("UPDATE_DYN gid: {:?}", renderer_modal.canvas);
renderer_modal.redraw(); renderer_modal.redraw();
xous::yield_slice(); xous::yield_slice();
@ -752,6 +755,7 @@ fn wrapped_main() -> ! {
} }
}, },
Some(Opcode::DoCloseDynamicNotification) => { Some(Opcode::DoCloseDynamicNotification) => {
#[cfg(not(any(feature = "hosted-baosec", feature = "cramium-soc")))]
renderer_modal.gam.relinquish_focus().unwrap(); renderer_modal.gam.relinquish_focus().unwrap();
dynamic_notification_active = false; dynamic_notification_active = false;
op = RendererState::None; op = RendererState::None;