Skip to content

riley-williams/buoyant

Repository files navigation

Buoyant

Partially working espresso machine UI

Crates.io Documentation

Buoyant is a library for writing and rendering SwiftUI-like views in Rust, primarily intended for use on no_std memory-constrained embedded systems.

Get started with the Book.

Available render targets

While this crate is primarily intended for use with embedded-graphics DrawTargets, it can also be used to layout and render views to the terminal.

  • 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.

Example

Here's an animated toggle component, implemented with Buoyant:

Toggle

fn toggle_button(is_on: bool) -> impl View<Rgb565, bool> {
    let alignment = if is_on { Alignment::Trailing } else { Alignment::Leading };
    let color = if is_on { Rgb565::GREEN } else { Rgb565::RED };

    Button::new(
        |is_on: &mut bool| *is_on = !*is_on,
        |_| {
            Capsule.foreground_color(color)
                .overlay(
                    alignment,
                    Circle
                        .foreground_color(Rgb565::WHITE)
                        .padding(Edges::All, 2)
                )
            .frame_sized(50, 25)
            .animated(Animation::ease_in_out(Duration::from_millis(500)), is_on)
            .geometry_group()
        }
    )
}

Feature progress

Layout and Rendering

Static layout and animation between layouts are relatively feature-complete, aside from transitions. You should be able to construct most desired layouts and animations.

  • βœ… Stacks of heterogeneous views (VStack, HStack, ZStack)
  • 🚧 Stacks of homogeneous views (ForEach) - partial, vertical only
  • βœ… Common SwiftUI-like primitives (Spacer, Divider, ...)
  • βœ… Common SwiftUI-like modifiers (.frame, .padding, ...)
  • βœ… Conditional views, with match variable binding
  • βœ… Text (embedded-graphics Monospace and u8g2 fonts)
  • βœ… Images (fixed size)
  • βœ… Interruptible Animations + Curves
  • 🚧 Transitions (partially implemented)
  • βœ… Shape stroke+fill
  • βœ… Common embedded-graphics shape primitives
  • βœ… Custom sizing with GeometryView
  • πŸ’€ Charts
  • πŸ’€ Canvas for arbitrary path/shape/raster drawing
  • πŸ’€ Simulated alpha and antialiasing
  • πŸ’€ Shape styles (e.g. gradients)

Interactivity

Interactivity is under active development, and is not yet feature-complete.

  • βœ… State management
  • 🚧 Click/tap routing
  • βœ… Button
  • 🚧 ScrollView
  • πŸ’€ Focus management + keyboard input
  • πŸ’€ TextField

Who should use this?

This project could be used in production by the brave, but is probably better suited for hobby projects at this point. It's significantly 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.

About

Declarative UI layout and rendering for no_std targets, inspired by SwiftUI

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Sponsor this project

  •  

Contributors 4

  •  
  •  
  •  
  •  

Languages