2021-01-16 20:02:08 +00:00
|
|
|
use xous::{Message, ScalarMessage};
|
2021-02-18 20:02:29 +00:00
|
|
|
use graphics_server::api::{Point, Rectangle, TextView, TextViewResult, Gid};
|
2021-01-20 08:22:38 +00:00
|
|
|
use blitstr_ref as blitstr;
|
2021-01-16 20:02:08 +00:00
|
|
|
use blitstr::{GlyphStyle, Cursor};
|
2021-01-17 09:02:40 +00:00
|
|
|
|
2021-02-25 19:37:48 +00:00
|
|
|
#[derive(Debug, rkyv::Archive, rkyv::Unarchive, Copy, Clone)]
|
|
|
|
|
// #[archive(derive(Copy, Clone))]
|
2021-01-19 19:18:13 +00:00
|
|
|
pub enum Opcode {
|
2021-01-16 20:02:08 +00:00
|
|
|
// clears a canvas with a given GID
|
2021-01-17 13:58:02 +00:00
|
|
|
ClearCanvas(Gid),
|
2021-01-16 20:02:08 +00:00
|
|
|
|
|
|
|
|
// renders a TextView
|
2021-01-19 19:18:13 +00:00
|
|
|
RenderTextView(TextView),
|
2021-01-16 20:02:08 +00:00
|
|
|
|
|
|
|
|
// returns a GID to the "content" Canvas; requires an authentication token
|
2021-01-17 13:58:02 +00:00
|
|
|
RequestContentCanvas(Gid),
|
2021-01-16 20:02:08 +00:00
|
|
|
|
|
|
|
|
// hides a canvas with a given GID
|
2021-01-17 13:58:02 +00:00
|
|
|
HideCanvas(Gid),
|
2021-01-16 20:02:08 +00:00
|
|
|
|
|
|
|
|
// requests the GID to the "input" Canvas; call only works once (for the IME server), then maps out
|
2021-02-18 20:02:29 +00:00
|
|
|
RequestInputCanvas,
|
2021-01-16 20:02:08 +00:00
|
|
|
|
|
|
|
|
// indicates if the current UI layout requires an input field
|
|
|
|
|
HasInput(bool),
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-19 19:18:13 +00:00
|
|
|
impl core::convert::TryFrom<&Message> for Opcode {
|
2021-01-16 20:02:08 +00:00
|
|
|
type Error = &'static str;
|
2021-01-19 19:18:13 +00:00
|
|
|
fn try_from(message: &Message) -> Result<Self, Self::Error> {
|
2021-01-16 20:02:08 +00:00
|
|
|
match message {
|
|
|
|
|
Message::Scalar(m) => match m.id {
|
2021-01-17 13:58:02 +00:00
|
|
|
0 => Ok(Opcode::ClearCanvas(Gid::new([m.arg1 as _, m.arg2 as _, m.arg3 as _, m.arg4 as _]))),
|
2021-01-16 20:02:08 +00:00
|
|
|
_ => Err("GAM api: unknown Scalar ID"),
|
|
|
|
|
},
|
|
|
|
|
_ => Err("GAM api: unhandled message type"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-19 19:18:13 +00:00
|
|
|
impl Into<Message> for Opcode {
|
2021-01-16 20:02:08 +00:00
|
|
|
fn into(self) -> Message {
|
|
|
|
|
match self {
|
|
|
|
|
Opcode::ClearCanvas(gid) => Message::Scalar(ScalarMessage {
|
2021-01-18 20:54:54 +00:00
|
|
|
id: 0, arg1: gid.gid()[0] as _, arg2: gid.gid()[1] as _, arg3: gid.gid()[2] as _, arg4: gid.gid()[3] as _
|
2021-01-16 20:02:08 +00:00
|
|
|
}),
|
|
|
|
|
_ => panic!("GAM api: Opcode type not handled by Into(), maybe you meant to use a helper method?"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|