diff --git a/docs/images/graphics-server/boot_logo.png b/docs/images/graphics-server/boot_logo.png new file mode 100644 index 000000000..ed2afc5eb Binary files /dev/null and b/docs/images/graphics-server/boot_logo.png differ diff --git a/docs/images/graphics-server/circle.png b/docs/images/graphics-server/circle.png new file mode 100644 index 000000000..4cc422d1c Binary files /dev/null and b/docs/images/graphics-server/circle.png differ diff --git a/docs/images/graphics-server/circle_clipped.png b/docs/images/graphics-server/circle_clipped.png new file mode 100644 index 000000000..b7ad2a98e Binary files /dev/null and b/docs/images/graphics-server/circle_clipped.png differ diff --git a/docs/images/graphics-server/line.png b/docs/images/graphics-server/line.png new file mode 100644 index 000000000..8cfaa47e2 Binary files /dev/null and b/docs/images/graphics-server/line.png differ diff --git a/docs/images/graphics-server/line_clipped.png b/docs/images/graphics-server/line_clipped.png new file mode 100644 index 000000000..d60b28bad Binary files /dev/null and b/docs/images/graphics-server/line_clipped.png differ diff --git a/docs/images/graphics-server/line_clipped_xor.png b/docs/images/graphics-server/line_clipped_xor.png new file mode 100644 index 000000000..dd3e80ed5 Binary files /dev/null and b/docs/images/graphics-server/line_clipped_xor.png differ diff --git a/docs/images/graphics-server/object_list_clipped.png b/docs/images/graphics-server/object_list_clipped.png new file mode 100644 index 000000000..f93ffb4d1 Binary files /dev/null and b/docs/images/graphics-server/object_list_clipped.png differ diff --git a/docs/images/graphics-server/rectangle.png b/docs/images/graphics-server/rectangle.png new file mode 100644 index 000000000..2ca6ded60 Binary files /dev/null and b/docs/images/graphics-server/rectangle.png differ diff --git a/docs/images/graphics-server/rectangle_clipped.png b/docs/images/graphics-server/rectangle_clipped.png new file mode 100644 index 000000000..6d364f452 Binary files /dev/null and b/docs/images/graphics-server/rectangle_clipped.png differ diff --git a/docs/images/graphics-server/rounded_rectangle.png b/docs/images/graphics-server/rounded_rectangle.png new file mode 100644 index 000000000..5a4d3beb4 Binary files /dev/null and b/docs/images/graphics-server/rounded_rectangle.png differ diff --git a/docs/images/graphics-server/rounded_rectangle_clipped.png b/docs/images/graphics-server/rounded_rectangle_clipped.png new file mode 100644 index 000000000..ce1afa5d6 Binary files /dev/null and b/docs/images/graphics-server/rounded_rectangle_clipped.png differ diff --git a/docs/images/graphics-server/selftest.png b/docs/images/graphics-server/selftest.png new file mode 100644 index 000000000..bf0308bc7 Binary files /dev/null and b/docs/images/graphics-server/selftest.png differ diff --git a/docs/images/graphics-server/sleepscreen.png b/docs/images/graphics-server/sleepscreen.png new file mode 100644 index 000000000..da590ee3b Binary files /dev/null and b/docs/images/graphics-server/sleepscreen.png differ diff --git a/docs/images/graphics-server/textview.png b/docs/images/graphics-server/textview.png new file mode 100644 index 000000000..c1a592a66 Binary files /dev/null and b/docs/images/graphics-server/textview.png differ diff --git a/docs/images/modals_dynamic_notification.png b/docs/images/modals/dynamic_notification.png similarity index 100% rename from docs/images/modals_dynamic_notification.png rename to docs/images/modals/dynamic_notification.png diff --git a/docs/images/modals_get_checkbox.png b/docs/images/modals/get_checkbox.png similarity index 100% rename from docs/images/modals_get_checkbox.png rename to docs/images/modals/get_checkbox.png diff --git a/docs/images/modals_get_radiobutton.png b/docs/images/modals/get_radiobutton.png similarity index 100% rename from docs/images/modals_get_radiobutton.png rename to docs/images/modals/get_radiobutton.png diff --git a/docs/images/modals_input_bip39_1.png b/docs/images/modals/input_bip39_1.png similarity index 100% rename from docs/images/modals_input_bip39_1.png rename to docs/images/modals/input_bip39_1.png diff --git a/docs/images/modals_input_bip39_2.png b/docs/images/modals/input_bip39_2.png similarity index 100% rename from docs/images/modals_input_bip39_2.png rename to docs/images/modals/input_bip39_2.png diff --git a/docs/images/modals_input_bip39_3.png b/docs/images/modals/input_bip39_3.png similarity index 100% rename from docs/images/modals_input_bip39_3.png rename to docs/images/modals/input_bip39_3.png diff --git a/docs/images/modals_show_bip39.png b/docs/images/modals/show_bip39.png similarity index 100% rename from docs/images/modals_show_bip39.png rename to docs/images/modals/show_bip39.png diff --git a/docs/images/modals_show_notification.png b/docs/images/modals/show_notification.png similarity index 100% rename from docs/images/modals_show_notification.png rename to docs/images/modals/show_notification.png diff --git a/docs/images/modals_slider.png b/docs/images/modals/slider.png similarity index 100% rename from docs/images/modals_slider.png rename to docs/images/modals/slider.png diff --git a/docs/images/modals_start_progress.png b/docs/images/modals/start_progress.png similarity index 100% rename from docs/images/modals_start_progress.png rename to docs/images/modals/start_progress.png diff --git a/services/graphics-server/src/lib.rs b/services/graphics-server/src/lib.rs index bb9fc6e68..ec7aee79e 100644 --- a/services/graphics-server/src/lib.rs +++ b/services/graphics-server/src/lib.rs @@ -31,6 +31,23 @@ impl Gfx { pub fn conn(&self) -> xous::CID { self.conn } + /// Draws a line. + /// + ///
+ /// Example Image + /// + /// ![Example Image](https://github.com/betrusted-io/xous-core/blob/main/docs/images/graphics-server/line.png?raw=true) + /// + ///
+ /// + /// # Example + /// ``` + /// use graphics_server::{Gfx, Line, Point}; + /// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap(); + /// let line = Line::new(Point::new(100, 100), Point::new(200, 200)); // if you want to specify a style, use Line::new_with_style + /// gfx.draw_line(line).unwrap(); + /// gfx.flush().unwrap(); + /// ``` pub fn draw_line(&self, line: Line) -> Result<(), xous::Error> { send_message( self.conn, @@ -45,6 +62,23 @@ impl Gfx { .map(|_| ()) } + /// Draws a circle. + /// + ///
+ /// Example Image + /// + /// ![Example Image](https://github.com/betrusted-io/xous-core/blob/main/docs/images/graphics-server/circle.png?raw=true) + /// + ///
+ /// + /// # Example + /// ``` + /// use graphics_server::{Circle, Gfx, Point}; + /// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap(); + /// let circle = Circle::new(Point::new(150, 150), 25); // if you want to specify a style, use Circle::new_with_style + /// gfx.draw_circle(circle).unwrap(); + /// gfx.flush().unwrap(); + /// ``` pub fn draw_circle(&self, circ: Circle) -> Result<(), xous::Error> { send_message( self.conn, @@ -59,6 +93,23 @@ impl Gfx { .map(|_| ()) } + /// Draws a rectangle. + /// + ///
+ /// Example Image + /// + /// ![Example Image](https://github.com/betrusted-io/xous-core/blob/main/docs/images/graphics-server/rectangle.png?raw=true) + /// + ///
+ /// + /// # Example + /// ``` + /// use graphics_server::{Gfx, Point, Rectangle}; + /// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap(); + /// let rect = Rectangle::new(Point::new(100, 100), Point::new(250, 150)); // if you want to specify a style, use Rectangle::new_with_style + /// gfx.draw_rectangle(rect).unwrap(); + /// gfx.flush().unwrap(); + /// ``` pub fn draw_rectangle(&self, rect: Rectangle) -> Result<(), xous::Error> { send_message( self.conn, @@ -73,6 +124,23 @@ impl Gfx { .map(|_| ()) } + /// Draws a rounded rectangle. + /// + ///
+ /// Example Image + /// + /// ![Example Image](https://github.com/betrusted-io/xous-core/blob/main/docs/images/graphics-server/rounded_rectangle.png?raw=true) + /// + ///
+ /// + /// # Example + /// ``` + /// use graphics_server::{Gfx, Point, Rectangle, RoundedRectangle}; + /// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap(); + /// let rr = RoundedRectangle::new(Rectangle::new(Point::new(100, 100), Point::new(150, 200)), 5); + /// gfx.draw_rounded_rectangle(rr).unwrap(); + /// gfx.flush().unwrap(); + /// ``` pub fn draw_rounded_rectangle(&self, rr: RoundedRectangle) -> Result<(), xous::Error> { send_message( self.conn, @@ -87,21 +155,82 @@ impl Gfx { .map(|_| ()) } + /// Flushes the graphics server, ensuring all previous drawing commands are executed. + /// + /// # Example + /// ``` + /// use graphics_server::{Circle, Gfx, Line, Point}; + /// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap(); + /// let line = Line::new(Point::new(0, 0), Point::new(100, 100)); + /// let circle = Circle::new(Point::new(150, 150), 25); + /// gfx.draw_line(line).unwrap(); + /// gfx.draw_circle(circle).unwrap(); + /// gfx.flush().unwrap(); // Both the line and the circle will be drawn + /// ``` pub fn flush(&self) -> Result<(), xous::Error> { send_message(self.conn, Message::new_scalar(Opcode::Flush.to_usize().unwrap(), 0, 0, 0, 0)) .map(|_| ()) } + /// Draws the sleep screen. + /// + /// This function sends a message to the graphics server to draw the sleep screen. + /// + ///
+ /// Example Image + /// + /// ![Example Image](https://github.com/betrusted-io/xous-core/blob/main/docs/images/graphics-server/sleepscreen.png?raw=true) + /// + ///
+ /// + /// # Example + /// ``` + /// use graphics_server::Gfx; + /// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap(); + /// gfx.draw_sleepscreen().unwrap(); + /// gfx.flush().unwrap(); + /// ``` pub fn draw_sleepscreen(&self) -> Result<(), xous::Error> { send_message(self.conn, Message::new_scalar(Opcode::DrawSleepScreen.to_usize().unwrap(), 0, 0, 0, 0)) .map(|_| ()) } + /// Draws the boot logo. + /// + /// This function sends a message to the graphics server to draw the boot logo. + /// The boot logo is typically displayed during the device's startup sequence. + /// + ///
+ /// Example Image + /// + /// ![Example Image](https://github.com/betrusted-io/xous-core/blob/main/docs/images/graphics-server/boot_logo.png?raw=true) + /// + ///
+ /// + /// # Example + /// ``` + /// use graphics_server::Gfx; + /// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap(); + /// gfx.draw_boot_logo().unwrap(); + /// gfx.flush().unwrap(); + /// ``` pub fn draw_boot_logo(&self) -> Result<(), xous::Error> { send_message(self.conn, Message::new_scalar(Opcode::DrawBootLogo.to_usize().unwrap(), 0, 0, 0, 0)) .map(|_| ()) } + /// Retrieves the screen size from the graphics server. + /// + /// This function sends a message to the graphics server to query the screen size. + /// The screen size is returned as a `Point` representing the width and height. + /// + /// # Example + /// ``` + /// use graphics_server::Gfx; + /// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap(); + /// let screen_dimensions = gfx.screen_size().expect("Couldn't get screen size"); + /// println!("Screen size: {}x{}", screen_dimensions.x, screen_dimensions.y); + /// ``` pub fn screen_size(&self) -> Result { let response = send_message( self.conn, @@ -115,6 +244,18 @@ impl Gfx { } } + /// Retrieves the height hint for a specific glyph from the graphics server. + /// + /// This function sends a message to the graphics server to query the height hint of a glyph. + /// The height hint is returned as a `usize`. + /// + /// # Example + /// ``` + /// use graphics_server::{Gfx, GlyphStyle}; + /// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap(); + /// let height_hint = gfx.glyph_height_hint(GlyphStyle::Regular).unwrap(); + /// println!("Glyph height hint: {}", height_hint); + /// ``` pub fn glyph_height_hint(&self, glyph: GlyphStyle) -> Result { let response = send_message( self.conn, @@ -134,8 +275,31 @@ impl Gfx { } } - /// This function will truncate a TextView string if it is too long to transmit in - /// a single page of memory. + /// Draws a `TextView`. + /// + /// This function sends a message to the graphics server to draw the specified `TextView`. + /// If the text in the `TextView` is too long to transmit in a single page of memory, it will be + /// truncated. + /// Text that overflows the bounds of the `TextView` will be clipped. + /// + ///
+ /// Example Image + /// + /// ![Example Image](https://github.com/betrusted-io/xous-core/blob/main/docs/images/graphics-server/textview.png?raw=true) + /// + ///
+ /// + /// # Example + /// ``` + /// use graphics_server::{Gfx, TextView}; + /// let clipping_area = Rectangle::new_coords(50, 50, 290, 450); + /// let text_bounds = Rectangle::new_coords(10, 10, 240, 400); + /// let mut tv = TextView::new(Gid::new([0, 0, 0, 0]), TextBounds::BoundingBox(text_bounds)); + /// tv.clip_rect = Some(clipping_area); + /// write!(tv, "Hello, world!").unwrap(); + /// gfx.draw_textview(&mut tv).unwrap(); + /// gfx.flush().unwrap(); + /// ```` pub fn draw_textview(&self, tv: &mut TextView) -> Result<(), xous::Error> { if tv.text.len() > TEXTVIEW_LEN { tv.text.truncate(TEXTVIEW_LEN); @@ -152,31 +316,137 @@ impl Gfx { Ok(()) } + /// Draws a line with clipping. + /// + /// This function sends a message to the graphics server to draw the specified `Line` within the specified + /// `Rectangle` clip area. + /// + ///
+ /// Example Image - clipped line with clipping area represented by light rectangle. + /// + /// ![Example Image](https://github.com/betrusted-io/xous-core/blob/main/docs/images/graphics-server/line_clipped.png?raw=true) + /// + ///
+ /// + /// # Example + /// ``` + /// use graphics_server::{Gfx, Line, Point, Rectangle}; + /// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap(); + /// let line = Line::new(Point::new(100, 100), Point::new(200, 200)); + /// let clip = Rectangle::new(Point::new(110, 110), Point::new(190, 190)); + /// gfx.draw_line_clipped(line, clip).unwrap(); + /// gfx.flush().unwrap(); + /// ``` pub fn draw_line_clipped(&self, line: Line, clip: Rectangle) -> Result<(), xous::Error> { let co = ClipObject { clip, obj: ClipObjectType::Line(line) }; let buf = Buffer::into_buf(co).or(Err(xous::Error::InternalError))?; buf.lend(self.conn, Opcode::DrawClipObject.to_u32().unwrap()).map(|_| ()) } - // for use in the deface operation + /// Draws a line with XOR clipping. + /// For use in the deface operation. + /// + /// This function sends a message to the graphics server to draw the specified `Line` within the specified + /// `Rectangle` clip area using XOR mode. + /// + ///
+ /// Example Image - line clipped by area represented by dark rectangle. Light inner + /// rectangle added to show XOR behavior. + /// + /// ![Example Image](https://github.com/betrusted-io/xous-core/blob/main/docs/images/graphics-server/line_clipped_xor.png?raw=true) /// + ///
+ /// + /// # Example + /// ``` + /// use graphics_server::{Gfx, Line, Point, Rectangle}; + /// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap(); + /// let line = Line::new(Point::new(0, 0), Point::new(100, 100)); + /// let clip = Rectangle::new(Point::new(10, 10), Point::new(90, 90)); + /// gfx.draw_line_clipped_xor(line, clip).unwrap(); + /// gfx.flush().unwrap(); + /// ``` pub fn draw_line_clipped_xor(&self, line: Line, clip: Rectangle) -> Result<(), xous::Error> { let co = ClipObject { clip, obj: ClipObjectType::XorLine(line) }; let buf = Buffer::into_buf(co).or(Err(xous::Error::InternalError))?; buf.lend(self.conn, Opcode::DrawClipObject.to_u32().unwrap()).map(|_| ()) } + /// Draws a circle with clipping. + /// + /// This function sends a message to the graphics server to draw the specified `Circle` within the + /// specified `Rectangle` clip area. + /// + ///
+ /// Example Image - circle clipped by area represented by light rectangle. + /// + /// ![Example Image](https://github.com/betrusted-io/xous-core/blob/main/docs/images/graphics-server/circle_clipped.png?raw=true) + /// + ///
+ /// + /// # Example + /// ``` + /// use graphics_server::{Circle, Gfx, Point, Rectangle}; + /// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap(); + /// let circ = Circle::new(Point::new(130, 130), 25); + /// let clip = Rectangle::new(Point::new(110, 110), Point::new(190, 190)); + /// gfx.draw_circle_clipped(circ, clip).unwrap(); + /// gfx.flush().unwrap(); + /// ``` pub fn draw_circle_clipped(&self, circ: Circle, clip: Rectangle) -> Result<(), xous::Error> { let co = ClipObject { clip, obj: ClipObjectType::Circ(circ) }; let buf = Buffer::into_buf(co).or(Err(xous::Error::InternalError))?; buf.lend(self.conn, Opcode::DrawClipObject.to_u32().unwrap()).map(|_| ()) } + /// Draws a rectangle with clipping. + /// + /// This function sends a message to the graphics server to draw the specified `Rectangle` + /// within the specified `ClipRect` clip area. + /// + ///
+ /// Example Image - rectangle clipped by area represented by light rectangle. + /// + /// ![Example Image](https://github.com/betrusted-io/xous-core/blob/main/docs/images/graphics-server/rectangle_clipped.png?raw=true) + /// + ///
+ /// + /// # Example + /// ``` + /// use graphics_server::{Gfx, Point, Rectangle}; + /// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap(); + /// let rect = Rectangle::new(Point::new(100, 100), Point::new(160, 160)); + /// let clip = Rectangle::new(Point::new(110, 110), Point::new(190, 190)); + /// gfx.draw_rectangle_clipped(rect, clip).unwrap(); + /// gfx.flush().unwrap(); + /// ``` pub fn draw_rectangle_clipped(&self, rect: Rectangle, clip: Rectangle) -> Result<(), xous::Error> { let co = ClipObject { clip, obj: ClipObjectType::Rect(rect) }; let buf = Buffer::into_buf(co).or(Err(xous::Error::InternalError))?; buf.lend(self.conn, Opcode::DrawClipObject.to_u32().unwrap()).map(|_| ()) } + /// Draws a rounded rectangle with clipping. + /// + /// This function sends a message to the graphics server to draw the specified `RoundedRectangle` + /// within the specified `ClipRect` clip area. + /// + ///
+ /// Example Image - rounded rectangle clipped by area represented by light + /// rectangle. + /// + /// ![Example Image](https://github.com/betrusted-io/xous-core/blob/main/docs/images/graphics-server/rounded_rectangle_clipped.png?raw=true) + /// + ///
+ /// + /// # Example + /// ``` + /// use graphics_server::{Gfx, Point, Rectangle, RoundedRectangle}; + /// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap(); + /// let rr = RoundedRectangle::new(Rectangle::new(Point::new(100, 100), Point::new(160, 160)), 8); + /// let clip = Rectangle::new(Point::new(0, 0), Point::new(100, 100)); + /// gfx.draw_rounded_rectangle_clipped(rr, clip).unwrap(); + /// gfx.flush().unwrap(); + /// ``` pub fn draw_rounded_rectangle_clipped( &self, rr: RoundedRectangle, @@ -195,25 +465,93 @@ impl Gfx { buf.lend(self.conn, Opcode::DrawClipObject.to_u32().unwrap()).map(|_| ()) } + /// Draws a list of objects with clipping. + /// + /// This function sends a message to the graphics server to draw the specified list of objects + /// within the specified `ClipRect` clip area. + /// + ///
+ /// Example Image - two objects, a line and a circle, each with their own clipping areas + /// represented by light rectangles. + /// + /// ![Example Image](https://github.com/betrusted-io/xous-core/blob/main/docs/images/graphics-server/object_list_clipped.png?raw=true) + /// + ///
+ /// + /// # Example + /// ``` + /// use graphics_server::{ClipObjectList, Gfx, Point, Rectangle}; + /// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap(); + /// let mut object_list = ClipObjectList::default(); + /// + /// // Create and add the first object (a line) + /// let line = Line::new(Point::new(0, 0), Point::new(100, 100)); + /// let clip = Rectangle::new(Point::new(10, 10), Point::new(90, 90)); + /// object_list.push(ClipObjectType::Line(line), clip); + /// + /// // Create and add the second object (a circle) + /// let circle = Circle::new(Point::new(150, 150), 25); + /// let clip2 = Rectangle::new(Point::new(140, 100), Point::new(190, 190)); + /// object_list.push(ClipObjectType::Circ(circle), clip2); + /// + /// gfx.draw_object_list_clipped(object_list).unwrap(); + /// gfx.flush().unwrap(); + /// ``` pub fn draw_object_list_clipped(&self, list: ClipObjectList) -> Result<(), xous::Error> { let buf = Buffer::into_buf(list).or(Err(xous::Error::InternalError))?; buf.lend(self.conn, Opcode::DrawClipObjectList.to_u32().unwrap()).map(|_| ()) } - /// this is a one-way door, once you've set it, you can't unset it. + /// Sets the developer boot mode. + /// + /// This function sends a message to the graphics server to enable or disable the developer boot mode. + /// The purpose of this call is to let users be aware of who signed their kernel. Kernels signed with the + /// developer signature can boot, but this API call ensures that a small dashed line appears through the + /// status bar, so there is an obvious indicator that the kernel has yet to be self-signed. Self-signed + /// kernels do not have this signature. + /// + /// NOTE: This call is a one-way operation. Once the developer boot mode is enabled, it cannot be + /// disabled. + /// + /// # Example + /// ``` + /// use graphics_server::Gfx; + /// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap(); + /// gfx.set_devboot(true); // Enable developer boot mode + /// ``` pub fn set_devboot(&self, enable: bool) -> Result<(), xous::Error> { let ena = if enable { 1 } else { 0 }; send_message(self.conn, Message::new_scalar(Opcode::Devboot.to_usize().unwrap(), ena, 0, 0, 0)) .map(|_| ()) } - /// instead of implementing the read in the library, we had the raw opcode to the caller - /// this allows the caller to re-use the bulk read data structure across multiple reads - /// instead of it being re-allocated and re-init'd every single call + /// Reads the font map in bulk from the graphics server. + /// + /// Instead of implementing the read in the library, we hand the raw opcode to the caller. + /// This allows the caller to re-use the bulk read data structure across multiple reads + /// instead of it being re-allocated and re-initialized every single call. This is used by the security + /// system to inspect the font maps for integrity. + /// + /// # Example + /// ``` + /// use graphics_server::{ArchivedBulkRead, Gfx}; + /// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap(); + /// let font_map = gfx.bulk_read_fontmap_op(); + /// // Process the font map as needed + /// ``` pub fn bulk_read_fontmap_op(&self) -> u32 { Opcode::BulkReadFonts.to_u32().unwrap() } - /// the bulk read auto-increments a pointer on the gfx server, so this message is necessary + /// Resets the bulk read pointer. + /// + /// The bulk read operation auto-increments a pointer on the graphics server, so this message is necessary /// to reset the pointer to 0. + /// + /// # Example + /// ``` + /// use graphics_server::Gfx; + /// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap(); + /// gfx.bulk_read_restart(); + /// ``` pub fn bulk_read_restart(&self) { send_message( self.conn, @@ -222,6 +560,24 @@ impl Gfx { .expect("couldn't reset bulk read"); } + /// Runs a self-test pattern. + /// + /// This function sends a message to the graphics server to display a test pattern for a specified + /// duration. The test pattern is typically used to verify the functionality of the graphics hardware. + /// + ///
+ /// Example Image - selftest in progress. + /// + /// ![Example Image](https://github.com/betrusted-io/xous-core/blob/main/docs/images/graphics-server/selftest.png?raw=true) + /// + ///
+ /// + /// # Example + /// ``` + /// use graphics_server::Gfx; + /// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap(); + /// gfx.selftest(1000); // Display the test pattern for 1000 milliseconds + /// ``` pub fn selftest(&self, duration_ms: usize) { send_message( self.conn, @@ -230,6 +586,25 @@ impl Gfx { .expect("couldn't self test"); } + /// Stashes the current graphics state. + /// + /// This function sends a message to the graphics server to stash (save) the current graphics state. + /// The stashed state can be restored later using the `pop` function. This is useful for temporarily + /// saving the current state before making changes, and then restoring it later. + /// + /// If `blocking` is `true`, the function will wait until the graphics server confirms that the state + /// has been stashed, otherwise it will return immediately without waiting for confirmation. + /// + /// NOTE: the top 34 lines will not be stashed, as this is the area where the status bar is drawn. + /// + /// # Example + /// ``` + /// use graphics_server::Gfx; + /// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap(); + /// let line = Line::new(Point::new(0, 0), Point::new(100, 100)); + /// gfx.draw_line(line).unwrap(); // Draw a line before stashing + /// gfx.stash(false); // Stash the current state in a non-blocking manner + /// ``` pub fn stash(&self, blocking: bool) { if blocking { send_message( @@ -243,6 +618,47 @@ impl Gfx { } } + /// Restores the previously stashed graphics state on the graphics server. + /// + /// This function sends a message to the graphics server to restore the previously stashed graphics state. + /// The stashed state can be restored using this function after it has been saved using the `stash` + /// function. This is useful for reverting to a previous state after making temporary changes. + /// + /// # Example + /// ``` + /// use graphics_server::{DrawStyle, Gfx, Line, PixelColor, Point, Rectangle}; + /// use ticktimer_server::Ticktimer; + /// let gfx = Gfx::new(&xous_names::XousNames::new().unwrap()).unwrap(); + /// let ticktimer = Ticktimer::new().expect("Couldn't connect to Ticktimer"); + /// + /// // Draw a line + /// let line = Line::new(Point::new(0, 0), Point::new(100, 100)); + /// gfx.draw_line(line).unwrap(); + /// gfx.flush().unwrap(); + /// + /// // Wait for a moment + /// ticktimer.sleep_ms(1000).unwrap(); + /// + /// // Stash the current state + /// gfx.stash(true); // Stash the current state in a blocking manner + /// + /// // Clear the screen + /// let screensize = gfx.screen_size().expect("Couldn't get screen size"); + /// let whiteout = Rectangle::new_with_style( + /// Point::new(0, 0), + /// screensize, + /// DrawStyle::new(PixelColor::Light, PixelColor::Light, 1), + /// ); + /// gfx.draw_rectangle(blackout).unwrap(); + /// gfx.flush().unwrap(); + /// + /// // Wait for a moment + /// ticktimer.sleep_ms(1000).unwrap(); + /// + /// // Restore the previously stashed state + /// gfx.pop(true); // Restore the previously stashed state in a blocking manner + /// gfx.flush().unwrap(); + /// ``` pub fn pop(&self, blocking: bool) { if blocking { send_message( diff --git a/services/modals/src/lib.rs b/services/modals/src/lib.rs index 12a6aec98..ca63cd53f 100644 --- a/services/modals/src/lib.rs +++ b/services/modals/src/lib.rs @@ -209,7 +209,7 @@ impl Modals { ///
/// Example Image /// - /// ![Example Image](https://github.com/betrusted-io/xous-core/blob/main/docs/images/modals_show_notification.png?raw=true) + /// ![Example Image](https://github.com/betrusted-io/xous-core/blob/main/docs/images/modals/show_notification.png?raw=true) /// ///
/// @@ -248,7 +248,7 @@ impl Modals { ///
/// Example Image /// - /// ![Example Image](https://github.com/betrusted-io/xous-core/blob/main/docs/images/modals_show_bip39.png?raw=true) + /// ![Example Image](https://github.com/betrusted-io/xous-core/blob/main/docs/images/modals/show_bip39.png?raw=true) /// ///
/// @@ -296,9 +296,9 @@ impl Modals { ///
/// Example Images (from example code below) /// - /// ![Example Image - Initial](https://github.com/betrusted-io/xous-core/blob/main/docs/images/modals_input_bip39_1.png?raw=true) - /// ![Example Image - Input](https://github.com/betrusted-io/xous-core/blob/main/docs/images/modals_input_bip39_2.png?raw=true) - /// ![Example Image - Confirmation](https://github.com/betrusted-io/xous-core/blob/main/docs/images/modals_input_bip39_3.png?raw=true) + /// ![Example Image - Initial](https://github.com/betrusted-io/xous-core/blob/main/docs/images/modals/input_bip39_1.png?raw=true) + /// ![Example Image - Input](https://github.com/betrusted-io/xous-core/blob/main/docs/images/modals/input_bip39_2.png?raw=true) + /// ![Example Image - Confirmation](https://github.com/betrusted-io/xous-core/blob/main/docs/images/modals/input_bip39_3.png?raw=true) /// ///
/// @@ -385,7 +385,7 @@ impl Modals { ///
/// Example Image /// - /// ![Example Image](https://github.com/betrusted-io/xous-core/blob/main/docs/images/modals_start_progress.png?raw=true) + /// ![Example Image](https://github.com/betrusted-io/xous-core/blob/main/docs/images/modals/start_progress.png?raw=true) /// ///
/// @@ -424,7 +424,7 @@ impl Modals { ///
/// Example Image /// - /// ![Example Image](https://github.com/betrusted-io/xous-core/blob/main/docs/images/modals_slider.png?raw=true) + /// ![Example Image](https://github.com/betrusted-io/xous-core/blob/main/docs/images/modals/slider.png?raw=true) /// ///
/// @@ -616,7 +616,7 @@ impl Modals { ///
/// Example Image /// - /// ![Example Image](https://github.com/betrusted-io/xous-core/blob/main/docs/images/modals_get_radiobutton.png?raw=true) + /// ![Example Image](https://github.com/betrusted-io/xous-core/blob/main/docs/images/modals/get_radiobutton.png?raw=true) /// ///
/// @@ -691,7 +691,7 @@ impl Modals { ///
/// Example Image /// - /// ![Example Image](https://github.com/betrusted-io/xous-core/blob/main/docs/images/modals_get_checkbox.png?raw=true) + /// ![Example Image](https://github.com/betrusted-io/xous-core/blob/main/docs/images/modals/get_checkbox.png?raw=true) /// ///
/// @@ -794,7 +794,7 @@ impl Modals { ///
/// Example Image /// - /// ![Example Image](https://github.com/betrusted-io/xous-core/blob/main/docs/images/modals_dynamic_notification.png?raw=true) + /// ![Example Image](https://github.com/betrusted-io/xous-core/blob/main/docs/images/modals/dynamic_notification.png?raw=true) /// ///
///