THE WHOLE DESIGNER, REWRITTEN IN RUST?! 547 Widgets, Zero Segfaults, and a Code Generator That Reproduces 390 Files Byte-for-Byte!

The entire LightGUI designer ported from C++/GTK3 to Rust: gtk-rs 0.18, x11rb 0.13, 547 widgets in 14 archetypes, 167 tests passing, code generation byte-for-byte — and the pixel gap, stated honestly.

THE WHOLE DESIGNER, REWRITTEN IN RUST?! 547 Widgets, Zero Segfaults, and a Code Generator That Reproduces 390 Files Byte-for-Byte!

There is a particular kind of rewrite that never gets started, and it is not the hard kind. It is the big kind. You have a working C++ application — a GUI designer with 547 widgets, six windows, a code generator, a debugger, and a project file format — and the rewrite means touching every single piece of it, with no piece allowed to come back wrong. LightGUI in Rust is that rewrite, finished: the entire designer ported from C++/GTK3 to Rust, widget for widget, window for window, byte for byte where it counts — and the numbers below are the measured results, including the ones that are not flattering yet.

The Rust designer running under Xvfb: the generated-code view, the 583-entry Widgets palette, and the Object Inspector with its colour palette — three of the six windows, live at once.

The count, stated straight — with corrections

First, three corrections to numbers from the first article, stated openly, because the old ones are still floating around. The widget families in the registry are Stock 37, Instrumentation 66, and X 2 — not 38 and 67. The shared StockData.h and InstData.h headers were counted as widgets by mistake; they are headers, not widgets. The event kinds are 10, not 11. And the debugger harness is 44 checks, not 46. The 46 was a miscount; the harness that runs against real GDB has 44 checks, and all 44 pass. If you see 38, 67, 11, or 46 anywhere, those are the old counts, not this build.

The corrected registry, re-derived from the C++ sources and checked by machine, is 547 widgets in 14 archetypes — and every widget belongs to exactly one archetype:

ArchetypeWidgets
Indicator250
Container53
Instrument49
Chart36
ListSel37
Dialog25
Display22
Button21
Toggle18
Entry14
Range13
Label7
Graph1
Spreadsheet1
Total547

The 250 Indicators are the long tail — every technical indicator from the stock-market section, each one a real widget with its own drawing code. The 49 Instruments are the gauges, tanks, and meters from the control-room section. The rest are the everyday GUI toolkit: containers, dialogs, buttons, entries, lists, and charts. All 547 are in the registry as data, not as 547 special cases in code.

What the port actually is

This is not a wrapper around the C++ binary, and it is not a fresh design that happens to share a name. It is a port: the same designer, the same widgets, the same project format, rebuilt in Rust. The toolkit is gtk-rs 0.18 (GTK 3.24) for the designer itself, x11rb 0.13 for the raw-X11 widgets that draw themselves pixel by pixel with no toolkit underneath, and serde for the .fdj project format. The Cargo workspace is thirteen crates:

CrateJob
lightgui-designerThe designer application itself — canvas, menus, six windows
lightgui-coreProject model, properties, events, the .fdj format
lightgui-genThe code generator — layout to C++/GTK source
lightgui-debugThe GDB debugger harness and interface
lightgui-supportCode view, themes, preferences, CMake build
xframe-coreShared widget core for the raw-X11 widgets
xframe-indicatorsThe 250 indicator widgets
xframe-widgetsThe remaining XFrame widget families
xframe-demoThe 547-widget demo runner
xframe-paletteThe 547-widget palette window
xframe-layoutThe layout window
xframe-test-runnerThe automated widget test runner
xframe-commonShared types across the XFrame crates

Alongside the crates sit data/ — the registry, palette, properties, events, and indicators as JSON, regenerated from the C++ sources rather than typed by hand — and probe/, the tooling that measured the port against the original. The source of truth stayed the C++ code; the Rust side was checked against it, not against somebody's memory of it.

Six windows, each its own — matching the C binary exactly

