#declarative-ui #ui #embedded-graphics #graphics #rendering #display #tui

nightly no-std buoyant

A library for building and rendering declarative SwiftUI-like UIs in Rust

10 releases

new 0.3.0-alpha.3 Feb 19, 2025
0.3.0-alpha.1 Feb 9, 2025
0.2.3 Dec 27, 2024
0.1.5 Jul 10, 2024
0.1.3 Jun 9, 2024

#93 in Graphics APIs

Download history 2/week @ 2024-10-29 3/week @ 2024-11-05 1/week @ 2024-12-10 120/week @ 2024-12-24 1/week @ 2025-01-07 89/week @ 2025-02-04 15/week @ 2025-02-11

104 downloads per month

MIT/Apache

180KB
5K SLoC

Buoyant

This is a library for writing and rendering SwiftUI-like views in Rust, primarily intended for use on no_std memory-constrained embedded systems. Floating point math is aggressively avoided.

Available render targets

  • DrawTarget: embedded-graphics displays.
  • TextBuffer: A basic fixed-size char buffer. Does not respect graphemes. This is primarily useful for testing and debugging.
  • CrossTerm: Renders colored character-pixels to a terminal using the crossterm crate.

A Quick Example

Here's what an Apple-like toggle button component would look like, implemented with Buoyant:

// Omitting the large number of imports...

fn toggle_button(is_on: bool) -> impl Renderable<Rgb565, Renderables: EmbeddedGraphicsRender<Rgb565>> {
    let alignment = if is_on {
        HorizontalAlignment::Trailing
    } else {
        HorizontalAlignment::Leading
    };

    let color = if is_on { Rgb565::GREEN } else { Rgb565::RED };

    ZStack::new((
        Capsule.foreground_color(color),
        Circle.foreground_color(Rgb565::WHITE).padding(2),
    ))
    .with_horizontal_alignment(alignment)
    .frame(Some(50), Some(25), None, None)
    .animated(Animation::Linear(Duration::from_millis(200)), is_on)
}

As state management isn't yet implemented, this isn't really a useful component yet. Maybe I should have picked a different example....

Feature progress

Layout and Rendering

  • Fixed-size Stacks with hetereogeneos children (VStack, HStack, ZStack)
  • Stacks with homogeneous children (ForEach) - partial, vertical only
  • Common SwiftUI primitives (Spacer, Divider)
  • Conditional views - partial, no unwrapping
  • Text, basic line breaking
  • Text, Unicode line breaking
  • Text, monospaced fonts
  • Text, arbitrary fonts
  • Animation
  • Transition
  • Common embedded-graphics shape primitives
  • Canvas for arbitrary path/shape/raster drawing
  • Shape stroke/fill
  • Shape styles (gradients, fragment shaders)
  • Images
  • Alpha rendering
  • Adaptive antialiasing

Interactivity

  • State management
  • Click/tap routing
  • Focus management + keyboard input (Text input view)

Who should use this?

This project should not be used in production...yet. For hobby projects it's lightyears better than dealing with raw embedded-graphics. If you're familiar with SwiftUI, you should feel especially at home.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~4–12MB
~128K SLoC