#ui #layout #graphics #view #rendering #render #render-target

no-std buoyant

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

4 releases

0.1.3 Jun 9, 2024
0.1.2 Jun 9, 2024
0.1.1 Jun 8, 2024
0.1.0 Jun 5, 2024

#98 in Graphics APIs

Download history 196/week @ 2024-06-02 245/week @ 2024-06-09 26/week @ 2024-06-16

467 downloads per month

MIT/Apache

61KB
1.5K SLoC

Buoyant

This is a library for writing and rendering SwiftUI-like layouts in Rust.

Goals

  • Embedded / no_std support:
    • Zero heap allocation
    • Minimal memory footprint
    • Immediate mode, CPU rendering
  • Support for both text-based and pixel-based rendering and layout through the use of generic traits
  • Ability to support a variety of render devices (e.g., terminal, framebuffer, SPI display, ...)

Layout and rendering

  • View definition: This follows the SwiftUI model of defining the view hierarchy entirely withing the type system.

  • Layout: The view object is passed through the layout engine, which computes the size of each view. Just like SwiftUI, the parent offers a size, but children are free to choose their own size. This produces a statically typed layout tree that mirrors the structure of the view definition.

  • Render: The render target is passed to the layout, and the layout engine renders the view hierarchy to the target. Minor layout computations such as text wrapping may be repeated, depending on the available cache size.

Available views

  • Text: A view that renders text. The text is wrapped to the width of the parent offer, attempting to respect word boundaries. Options are available for multiline text alignment.

  • HStack, VStack: Views that stack their children horizontally or vertically. The size of the stack is determined by the size of the children. Alignment and spacing options are available.

  • Spacer: A view that takes up all available space in the parent view. It is aware of the layout direction it was presented in, and will expand in the appropriate dimension.

  • Divider: A view that renders a horizontal or vertical line. Like Spacer, it is aware of the layout direction it was presented in, and will render as a line in the appropriate dimension.

  • Padding: A view that adds padding around its child view. This is equivalent to the SwiftUI padding modifier.

Available render targets

  • TextBuffer: A basic fixed-size char buffer. Does not respect graphemes. This is primarily useful for testing and debugging.

Roadmap

  • crossterm rendering
  • embedded-graphics trait implementations
  • Layout reuse
  • Animations
  • click/tap routing
  • Examples!

Usage notes

It is a work in progress and should not be used in production.

At this point in time, all public API should be considered unstable, and this library does not yet respect SemVer.

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

~0.8–6MB
~22K SLoC