clean up ux-api to be no-std clean

ux-api can't do rkyv derives and rely on std items in a
no-std environment. This is necessary because some of the
base layer APIs (frame buffers, points, etc.) are relied
upon in a no-std loader environment to render diagnostics
to the screen. Thus ux-api needs to have a baseline of
primitives available without a std flag.
This commit is contained in:
bunnie 2025-02-20 13:32:52 +08:00
parent 1dcf7b191b
commit 2235f7a3f1
11 changed files with 56 additions and 29 deletions

View file

@ -5,7 +5,7 @@ edition = "2021"
[dependencies] [dependencies]
xous = "0.9.64" xous = "0.9.64"
xous-ipc = "0.10.4" xous-ipc = { version = "0.10.4", optional = true }
log = "0.4.14" log = "0.4.14"
num-derive = { version = "0.4.2", default-features = false } num-derive = { version = "0.4.2", default-features = false }
num-traits = { version = "0.2.14", default-features = false } num-traits = { version = "0.2.14", default-features = false }
@ -18,13 +18,15 @@ enum_dispatch = "0.3.7"
blitstr2 = { path = "../blitstr2", optional = true } blitstr2 = { path = "../blitstr2", optional = true }
# used in notifications # used in notifications
locales = { path = "../../locales" } locales = { path = "../../locales", optional = true }
qrcode = { version = "0.12", default-features = false } qrcode = { version = "0.12", default-features = false, optional = true }
# used in bip39 dialogue # used in bip39 dialogue
hex = { version = "0.4.3", default-features = false, features = ["alloc"] } hex = { version = "0.4.3", default-features = false, features = [
sha2 = { version = "0.10.8" } "alloc",
digest = "0.9.0" ], optional = true }
sha2 = { version = "0.10.8", optional = true }
digest = { version = "0.9.0", optional = true }
[features] [features]
# various feature gates - recommended to be selective about these because # various feature gates - recommended to be selective about these because
@ -50,7 +52,9 @@ default-widgets = [
# board definition is used to define things like the size of the screen. # board definition is used to define things like the size of the screen.
board-baosec = ["blitstr2/board-baosec"] board-baosec = ["blitstr2/board-baosec"]
loader-baosec = []
board-baosor = [] board-baosor = []
loader-baosor = []
hosted-baosec = ["blitstr2/hosted-baosec"] hosted-baosec = ["blitstr2/hosted-baosec"]
# Used by font codegen routine # Used by font codegen routine
@ -58,6 +62,7 @@ hosted = ["blitstr2/hosted"]
renode = ["blitstr2/renode"] renode = ["blitstr2/renode"]
cramium-soc = [] cramium-soc = []
precursor = ["blitstr2/precursor"] precursor = ["blitstr2/precursor"]
derive-rkyv = ["rkyv"]
std = ["rkyv"] std = ["derive-rkyv", "locales", "qrcode", "xous-ipc", "hex", "sha2", "digest"]
default = ["std", "default-widgets"] default = ["std", "default-widgets"]

View file

@ -1,11 +1,13 @@
#![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), no_std)]
pub mod minigfx; #[cfg(feature = "std")]
pub mod widgets;
mod wordwrap;
pub mod cursor; pub mod cursor;
mod fontmap; mod fontmap;
pub mod minigfx;
pub mod platform; pub mod platform;
#[cfg(feature = "std")]
pub mod widgets;
#[cfg(feature = "std")]
mod wordwrap;
#[cfg(feature = "std")]
pub const SYSTEM_STYLE: blitstr2::GlyphStyle = blitstr2::GlyphStyle::Tall; pub const SYSTEM_STYLE: blitstr2::GlyphStyle = blitstr2::GlyphStyle::Tall;

View file

@ -1,6 +1,7 @@
use crate::minigfx::*; use crate::minigfx::*;
#[derive(Debug, Clone, Copy, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] #[cfg_attr(feature = "derive-rkyv", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))]
#[derive(Debug, Clone, Copy)]
pub struct Circle { pub struct Circle {
pub center: Point, pub center: Point,
pub radius: isize, pub radius: isize,

View file

@ -10,7 +10,8 @@ use crate::minigfx::Point;
/// Cursor specifies a drawing position along a line of text. Lines of text can /// Cursor specifies a drawing position along a line of text. Lines of text can
/// be different heights. Line_height is for keeping track of the tallest /// be different heights. Line_height is for keeping track of the tallest
/// character that has been drawn so far on the current line. /// character that has been drawn so far on the current line.
#[derive(Copy, Clone, Debug, PartialEq, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] #[cfg_attr(feature = "derive-rkyv", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct Cursor { pub struct Cursor {
pub pt: Point, pub pt: Point,
pub line_height: usize, pub line_height: usize,

View file

@ -8,12 +8,19 @@ pub mod style;
pub use style::*; pub use style::*;
pub mod circle; pub mod circle;
pub use circle::*; pub use circle::*;
#[cfg(feature = "std")]
pub mod textview; pub mod textview;
#[cfg(feature = "std")]
pub use textview::*; pub use textview::*;
#[cfg(feature = "std")]
pub mod cursor; pub mod cursor;
#[cfg(feature = "std")]
pub use cursor::*; pub use cursor::*;
#[cfg(feature = "std")]
pub(crate) mod op; pub(crate) mod op;
#[cfg(feature = "std")]
use blitstr2::GlyphSprite; use blitstr2::GlyphSprite;
/// Abstract trait for a FrameBuffer. Slower than native manipulation /// Abstract trait for a FrameBuffer. Slower than native manipulation
@ -35,6 +42,7 @@ pub trait FrameBuffer {
/// defined by its `bb` record. The intention is that this abstract representation can be passed directly to /// defined by its `bb` record. The intention is that this abstract representation can be passed directly to
/// a rasterizer for rendering. /// a rasterizer for rendering.
#[derive(Debug)] #[derive(Debug)]
#[cfg(feature = "std")]
pub(crate) struct TypesetWord { pub(crate) struct TypesetWord {
/// glyph data to directly render the word /// glyph data to directly render the word
pub gs: Vec<GlyphSprite>, pub gs: Vec<GlyphSprite>,

View file

@ -1,6 +1,7 @@
use core::ops::{Add, AddAssign, Div, DivAssign, Index, Mul, MulAssign, Neg, Sub, SubAssign}; use core::ops::{Add, AddAssign, Div, DivAssign, Index, Mul, MulAssign, Neg, Sub, SubAssign};
#[derive(Copy, Clone, PartialEq, Eq, Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] #[cfg_attr(feature = "derive-rkyv", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))]
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct Point { pub struct Point {
pub x: isize, pub x: isize,
pub y: isize, pub y: isize,

View file

@ -2,7 +2,8 @@ use core::cmp::{max, min};
use crate::minigfx::*; use crate::minigfx::*;
#[derive(Debug, Clone, Copy, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] #[cfg_attr(feature = "derive-rkyv", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))]
#[derive(Debug, Clone, Copy)]
pub struct Rectangle { pub struct Rectangle {
pub tl: Point, pub tl: Point,
pub br: Point, pub br: Point,
@ -193,7 +194,8 @@ impl Rectangle {
} }
//////////////////////// Rounded Rectangle //////////////////////// Rounded Rectangle
#[derive(Debug, Clone, Copy, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] #[cfg_attr(feature = "derive-rkyv", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))]
#[derive(Debug, Clone, Copy)]
pub struct RoundedRectangle { pub struct RoundedRectangle {
pub border: Rectangle, // drawstyle is inherited from the Rectangle pub border: Rectangle, // drawstyle is inherited from the Rectangle
pub radius: isize, pub radius: isize,

View file

@ -1,7 +1,8 @@
use crate::minigfx::Point; use crate::minigfx::Point;
/// Type wrapper for native colors /// Type wrapper for native colors
#[derive(Clone, Copy, PartialEq, Eq, Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] #[cfg_attr(feature = "derive-rkyv", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))]
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct ColorNative(pub usize); pub struct ColorNative(pub usize);
impl From<usize> for ColorNative { impl From<usize> for ColorNative {
fn from(value: usize) -> Self { Self { 0: value } } fn from(value: usize) -> Self { Self { 0: value } }
@ -11,7 +12,8 @@ impl Into<usize> for ColorNative {
} }
/// Style properties for an object /// Style properties for an object
#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] #[cfg_attr(feature = "derive-rkyv", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))]
#[derive(Debug, Copy, Clone)]
pub struct DrawStyle { pub struct DrawStyle {
/// Fill colour of the object /// Fill colour of the object
pub fill_color: Option<ColorNative>, pub fill_color: Option<ColorNative>,
@ -40,7 +42,8 @@ impl Default for DrawStyle {
} }
} }
#[derive(Debug, Copy, Clone, PartialEq, Eq, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] #[cfg_attr(feature = "derive-rkyv", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum PixelColor { pub enum PixelColor {
Dark, Dark,
Light, Light,

View file

@ -1,12 +1,12 @@
use core::ops::Add; use core::ops::Add;
use String;
use blitstr2::GlyphStyle; use blitstr2::GlyphStyle;
use super::*; use super::*;
/// coordinates are local to the canvas, not absolute to the screen /// coordinates are local to the canvas, not absolute to the screen
#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] #[cfg_attr(feature = "derive-rkyv", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))]
#[derive(Debug, Copy, Clone)]
pub enum TextBounds { pub enum TextBounds {
// fixed width and height in a rectangle // fixed width and height in a rectangle
BoundingBox(Rectangle), BoundingBox(Rectangle),
@ -46,7 +46,8 @@ impl TextBounds {
} }
} }
#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, PartialEq)] #[cfg_attr(feature = "derive-rkyv", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))]
#[derive(Debug, Copy, Clone)]
// operations that may be requested of a TextView when sent to GAM // operations that may be requested of a TextView when sent to GAM
pub enum TextOp { pub enum TextOp {
Nop, Nop,
@ -76,7 +77,8 @@ impl From<usize> for TextOp {
pub const TEXTVIEW_LEN: usize = 3072; pub const TEXTVIEW_LEN: usize = 3072;
pub const TEXTVIEW_DEFAULT_STYLE: GlyphStyle = GlyphStyle::Regular; pub const TEXTVIEW_DEFAULT_STYLE: GlyphStyle = GlyphStyle::Regular;
#[derive(Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] #[cfg_attr(feature = "derive-rkyv", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))]
#[derive(Clone)]
pub struct TextView { pub struct TextView {
// this is the operation as specified for the GAM. Note this is different from the "op" when sent to // this is the operation as specified for the GAM. Note this is different from the "op" when sent to
// graphics-server only the GAM should be sending TextViews to the graphics-server, and a different // graphics-server only the GAM should be sending TextViews to the graphics-server, and a different

View file

@ -1,9 +1,9 @@
#[cfg(any(feature = "board-baosec", feature = "hosted-baosec"))] #[cfg(any(feature = "board-baosec", feature = "hosted-baosec", feature = "loader-baosec"))]
mod baosec; mod baosec;
#[cfg(any(feature = "board-baosec", feature = "hosted-baosec"))] #[cfg(any(feature = "board-baosec", feature = "hosted-baosec", feature = "loader-baosec"))]
pub use baosec::*; pub use baosec::*;
#[cfg(feature = "board-baosor")] #[cfg(any(feature = "board-baosor", feature = "loader-baosor"))]
mod baosor; mod baosor;
#[cfg(feature = "board-baosor")] #[cfg(any(feature = "board-baosor", feature = "loader-baosor"))]
pub use baosor::*; pub use baosor::*;

View file

@ -227,7 +227,9 @@ fn layout(modal: &mut Modal, top_text: Option<&str>, bot_text: Option<&str>, sty
// compute height of action item // compute height of action item
log::trace!("step 1 total_height: {}", total_height); log::trace!("step 1 total_height: {}", total_height);
total_height += modal.action.height(modal.line_height, modal.margin, &modal); total_height +=
modal.action.height(modal.line_height.try_into().unwrap(), modal.margin.try_into().unwrap(), &modal)
as isize;
total_height += modal.margin; total_height += modal.margin;
// compute height of bot_text, if any // compute height of bot_text, if any