r/rust • • 2d ago

🛠️ project blit: immediate (yet deferred) mode UI

I've been working on this for 5 months and was hesitant to post given the flood of rust UI frameworks.

its modularity is pretty unique compared to other rust UI libs. the core is #![no_std] with zero dependencies, and it runs on embedded devices (with a very fast software renderer), TUIs, and wgpu.

it's still early and experimental, but hope you find the writeup interesting

repo: https://github.com/nicoburniske/blit

https://pasttheboonies.com/jots/blit/

91 Upvotes

22 comments sorted by

19

u/syberianbull 1d ago

Embedded UI is a very underserved niche in Rust with only Slint being an option the last time I checked. But Slint licensing is a bit problematic for some applications, so any advances in this space are very welcome, keep going!

My particular use case would be something self made that is analogous to https://gaggiuino.github.io/#/?id=home. If blit supported all of the necessary widgets and can be comprehended by a non-softeare related engineer, it would immediately move into my perspective stack for the project (it's a very very long term type of thing 🙈).

And make sure to get blit listed on areweguiyet.com with an embedded tag for improved discoverability.

22

u/nicoburniske 1d ago

hey! yeah at my dayjob we've been using Slint for 2 years so I'm very familiar with it. the license, along with compile times and binary sizes, were big issues for us too.

the hardest part with embedded is how many different targets there are, so `blit-cpu` lets you write platform-specific SIMD kernels and custom pixel formats (the kindle port uses a `Gray8` framebuffer since it doesn't need color). you can even EXTEND the renderer with your own paint primitives!

on widgets, I'm actually hesitant to ship a big one-size-fits-all widget set. trying to make everything themeable across TUIs, embedded screens, and GPUs is a huge maintenance trap, and widgets in blit are some of the simplest code to write imo. blit is meant to let you build your own mini framework in a few hundred lines so your UI looks (and acts) how you want.

the platform agnostic "standard library" for blit is here (needs more docs haha), which has things like flex/grid layouts and text-input:

https://docs.rs/blit-widget/0.1.0/blit_widget/

ultimately I never want the user to be a prisoner to the framework, in license or in code.

3

u/CaptainJack42 1d ago

This looks neat, might give it a shot once I find some time. Do you have any Benchmarks about flash/ram requirements for embedded use cases?

4

u/nicoburniske 1d ago

no formal MCU benchmarks yet, just a quick size test I ran (opt-level = "z", LTO, panic = "abort", ~100-node line-buffered RGB565 UI):

  • core + blit-cpu scanline renderer: ~250 KB flash and ~60-100 KB RAM

    • ~253 B/node (worst case!) for the double-buffered tree + scanline working buffers
    • blit-cpu walks top-to-bottom one line at a time, so you don't strictly need a full framebuffer in RAM unless you use primitives that read it back (like backdrop blur)
  • BYOT (bring your own textsystem!):

    • minimal 8x8 bitmap font: ~170 LOC, ~14 KB flash, ~0 RAM cache
    • ab_glyph / fontdue for scalable TTFs: ~100-200 KB flash + your font and glyph cache

for a real-world reference, our smaller stripped ARMv7 apps on KeyOS (500 MHz Cortex-A5, 128 MB RAM) are ~730 KB total (opt-level = 3, no LTO, std, OS/IPC glue, ttf parsing, custom text rasterizer)

0

u/kissfrosted 1d ago

yeah those numbers would help me decide if its worth digging into too

0

u/FlirtyChunz_ 1d ago

might give it a shot too if the numbers aren't too scary, lmk what you find

4

u/teerre 1d ago

Very nice

2

u/Immotommi 4h ago

I was reading your article think that this reminds me of Anton's video, then I saw your attribution at the end.

Really love that it is no std. Being able to bring your own allocator is really cool

5

u/titaniumalt 1d ago

Awesome library, great ideas, also great execution, can't find signs of AI, and i really wanted to find something like blit for a long time already, congratulations!

1

u/decryphe 4h ago

Interesting read about the layouting engine, I learnt something new today.

1

u/stylist-trend 1d ago

Looks neat! This feels like it would work well as the graphics layer for firmware on the FM-1

1

u/wyvernbw 1d ago

this looks super cool and i usually hate new rust gui frameworks, great job. i was just about to give up and write my app's ui in swift, so this came at a weirdly right time, i'll keep an eye on it. Are there any plans to support accessibility?

1

u/rexpup 22h ago

Thanks for posting this! I just was looking for a UI for the Pimoroni Presto. I've gotten started with blit.

-18

u/Sermuns 2d ago

read rules of subreddit.

9

u/nicoburniske 2d ago

hey, I have spent a lot of time working on this lib + the associated article (which does in depth framework comparisons!), so AFAIK it does follow rule 7. lmk if I am missing something?

4

u/dumindunuwan 1d ago edited 1d ago

This does not look like an AI slop, plus it’s an interesting journey + demo on README

How these widgets in demo act, performance-wise compared to Slint and Clay?

7

u/nicoburniske 1d ago

clay is actually blit's biggest inspiration! I wanted to bring the clay model to rust and take advantage of the rust type system. clay is more portable since it's a single C header, though it's layout-only with a fixed set of layouts and draw commands, whereas blit puts layouts, interactions, and paint primitives in user space and ships with its own renderers.

in some simple micro-benchmarks I ran on a 1,000-node flex row, blit is ~2-3x faster than clay. a big reason is memory layout. clay packs everything into one flat 288-byte struct per node (convenient for a single allocator), while blit uses side-tables for rarely set properties to keep each node down to 52 bytes minimum.

vs slint, on our 500 MHz ARM device blit is ~4x faster on average, especially on layered/occluded UI, partial repaints (like typing or key presses), and scrolling. and on desktop, blit's software renderer is the fastest I've seen, hitting ~165 fps at 5K on a single thread (which still feels kinda unheard of to me). things like shadows and alpha blending will obviously kill framerate though.

1

u/Frozen5147 1d ago

TBF the rules don't care about AI slop or not (unfortunately, though I get why).

That said yeah this does seem to meet the rules for libraries from a quick glance so more power to OP.

11

u/Zde-G 1d ago

The blog post is actually pretty interesting.

Not my piece of cake (I've done GUI last time around 10 years ago thus a lot rusty in that area) but it's not a typical slop.

I just wish reddit post, itself, would have included at least something from it, though, instead of saying “hey, here's another GUI library, look at it”…