linfb 0.2.1

Library for interaction with Linux framebuffer
Documentation

linfb is a drawing library that uses Linux' /dev/fb0 device as it's backend. For most tasks you probably want to use OpenGL or Vulkan backed library. /dev/fb0 is deprecated but still useful for some specific cases. This library supports framebuffers that use 32 bits per pixel, so (theoretically) most modern systems.

Before drawing on framebuffer you should allocate a virtual terminal and switch to it. I recommend using vt crates for this task. You should never draw on virtual terminal used by X.org/Wayland server, this is unsafe and can lead to panics.

By default linfb includes text and images drawing capabilities, which brings additional dependencies. You can disable these features if you only need low-level framebuffer interactions and [Shape] trait.

Basic usage can look like this:

use linfb::Framebuffer;
use linfb::shape::{Color, Shape, Rectangle, Caption, Image, FontBuilder, Alignment};
let mut framebuffer = Framebuffer::open()
.expect("Failed to open framebuffer");
let mut compositor = framebuffer.compositor((255, 255, 255).into());
compositor
.add("rect1", Rectangle::builder()
.width(100)
.height(100)
.fill_color(Color::hex("#ff000099").unwrap())
.build()
.unwrap()
.at(100, 100))
.add("rect2", Rectangle::builder()
.width(100)
.height(100)
.fill_color(Color::hex("#00ff0099").unwrap())
.build()
.unwrap()
.at(150, 150))
.add("image", Image::from_path("image.png")
.unwrap()
.at(500, 500))
.add("wrapped_text", Caption::builder()
.text("Some centered text\nwith newlines".into())
.size(56)
.color(Color::hex("#4066b877").unwrap())
.font(FontBuilder::default()
.family("monospace")
.build()
.unwrap()
)
.alignment(Alignment::Center)
.max_width(650)
.build()
.unwrap()
.at(1000, 300));
// Compositor is shape, so we can just draw it at the top left angle
framebuffer.draw(0, 0, &compositor);
// Really changing screen contents
framebuffer.flush();