2020-08-29 17:17:56 +00:00
|
|
|
#![cfg_attr(target_os = "none", no_std)]
|
|
|
|
|
|
2020-11-22 16:40:40 +00:00
|
|
|
// pub mod size;
|
2020-08-29 17:17:56 +00:00
|
|
|
pub mod api;
|
2021-01-18 20:54:54 +00:00
|
|
|
pub use api::{Circle, DrawStyle, Line, PixelColor, Point, Rectangle, TextView, TextBounds, Gid, TextOp, TextAlignment};
|
2021-01-20 08:22:38 +00:00
|
|
|
use blitstr_ref as blitstr;
|
2021-01-03 10:31:51 +00:00
|
|
|
pub use blitstr::{ClipRect, Cursor, GlyphStyle};
|
2020-10-30 03:19:17 +00:00
|
|
|
use xous::String;
|
2021-01-18 20:54:54 +00:00
|
|
|
use xous::ipc::*;
|
2020-11-22 16:40:40 +00:00
|
|
|
pub mod op;
|
2020-08-29 17:17:56 +00:00
|
|
|
|
2020-10-14 03:18:31 +00:00
|
|
|
use xous::{send_message, CID};
|
2020-08-29 17:17:56 +00:00
|
|
|
|
2020-12-02 17:48:10 +00:00
|
|
|
pub fn draw_line(cid: CID, line: Line) -> Result<(), xous::Error> {
|
|
|
|
|
send_message(cid, api::Opcode::Line(line).into()).map(|_| ())
|
2020-08-29 17:17:56 +00:00
|
|
|
}
|
|
|
|
|
|
2020-12-02 17:48:10 +00:00
|
|
|
pub fn draw_circle(cid: CID, circ: Circle) -> Result<(), xous::Error> {
|
|
|
|
|
send_message(cid, api::Opcode::Circle(circ).into()).map(|_| ())
|
2020-08-29 17:17:56 +00:00
|
|
|
}
|
|
|
|
|
|
2020-12-02 17:48:10 +00:00
|
|
|
pub fn draw_rectangle(cid: CID, rect: Rectangle) -> Result<(), xous::Error> {
|
|
|
|
|
send_message(cid, api::Opcode::Rectangle(rect).into()).map(|_| ())
|
2020-08-29 17:17:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn flush(cid: CID) -> Result<(), xous::Error> {
|
2020-10-14 03:18:31 +00:00
|
|
|
send_message(cid, api::Opcode::Flush.into()).map(|_| ())
|
2020-08-29 17:17:56 +00:00
|
|
|
}
|
2020-10-30 02:22:03 +00:00
|
|
|
|
2021-01-18 20:54:54 +00:00
|
|
|
#[deprecated(
|
|
|
|
|
note = "Please use draw_textview for atomic text updates"
|
|
|
|
|
)]
|
2020-12-02 17:48:10 +00:00
|
|
|
pub fn set_string_clipping(cid: CID, r: ClipRect) -> Result<(), xous::Error> {
|
2020-11-26 19:33:44 +00:00
|
|
|
send_message(cid, api::Opcode::SetStringClipping(r).into()).map(|_| ())
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-18 20:54:54 +00:00
|
|
|
#[deprecated(
|
|
|
|
|
note = "Please use draw_textview for atomic text updates"
|
|
|
|
|
)]
|
2020-11-27 18:05:55 +00:00
|
|
|
pub fn set_cursor(cid: CID, c: Cursor) -> Result<(), xous::Error> {
|
|
|
|
|
send_message(cid, api::Opcode::SetCursor(c).into()).map(|_| ())
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-18 20:54:54 +00:00
|
|
|
#[deprecated(
|
|
|
|
|
note = "Please use draw_textview for atomic text updates"
|
|
|
|
|
)]
|
2020-12-02 17:48:10 +00:00
|
|
|
pub fn get_cursor(cid: CID) -> Result<Cursor, xous::Error> {
|
2020-11-27 18:05:55 +00:00
|
|
|
let response = send_message(cid, api::Opcode::GetCursor.into())?;
|
|
|
|
|
if let xous::Result::Scalar2(pt_as_usize, h) = response {
|
|
|
|
|
let p: Point = pt_as_usize.into();
|
2020-12-02 17:48:10 +00:00
|
|
|
Ok(Cursor::new(p.x as usize, p.y as usize, h as _))
|
2020-11-27 18:05:55 +00:00
|
|
|
} else {
|
|
|
|
|
panic!("unexpected return value: {:#?}", response);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-18 20:54:54 +00:00
|
|
|
#[deprecated(
|
|
|
|
|
note = "Please use draw_textview for atomic text updates"
|
|
|
|
|
)]
|
2020-10-30 03:19:17 +00:00
|
|
|
pub fn draw_string(cid: CID, s: &String) -> Result<(), xous::Error> {
|
|
|
|
|
s.lend(cid, 1).map(|_| ())
|
2020-10-30 02:22:03 +00:00
|
|
|
}
|
2020-11-23 06:55:56 +00:00
|
|
|
|
2021-01-18 20:54:54 +00:00
|
|
|
#[deprecated(
|
|
|
|
|
note = "Please use draw_textview for atomic text updates"
|
|
|
|
|
)]
|
2020-12-02 17:48:10 +00:00
|
|
|
pub fn set_glyph_style(cid: CID, glyph: GlyphStyle) -> Result<(), xous::Error> {
|
2021-01-03 10:31:51 +00:00
|
|
|
send_message(cid, api::Opcode::SetGlyphStyle(glyph).into()).map(|_| ())
|
2020-11-23 07:42:58 +00:00
|
|
|
}
|
|
|
|
|
|
2020-11-23 06:55:56 +00:00
|
|
|
pub fn screen_size(cid: CID) -> Result<Point, xous::Error> {
|
|
|
|
|
let response = send_message(cid, api::Opcode::ScreenSize.into())?;
|
|
|
|
|
if let xous::Result::Scalar2(x, y) = response {
|
|
|
|
|
Ok(Point::new(x as _, y as _))
|
|
|
|
|
} else {
|
|
|
|
|
panic!("unexpected return value: {:#?}", response);
|
|
|
|
|
}
|
2020-11-23 07:42:58 +00:00
|
|
|
}
|
|
|
|
|
|
2021-01-18 20:54:54 +00:00
|
|
|
#[deprecated(
|
|
|
|
|
note = "Please use draw_textview for atomic text updates"
|
|
|
|
|
)]
|
2020-12-02 17:48:10 +00:00
|
|
|
pub fn query_glyph(cid: CID) -> Result<(GlyphStyle, usize), xous::Error> {
|
|
|
|
|
let response = send_message(cid, api::Opcode::QueryGlyphStyle.into())?;
|
2020-11-23 07:42:58 +00:00
|
|
|
if let xous::Result::Scalar2(glyph, h) = response {
|
2020-12-02 17:48:10 +00:00
|
|
|
Ok((GlyphStyle::from(glyph), h))
|
2020-11-23 07:42:58 +00:00
|
|
|
} else {
|
|
|
|
|
panic!("unexpected return value: {:#?}", response);
|
|
|
|
|
}
|
2021-01-03 10:31:51 +00:00
|
|
|
}
|
2021-01-17 20:12:40 +00:00
|
|
|
|
|
|
|
|
pub fn glyph_height_hint(cid: CID, glyph: GlyphStyle) -> Result<usize, xous::Error> {
|
|
|
|
|
let response = send_message(cid, api::Opcode::QueryGlyphProps(glyph).into())?;
|
|
|
|
|
if let xous::Result::Scalar2(_, h) = response {
|
|
|
|
|
Ok(h)
|
|
|
|
|
} else {
|
|
|
|
|
panic!("unexpected return value: {:#?}", response);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-18 20:54:54 +00:00
|
|
|
|
2021-01-19 10:58:57 +00:00
|
|
|
pub fn draw_textview(cid: CID, tv: &mut TextView) -> Result<(), xous::Error> {
|
2021-01-18 20:54:54 +00:00
|
|
|
let mut sendable_tv = Sendable::new(tv)
|
|
|
|
|
.expect("can't create sendable TextView structure");
|
2021-01-19 10:58:57 +00:00
|
|
|
sendable_tv.lend_mut(cid, 0x100).map(|_| ())
|
2021-01-18 20:54:54 +00:00
|
|
|
}
|