2021-01-17 13:58:02 +00:00
|
|
|
#![cfg_attr(target_os = "none", no_std)]
|
|
|
|
|
|
|
|
|
|
pub mod api;
|
|
|
|
|
use api::*;
|
|
|
|
|
|
2021-02-18 20:02:29 +00:00
|
|
|
use rkyv::Write;
|
|
|
|
|
use rkyv::Unarchive;
|
|
|
|
|
use graphics_server::api::{TextOp, TextView, TextViewResult};
|
2021-01-17 13:58:02 +00:00
|
|
|
|
2021-01-19 19:18:13 +00:00
|
|
|
use graphics_server::api::{Rectangle, Point, Gid, TextBounds};
|
|
|
|
|
use log::{error, info};
|
|
|
|
|
|
2021-01-19 10:58:57 +00:00
|
|
|
/// 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
|
|
|
|
|
pub fn post_textview(gam_cid: xous::CID, tv: &mut TextView) -> Result<(), xous::Error> {
|
2021-02-17 18:01:11 +00:00
|
|
|
// for testing only
|
|
|
|
|
tv.set_op(TextOp::Render);
|
|
|
|
|
tv.cursor.pt.x = 37;
|
|
|
|
|
tv.cursor.pt.y = 5;
|
|
|
|
|
|
|
|
|
|
info!("tv before lend: {:?}", tv);
|
2021-02-18 20:02:29 +00:00
|
|
|
let mut rkyv_tv = api::Opcode::RenderTextView(*tv);
|
2021-02-17 18:01:11 +00:00
|
|
|
let mut writer = rkyv::ArchiveBuffer::new(xous::XousBuffer::new(4096));
|
|
|
|
|
let pos = writer.archive(&rkyv_tv).expect("couldn't archive textview");
|
|
|
|
|
let mut xous_buffer = writer.into_inner();
|
|
|
|
|
|
|
|
|
|
xous_buffer.lend_mut(gam_cid, pos as u32).expect("RenderTextView operation failure");
|
|
|
|
|
|
|
|
|
|
let returned = unsafe { rkyv::archived_value::<api::Opcode>(xous_buffer.as_ref(), pos)};
|
2021-02-18 20:02:29 +00:00
|
|
|
if let rkyv::Archived::<api::Opcode>::TextViewResult(result) = returned {
|
|
|
|
|
let tvr: TextViewResult = result.unarchive();
|
|
|
|
|
tv.set_computed_bounds(tvr.bounds_computed);
|
|
|
|
|
tv.cursor = tvr.cursor;
|
|
|
|
|
} else {
|
|
|
|
|
panic!("post_textview got a return value from the server that isn't expected or handled");
|
2021-02-17 18:01:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tv.set_op(TextOp::Nop);
|
2021-01-17 13:58:02 +00:00
|
|
|
Ok(())
|
|
|
|
|
}
|