XStackBar

XStackBar

XStackBar is a Monitor widget in LightGUI's XFrame widget set. Stacked multi-segment bar (used/cached/buffers/free) with a legend.

XStackBar shows one total split into named segments — the classic memory bar: used, cached, buffers, free — each in its own colour, with a legend naming them. Add a segment per part and the bar stacks them in order.

XStackBar running under Xvfb
XStackBar running — screenshot taken from the example below under Xvfb.

Key methods

  • add_segment(name, value, color) — append one named, coloured segment

Every widget also gets the shared properties visible, enabled, bounds (x, y, width, height) and style_name, plus the background / foreground colours from the active style.

Example

Segments stack left to right in the order added; the legend names each one.

XStackBar widget(display, screen, window, gc, &styles, 20, 20, 720, 40);
widget.add_segment("used",    512.0, Srgb{0, 170, 70});
widget.add_segment("cached",  256.0, Srgb{0, 100, 200});
widget.add_segment("buffers",  64.0, Srgb{200, 170, 0});
widget.add_segment("free",    128.0, Srgb{120, 120, 120});
widget.draw();

The snippet above is the widget part only. As with every XFrame example, the full program opens a display, creates a window and a style manager, then runs the standard event loop — see the complete example in the repo.

Build it from the repo root:

g++ -std=c++17 -Iwidgets/components -Iwidgets examples/XStackBar.cpp -lX11 -o XStackBar

Run it under Xvfb or a real X server; close the window to quit.

Example in the repo

The full working example is examples/XStackBar.cpp in the lightgui repo (C is canonical). The same widget is ported to the Rust and Python repos under the same name — see the links below.

Get the code

These widgets ship in all three LightGUI repos:

See also

Linux Rocks Every Day
Source code: LightGUI (C) · LightGUI (Rust) · LightGUI (Python)