diff --git a/services/gam/src/lib.rs b/services/gam/src/lib.rs index 4c407522d..aa1fe9897 100644 --- a/services/gam/src/lib.rs +++ b/services/gam/src/lib.rs @@ -24,7 +24,7 @@ pub use graphics_server::api::{Point, Rectangle}; pub use graphics_server::api::{TextOp, TextView}; use ime_plugin_api::{ApiToken, ImefCallback}; use num_traits::*; -use xous::{send_message, Message, CID}; +use xous::{CID, Message, send_message}; use xous_ipc::Buffer; #[doc = include_str!("../README.md")] @@ -146,10 +146,16 @@ impl Gam { } } - /// this "posts" a textview -- it's not a "draw" as the update is neither guaranteed nor instantaneous + /// This "posts" a textview -- it's not a "draw" as the update is neither guaranteed nor instantaneous /// the GAM first has to check that the textview is allowed to be updated, and then it will decide when /// the actual screen update is allowed + /// + /// This will also truncate any text that is too long to fit into a single paged-sized transaction, as set + /// by `graphics_server::api::TEXTVIEW_LEN` pub fn post_textview(&self, tv: &mut TextView) -> Result<(), xous::Error> { + if tv.text.len() > graphics_server::api::TEXTVIEW_LEN { + tv.text.truncate(graphics_server::api::TEXTVIEW_LEN); + } tv.set_op(TextOp::Render); // force the clip_rect to none, in case a stale value from a previous bounds computation was hanging // out the bounds should /always/ come from the GAM canvas when doing a "live fire" redraw diff --git a/services/graphics-server/src/api/text.rs b/services/graphics-server/src/api/text.rs index b616b28bd..3dd8c0b44 100644 --- a/services/graphics-server/src/api/text.rs +++ b/services/graphics-server/src/api/text.rs @@ -72,7 +72,7 @@ impl From for TextOp { } // roughly 168 bytes to represent the rest of the struct, and we want to fill out the 4096 byte page with text -const TEXTVIEW_LEN: usize = 3072; +pub const TEXTVIEW_LEN: usize = 3072; pub const TEXTVIEW_DEFAULT_STYLE: GlyphStyle = GlyphStyle::Regular; #[derive(Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] diff --git a/services/graphics-server/src/lib.rs b/services/graphics-server/src/lib.rs index cab7d79ec..bb9fc6e68 100644 --- a/services/graphics-server/src/lib.rs +++ b/services/graphics-server/src/lib.rs @@ -13,10 +13,10 @@ pub mod op; pub mod fontmap; pub use api::ArchivedBulkRead; pub use api::BulkRead; -use api::Opcode; // if you prefer to map the api into your local namespace +use api::{Opcode, TEXTVIEW_LEN}; // if you prefer to map the api into your local namespace pub use fontmap::*; use num_traits::ToPrimitive; -use xous::{send_message, Message}; +use xous::{Message, send_message}; use xous_ipc::Buffer; #[derive(Debug)] pub struct Gfx { @@ -134,7 +134,12 @@ impl Gfx { } } + /// This function will truncate a TextView string if it is too long to transmit in + /// a single page of memory. pub fn draw_textview(&self, tv: &mut TextView) -> Result<(), xous::Error> { + if tv.text.len() > TEXTVIEW_LEN { + tv.text.truncate(TEXTVIEW_LEN); + } let mut buf = Buffer::into_buf(tv.clone()).or(Err(xous::Error::InternalError))?; buf.lend_mut(self.conn, Opcode::DrawTextView.to_u32().unwrap()) .or(Err(xous::Error::InternalError))?;