The Rust designer opens the same six top-level windows as the C++ one, each doing one job: the designer canvas, the Widgets palette, the Object Inspector, the code view, the 547-widget palette, and the layout window. The Object Inspector is its own window, separate from the layout — 340×700, matching the C binary exactly — so the properties of the selected widget never cover the thing you are editing. The palette is the combined 583-entry palette: 36 designer widgets plus all 547 library widgets. Nothing was merged, tabbed, or folded away to make the port easier.

The byte-for-byte proof

A port can look right and still be wrong in the ways that matter — a project that saves differently, code that generates differently, a layout that builds differently. So the port was checked where it counts, in bytes:

  • Code generator: reproduces all 16 matrix cases / 390 files byte-for-byte — the generated C++ is identical to what the C++ designer generates, file for file.
  • Project files: a .fdj save from the Rust designer is byte-identical to the C++ saver's output for the same project. Open a Rust-saved project in the C++ designer, or the other way around — the bytes do not care which one wrote them.
  • Designer seam test: 4 / 4 — all 547 widgets through the full seam: layout, save to .fdj, generate, CMake build.
  • Palette self-test: 583 / 583 — every palette entry resolves to a real widget.

That is the point of a port done this way: the Rust designer is not a compatible-ish reimplementation. For the artifacts it produces — the generated code and the saved projects — it is indistinguishable from the original.

The test numbers, measured not promised

SuiteResult
cargo test --workspace (25 targets, under Xvfb)167 passed, 0 failed
Code generator matrix16 / 16 cases, 390 / 390 files byte-for-byte
.fdj savebyte-identical to the C++ saver
Designer seam test4 / 4 — all 547 through layout → .fdj → generate → CMake build
Palette self-test583 / 583
Debugger harness (real gdb 17.1)44 / 44
547-widget demo runner — build547 / 547
547-widget demo runner — draw546 / 547 (only GtkInvisible blank, by design, as in C++)
547-widget demo runner — key handling547 / 547
547-widget demo runner — exit547 / 547
Fresh-clone buildgreen
Release buildgreen in 1m 23s

The debugger deserves a line of its own: the harness runs 44 checks against real gdb 17.1 — run, step, breakpoints, locals, watches, call stack — and all 44 pass. The debugger was not stubbed out for the port; it drives a real debugger session, the same way the C++ one does.

The honest caveats — what does not match yet

Now the part a port announcement usually hides. The pixel comparison against the C++ screenshots is 42 / 547 MATCH (under 5% difference), with a median difference of 15.3%. That is the real number, and here is why it is what it is. The largest share of the gap is demo geometry, not widget drawing: the Rust demo renders each widget at 200×90, while the C++ reference mains render at 720×480, so absolute gutters and fonts land in different relative places and every pixel comparison pays for the size difference before it measures any drawing difference. On top of that, the Instrument archetype sits at a median of about 21% — its segment and LED displays improved from roughly 99% difference to roughly 26%, which is real progress and still not a match — and there are per-widget text and style differences scattered through the rest. The widgets draw; they do not yet draw identically.

Two more, for the record. Clippy still shows about 19 warnings in hand-written files — the generated code is clean; the warnings are in code a human wrote, and they are warnings, not errors, but they are there. And the run-matrix equivalent is 20 / 21: there is no chart-pro-screenshot equivalent yet, so one matrix case has no Rust counterpart to compare against.

One real bug was found and fixed during integration, and it is worth naming because it is exactly the kind of bug a port shakes out: Chart and Indicator widgets drew at (0,0) after a move — they stayed where they were born instead of following the widget — until set_bounds was made to propagate to the inner plot view. It is fixed, it is covered by the seam test, and it is the reason the seam test exists.

Where it lives

The port is open source at github.com/cnmcdee/lightgui_rust — main branch, remote HEAD 119cb5b, ported from the C++ sources at eb0b5fc. Clone it, cargo test --workspace under Xvfb, and the 167 tests above are the ones you will see pass. The pixel gap is the known next job: same geometry, then same pixels. The byte-for-byte parts — the generated code, the saved projects — are already done, and they are the parts a designer is actually for.

Linux Rocks Every Day