Files
lightgui_rust/PORTING_PLAN.md
T

34 KiB
Raw Blame History

LightGUI → Rust — Porting Plan

Survey-only document. No Rust code has been written yet. Source: /opt/lightgui on hot_newyork (172.93.49.176), repo https://github.com/cnmcdee/lightgui, HEAD eb0b5fc ("Docs for LightGUI: 547 widgets, 583-entry palette, Object Inspector window"). Target repo: https://github.com/cnmcdee/lightgui_rust (empty, public, main). Survey date: 2026-11-29. Do NOT touch /opt/lightgui, the C repo, or any Ghost/NPM/mailserver/GoAccess container.

0. Toolchain verified on hot_newyork

Tool Version Note
rustc / cargo 1.100.1 stable (20ddd0171 / 3acc79c0c) via rustup Only on login-shell PATH (bash -lc) or /root/.cargo/bin; plain non-login ssh … rustc says "command not found". Always use bash -lc or export PATH.
git 2.53.0 Direct GitHub SSH works, no agent forwarding (ssh -T git@github.com → "Hi cnmcdee!")
libgtk-3-dev 3.24.52 pkg-config --modversion gtk+-3.0 = 3.24.52
libglib2.0-dev 2.88.0
libcairo2-dev 1.18.4
libpango1.0-dev 1.57.0
libatk1.0-dev 2.60.4
libgdk-pixbuf-2.0-dev 2.44.5 (hyphenated name; libgdk-pixbuf2.0-dev has no candidate)
libX11 1.8.13 X11 widgets are raw Xlib, not GTK — see §2
gdb 17.1 (Ubuntu 17.1-2ubuntu1) Debugger backend target
xvfb-run, cmake, python3 present Headless GUI tests

Open risk: curl -I https://crates.io returned HTTP 403 (bot block on HEAD). A probe crate fetch (cargo new + a gtk/x11rb/serde dependency) must be run before committing to gtk-rs/x11rb; if crates.io is unreachable from the VPS, the fallback is vendored crates or direct FFI (gtk-sys, libc + Xlib). Do not start the designer port until the probe passes.

1. What the source actually is — two runtimes in one repo

The single most important survey finding: the 547 widgets are NOT GTK widgets. There are two different UI stacks:

  1. The designer IDE (src/, ui/) — GTK 3 via the C API. src/main.cpp (4,751 lines) loads ui/designer.ui (810 lines) through GtkBuilder, places real GTK widgets on a GtkFixed canvas, and edits them live. The code generator emits C++/GTK.
  2. The XFrame widget library (widgets/) — raw X11. Every widget is a standalone C++ class that draws itself with Xlib (Display* / Window / GC, XDrawRectangle, XDrawArc, XTextWidth, XFlush) through a shared style manager. No GTK, no gtkmm, no Cairo in the widget draw path. Each widget ships with its own X11 demo main.

The two halves meet only at the combined palette (583 entries) and the seam converter (widgets/tools/layout_to_lightgui.py), which turns an XFrame layout into a LightGUI project. A faithful port must therefore keep both runtimes, in Rust: gtk-rs for the designer, x11rb (or Xlib FFI) for the widgets. Do not try to re-implement the XFrame widgets as GTK widgets — that would change every pixel and every demo.

2. Source inventory (line counts from wc -l)

2.1 Designer — src/ (22,749 lines total)

File Lines Role
main.cpp 4,751 Designer: GtkBuilder UI, GtkFixed canvas, property pane, events pane, bulk ops, StockChart CSV preview, LIGHTGUI_SELFTEST / LIGHTGUI_PALETTE_SELFTEST hooks, palette window (36 FD + 547 XFrame buttons)
generator.cpp / generator.h 2,452 / 29 Code generator (see §5)
debugger.cpp / debugger.h 1,406 / 277 GDB/MI backend (see §6)
debugger_ui.cpp / debugger_ui.h 1,110 / 51 Debugger window (GTK)
codeview.cpp / codeview.h 864 / 122 Generated-code viewer: syntax highlight, brace matching, folding (FoldRegion, CodeViewInspectState)
theme.cpp / theme.h 509 / 80 Designer colour themes (CodeTheme, HlSpan)
project_io.cpp / project_io.h 368 / 24 .fdj JSON save/load, hand-rolled JSON (no library)
preferences.cpp / preferences.h 283 / 52 Settings incl. FontSettings, debugger settings persistence
cmake_build.cpp / cmake_build.h 176 / 52 Build generated projects (CMakeSettings, CMakeBuildResult)
props.h 277 Property tables (see §4)
events.h 227 Event/signal tables (see §4)
model.h 86 Project model (see §4)
xframe_palette.h 579 GENERATED palette table (see §3)
indicators.h / indicators_embedded.h 3,885 / 3,890 250 indicator modules for StockChart (namespace fdi)
drawings.h / drawings_embedded.h 597 / 602 Chart annotations (namespace fdw, 11 kinds)
ui/designer.ui 810 Glade file: 3× GtkWindow, 36× GtkButton, 19× GtkMenuItem, 7× GtkLabel, 5× GtkMenu, 5× GtkCheckMenuItem, 4× GtkSeparatorMenuItem, 2× GtkScrolledWindow, 2× GtkGrid, 2× GtkBox, GtkStatusbar, GtkPaned, GtkMenuBar, GtkFixed

Build: plain Makefile (g++ -O2 -Wall -Wextra -std=c++17, pkg-config gtk+-3.0). make = designer binary + all widget demos (CMake under widgets/). make test = seam test only. ide script starts designer + palette + layout.

2.2 XFrame widgets — widgets/ (775,615 lines of component headers)

Item Count / size
Component dirs in widgets/components/ 549 listed; 547 widget classes per the registry
Widget header files (*.h) 547
Per-widget demo mains (main_<Name>.cpp) 547
Total component header lines 775,615 (smallest 97 lines, largest XSpreadsheet.h 2,428; XGraph.h 1,277; GtkFileChooserDialog.h 1,319; TDateTimePicker.h 1,163)
Palette icons widgets/icons/*.ico 547 (16×16, 24bpp BMP ICO)
widgets/core/xframe_core.h 988 lines — shared core (see §3)
widgets/components/StockData.h 116 lines — OHLCV + deterministic seeded series (xorshift64*, seed 42, random walk from 100.0, daily bars from 2026-01-01)
widgets/components/InstData.h 97 lines — tank-level clamp, InstAlarmBands, InstSwitchState (Off/On/Tripped), InstLamp
widgets/common/registry.h 1,773 lines, GENERATED (see §3)
widgets/common/ico.h 101 lines — minimal BMP ICO decoder + XImage loader (no image lib)
widgets/common/ipc.h 63 lines — palette↔layout file IPC (see §7)
widgets/palette/main_palette.cpp 389 lines — palette window (X11)
widgets/layout/main_layout.cpp 740 lines — layout window (X11)
widgets/test-driver/run_tests.py 208 lines — per-widget demo tester
widgets/CMakeLists.txt + per-widget CMakeLists.txt CMake, C++17, find_package(X11), one executable per widget

Widget families (from ls widgets/components):

Family Count Meaning
Gtk* 102 GTK-named controls re-implemented as hand-drawn X11 widgets
T* 90 Lazarus/Delphi-style controls (TButton, TForm, TNotebook, …)
Ind* 250 Stock-market indicators (each a widget + a formula)
Stock* 38 Stock charts / drawing tools (candlestick, Renko, VWAP, trendline, …)
Inst* 67 Instrumentation (gauges, lamps, LEDs, tanks, switches, …)
Total 547

Palette sections (11, from sections.py / xframe_palette.h): Windows & Dialogs 28, Containers & Layout 34, Buttons 24, Display 33, Text & Entry 28, Choosers 10, Views & Lists 17, Menus & Toolbars 16, Misc / X 4, Stock Market 287 (= 250 Ind + 37 Stock + …; see note below), Instrumentation 66. Note: README counts 66 instrumentation vs 67 Inst* dirs — one Inst* class sits in another section; the registry is authoritative, not the name prefix. Total sections sum to 547.

2.3 Docs & tools

  • DESIGN.md (402 lines) — original design: Tk→GTK mapping, JSON .fdj replacing pickle, all-code generator revision, StockChart addition.
  • README.md (267 lines) — features, install (build-essential pkg-config libgtk-3-dev glade cmake gdb xvfb python3), palette section table (generated between <!-- SECTIONS:BEGIN/END --> markers).
  • docs/ — 25 Markdown files (buttons, choosers, containers-layout, display, ide, instrumentation-, menus-toolbars, misc-x, stock-market-, text-entry, views-lists, windows-dialogs).
  • widgets/tools/ — gen_registry.py, gen_xframe_palette_data.py, sections.py (section assignment + accent colours), widget_count.py, glyphs_*.py (5 icon generators: buttons/inst/stock/text/windows), gen_icons.py, layout_to_lightgui.py (seam converter), render_widget_pics.py, verify_*.py, test_inst_*.py, stock_indicators_{momentum,trend,volatility}.txt + .json spec.
  • tools/ — gen_palette_icons.py (340 lines), verify_palette_icons.py, embed_drawings.sh, embed_indicators.sh (produce the *_embedded.h files the generator pastes verbatim into generated code).

3. Widget definition shape — what a widget IS

Every XFrame widget follows one rigid template (verified on GtkButton, IndRSI, InstPressureGauge). This is the port's central fact: the 547 widgets are variations on one archetype, mostly hand-written but mechanically regular — not 547 unrelated programs.

Per-widget directory: <Name>.h, main_<Name>.cpp, CMakeLists.txt, plus a core/ dir (empty placeholder; the real core is widgets/core/).

class <Name> {
    Display *display_; int screen_; Window window_; GC gc_;
    SStyle_Manager *styles_;
    int x1_, y1_, x2_, y2_;                 // bounds (x,y,w,h at construction)
    std::string name_, text_, style_name_;  // "" style = manager's active style
    bool visible_=true, enabled_=true, focused_=false, pressed_=false;
    // family extras: hover_, value_/min_/max_, period_, etc.
public:
    std::function<void()> on_click;          // (some widgets: more callbacks)
    <Name>(Display*, int, Window, GC, SStyle_Manager*, int x, int y, int w, int h [, defaults]);
    void set_bounds(int,int,int,int); int width(); int height();
    bool contains(int x, int y);
    void set_visible(bool); bool get_visible();
    void set_enabled(bool); bool get_enabled();
    void set_style_name(std::string); void set_text(std::string); std::string get_text();
    SStyle style();                            // styles_->resolve(style_name_)
    void draw();                               // Xlib primitives via xf:: helpers
    bool on_button_press(int x, int y, unsigned button);
    bool on_button_release(int x, int y, unsigned button);
    bool on_motion(int x, int y);
    bool on_key(KeySym key, const char* str);
};

Shared core (widgets/core/xframe_core.h, 988 lines): Srgb, SStyle (fill/outline/line/text colours, radius, lineWidth, font), SStyle_Manager (named styles vector, add_style_ex, resolve, delete_style, bounds-safe getters, get_color_rgb), xf:: drawing primitives (draw_polished = two fill rects + four fill arcs rounded body, four lines

  • four draw arcs outline; draw_text_centered via XTextWidth + font ascent/descent), Canvas class. Style contract: default + dark styles registered by every demo (default Srgb{225,225,225}…, dark Srgb{45,45,48}…).

Demo main_<Name>.cpp (~36–53 lines, identical skeleton): XOpenDisplay, 800×600 window, select input (Exposure/Key/Structure/ButtonPress/Release/ Motion), WM_DELETE_WINDOW, SStyle_Manager, construct widget at (40,40,340,200)-ish, event loop dispatching to on_*, XClearWindow + draw() + XFlush when handled, exit on close. This is the generic widget-demo runner in waiting (see §8): one Rust binary driven by the registry can replace all 547 mains.

Family extras on top of the template:

  • Indicators (Ind*, e.g. IndRSI.h, 366 lines): header comment states formula, output-length contract ("output length == input length; leading warm-up bars are NaN"), draw style (pane/overlay/markers), attribution. Shared helpers in a detail namespace (sma, ema, wilder, stddev, highest, lowest, nanv, fin) are duplicated inline in each indicator header (copy-paste, not shared) — the Rust port must de-duplicate them into one module. Each indicator consumes OHLCVSeries (from StockData.h) and returns Vec<f64> with NaN warm-up.
  • Stock charts (Stock*, e.g. StockCandlestickChart.h, 252 lines): same template + OHLCV data + cairo-style candle rendering in Xlib.
  • Instrumentation (Inst*, e.g. InstPressureGauge.h, 160 lines): same template + value_/min_/max_ + set_value (clamped) / set_range / fraction() / fmt(); dial/needle/tank drawing with hard-coded constants (e.g. red zone above 240 psi, range 0–300, default value 180.0). InstData.h holds the shared clamps/alarms/switch states.

Hand-written vs generated: the widget classes are hand-written (775k lines, but ~90% template + draw calls); the registry, palette table, section table in README, and icon set are generated by Python tools from sections.py + the component directory listing. The Rust port must reproduce the generators, not hand-write 547 Rust files.

Registry schema (widgets/common/registry.h, GENERATED by gen_registry.py)

namespace lg {
  inline const int kWidgetCount = 547;
  inline const int kSectionCount = 11;
  inline const char* kSectionNames[kSectionCount] = { …11 names… };
  inline const char* kWidgetNames[kWidgetCount] = { …sorted names… };
  inline const int kWidgetSection[kWidgetCount] = { …section index per widget… };
  inline const int kWidgetDefaultW[kWidgetCount] = { … };  // default_size(): dialogs/windows 300×220, grids/lists 260×180, buttons 150×36, labels/entries 180×30, else 200×90; spreadsheet/graph 320×200
  inline const int kWidgetDefaultH[kWidgetCount] = { … };
  inline int index_of(const std::string& name);            // linear scan, -1 if absent
  // Type-erased factory: Holder<T> wraps any widget behind one interface
  // (same ctor + event-method signatures); a switch on 0..546 returns
  // std::make_unique<Holder<…>>(d, s, win, gc, st, x, y, w, h); default: nullptr.
}

Palette schema (src/xframe_palette.h, GENERATED by gen_xframe_palette_data.py)

struct XFramePaletteEntry { const char* name; const char* section; int index; /* registry index 0..546 */ };
inline const char* kXFrameSections[] = { …11… };
inline const int kXFrameSectionCount = 11;
inline const XFramePaletteEntry kXFramePalette[] = { {"GtkAboutDialog","Windows & Dialogs",0}, … 547 entries, section order … };

Rust equivalent: one registry.rs (or registry.toml/registry.json + build.rs codegen) holding name, section, default_w, default_h per widget, plus a WidgetKind enum and a create(kind, …) -> Box<dyn Widget> factory. The Python generators (gen_registry.py, sections.py, gen_xframe_palette_data.py) should be ported to a Rust codegen step that reads the same section data, so the registry stays generated, not hand-maintained. Keep the exact index order (palette → layout selection file carries the registry index).

4. Designer model — the data the IDE edits

src/model.h:

struct Widget { std::string name;            // "Button_001"
                std::string type;            // palette type key, e.g. "Button"
                int x, y, width, height;     // absolute geometry (Tk .place() style)
                std::map<std::string,std::string> props;  // GTK properties, as strings
                std::vector<std::string> signals; };       // signals to stub
struct Project { std::string title="Main Window", class_name="MyWindow";
                 int win_width=800, win_height=600;
                 std::string background;      // "" = default
                 std::string menubar;         // "File: New | Open | - | Quit", "-" = separator
                 std::vector<Widget> widgets; };
struct TypeInfo { const char* key; const char* palette_id; int def_width, def_height; bool phase1; };
// kTypes[]: 36 entries — Button, Label, Entry, Checkbutton, Radiobutton,
// Frame, Combobox, Listbox, Menubutton, Canvas, Scale, Scrollbar, Text,
// Toplevel, Spreadsheet, StockChart, Memo, GroupBox, Panel, Image, Shape,
// Notebook, ScrollBox, Splitter, StatusBar, ToolBar, MenuBar, SpinEdit,
// TrackBar, ProgressBar, DateTimePicker, ColorBox, ListView, TreeView,
// StringGrid, Plot.

src/props.h: enum class PropKind { Str, Bool, Int, Double, Color, Enum }, PropDef (name, kind, default, lo/hi for Int/Double, enum_labels / enum_values for Enum), one table per widget type. canonicalize() in main.cpp enforces lo/hi — a past bug let out-of-range values (e.g. Label xalign outside 0..1) reach GTK; the port must keep the same tables and the same clamping.

src/events.h: enum class EventKind { Simple, SwitchPage, RowActivated, RowSelected, BufferChanged, DeleteEvent, Draw, ItemClicked, ItemActivate, CellChanged } (11 variants), EventDef { signal, handler, label, kind, builtin } — e.g. {"clicked","on_clicked","Clicked",Simple}, {"draw","on_draw","Draw (redraw)",Draw}, {"delete-event", "on_delete_event","Window close (delete-event)",DeleteEvent}. builtin=true means already wired by the generator — document only, do not reconnect. Per-type static tables (button, canvas, scale, text, toplevel, spreadsheet, stockchart, memo, shape, notebook, toolbar, menubar, spinedit, …).

Project file (.fdj, project_io.cpp, hand-rolled JSON, format "lightgui", version 1): {"format","version","window":{title,class_name, width,height,background,menubar},"widgets":[{name,type,x,y,width,height, props:{…},signals:[…]}]}. Rust: serde + serde_json with the identical schema — existing .fdj files must load byte-for-byte equivalently.

5. Code generator — what it emits (sample verified)

src/generator.cpp (2,452 lines). Current revision (per DESIGN.md) emits all code, no .ui — so a stepping debugger can walk construction — with one standalone class per designed widget in its own .h/.cpp pair, mirroring the Python generator's boilerplate. Verified sample: tests/out/02_all_types/Button_001.h:

// Generated by LightGUI (C++/GTK) — standalone widget class.
class Button_001 {
  explicit Button_001(GtkWidget* fixed); ~Button_001();
  GtkWidget* widget() const;
  void util_error_print(const char* what);
  // nine mouse handlers: buttonPress1-3, dblbuttonPress1-3, buttonRelease1-3
  // + static on_press/on_release dispatchers
};

Per widget emitted: // #region <Name> creation + .place()-equivalent (gtk_fixed_put + size request) + config in the constructor, the nine mouse handlers routed by two dispatchers, util_error_print helper. The window class keeps the Root_001 handler set and just instantiates one widget class per designed widget; plus emit_main, a Makefile and a CMakeLists.txt per generated project. The StockChart implementation is emitted verbatim into every generated project that uses it (CSV loader load_csv, set_candles/candle_count, cairo wicks+bodies, min/max scaling; Massive aggregates CSV, columns matched by header name: ticker,volume,open,close,high,low,window_start,transactions). Per-type emitters: emit_notebook_pages, emit_toolbar_items, emit_menubar_items, emit_listview_setup, emit_treeview_setup, emit_stringgrid_setup, plus the embedded indicators.h / drawings.h pasted verbatim (via tools/embed_*.sh → *_embedded.h).

Port decision (needs a user call, §10): the Rust generator should first reproduce the C++/GTK output byte-for-byte (same files, same class-per-widget shape) — that is what the run-matrix tests verify. A second, Rust-emitting generator (gtk-rs output) is a later phase, not the port's first milestone. Do not change the emitted language silently.

6. Debugger — how it talks to GDB

src/debugger.h / debugger.cpp (1,406 lines): GdbSession spawns gdb -q -i=mi2 via fork() + execl() with two pipes (stdin in, stdout+stderr out, stdout set O_NONBLOCK); a hand-written MI parser handles *stopped/*running async records, result records, console (~) and log (&) streams, and gdb 13's plain i=0 x=1 … value lines. API: start/run/cont/step_over (-exec-next) / step_into (-exec-step) / step_out (-exec-finish) / kill_target / restart / interrupt (SIGINT to the inferior) / wait_for_stop(timeout_ms) / load_executable / start_gdb_only / shutdown (SIGKILL group if it lingers). Types: DebuggerSettings (incl. gdb_path, pretty-print, break_on_main, stop_on_entry), BpKind { Plain, Conditional, Logpoint }, Breakpoint, Variable, StackFrame, StopInfo, DbgState { Idle, Starting, Running, Stopped, Exited, Error }, MiValue. Breakpoints persist to disk between runs. debugger_ui.cpp (1,110 lines) is the GTK window (locals, watch list, stack frames, target stdout/stderr). Rust: std::process::Command + pipes + a dedicated MI-reader thread; the MI parser is the highest-risk hand port — port it with the existing harness as the oracle (see §9).

7. Palette / layout apps and IPC

  • widgets/palette/main_palette.cpp (389 lines) and widgets/layout/main_layout.cpp (740 lines) are separate X11 programs; the ide script runs designer + palette + layout together.
  • widgets/common/ipc.h: palette → layout via a selection file (/tmp/lightgui-selection.txt, env LIGHTGUI_SELECTION): palette writes <name>\n<registry index>\n on every selection; layout polls the file's mtime. Layout → tests via a state file (/tmp/lightgui-layout-state.txt, env LIGHTGUI_LAYOUT_STATE) written after every mutation. Icons dir via LIGHTGUI_ICONS (default /opt/lightgui/widgets/icons).
  • widgets/common/ico.h: 16×16 BMP ICO decoder, no image library.
  • Seam: widgets/tools/layout_to_lightgui.py converts an XFrame layout into a LightGUI .fdj project; make test runs it.

8. What is data vs code — the port's leverage

Data (port as tables / generated code, do not hand-write) Code (port by hand, once per archetype)
Registry: 547 names, sections, default sizes (gen_registry.py + sections.py) xframe_core: styles, draw_polished, text centring, Canvas
Palette table: 547 {name, section, index} Widget trait + event dispatch (press/release/motion/key, focus/pressed state machine)
Property tables + enum labels/values; event tables per type Property engine: validate + canonicalize (lo/hi clamping)
547 icons (.ico files — reuse as-is) Demo runner: one generic binary driven by the registry (replaces 547 mains)
Indicator formulas (pure Vec<f64> → Vec<f64>, NaN warm-up) — port formula-by-formula, de-duplicating the copy-pasted sma/ema/wilder/stddev helpers into one module Indicator registry + pane/overlay/marker plumbing in StockChart
Drawing specs (parse_spec grammar: trend/ray/arrow/h-line/v-line/rect/ellipse/text/Fibonacci/freehand/measure) Data→pixel mapping (Map) so drawings survive resize/zoom/pan
.fdj schema, .ui file (reuse ui/designer.ui verbatim via gtk-rs Builder) Generator emitters (per-type emit_*), GDB/MI parser, CMake runner
Glyph/icon generation scripts (glyphs_*.py) — port or keep as Python tools main.cpp UI wiring: canvas, inspector, bulk ops, rebuilders (notebook/toolbar/menubar/listview/treeview/stringgrid/spreadsheet)

The key insight: do not hand-port 547 widgets. Port the archetype (button-like, label/text-like, container, chooser/dialog, chart, gauge, lamp/LED, switch, tank, segment display) + the trait + a codegen step that derives each widget's struct from its C++ header's field list and draw() body pattern. Most draw() bodies are 10–40 lines of draw_polished / rectangle / arc / line / text calls with constants — classify first, then generate. The two outliers (XSpreadsheet.h 2,428 lines, XGraph.h 1,277) get their own milestones.

9. Test inventory — what must be ported, with counts

Counts below are as verified in this survey (code inspection, not re-runs). Where the parent brief quoted a count, the verification method is noted.

Suite Location What it checks Count
Generator matrix tests/run_matrix.sh + tests/gen_matrix.cpp Generate 16 designs, compile each with -Wall -Wextra (zero warnings), run 3 s under Xvfb (must stay up, exit 124 via timeout), no GTK CRITICAL/WARNING; plus candle-render, indicator-render, drawings, chart-pro-render, chart-pro-screenshot 21 checks (16 gen cases 01_empty…16_stockchart_pro + 5 render/screenshot) — enumerated from the script
Debugger harness tests/debugger_tests.sh, tests/debugger/dbg_harness.cpp GDB/MI: run/breakpoints (file:line + function), locals, watch/evaluate, step over/into/out, continue, disable/enable/delete, conditional/ignore-count/logpoint breakpoints, frames, kill/restart, settings, target args/output; console + GTK targets under Xvfb + GUI smoke 46 checks (47 report( calls in the harness incl. the helper definition) — counted
Palette self-test LIGHTGUI_PALETTE_SELFTEST=<log> in src/main.cpp Drives every palette button through its real clicked handler: 36 LightGUI buttons each add one widget; 547 XFrame buttons each write name+index to the selection file; icon-attach counts 583 entries (36 + 547) — verified in code
Widget placement / demo runner widgets/test-driver/run_tests.py Per widget: build demo, screenshot draw/hover/click/key/exit, pixel-diff thresholds (>50 px change = response), clean exit on WM_DELETE_WINDOW 547 widgets — one row per registry entry
Designer self-test LIGHTGUI_SELFTEST=1 ./lightgui Placement, properties, bulk ops, generation, save/load round-trips, Phase 5 extras; prints SELFTEST PASS/FAIL 1 run, many check()s in main.cpp
Seam test make test → widgets/tests/test_layout_to_lightgui.py XFrame layout → LightGUI .fdj conversion 1 suite
Per-area shell suites tests/{widget,palette_icons,palette_window,theme,font,event_handler,code_window,cmake}_tests.sh Icons load (all 547), palette window geometry, themes, fonts, event-handler codegen, code-window folding, CMake self-test 8 scripts
Stock / instrumentation Python tests widgets/tests/test_{stock_ohlc,stock_indicators_trend,stock_indicators_volatility,stock_drawing,stock_compare_volume,momentum_indicators,inst_lamps,inst_tanks,inst_switches,inst_group_f,inst_group_g,palette_layout}.py + C++ smoke_* / *_state.cpp Indicator values vs reference, OHLC/drawing/compare-volume rendering, lamp/tank/switch state machines, palette layout ~12 files
Indicator / drawing render tests tests/{indicator,candle,chart_pro}_render_test.cpp, tests/drawings_test.cpp, tests/chart_screenshot.cpp Offscreen render + pixel counts (up/down-coloured pixels prove the chart plots); 1024×768 screenshot 4 programs
Misc C++ tests tests/{widget,theme,font,event_handler_runtime,cmake_probe}_tests.cpp, tests/data/SPY_fake.csv (120 synthetic SPY minute bars) Widget/theme/font/event-handler/CMake behaviour 5 programs

Porting rule: port the tests before the code they cover, in Rust (cargo test, headless under Xvfb where a display is needed). Golden outputs to preserve: generated C++ files in tests/out/ (keep a copy as fixtures — the Rust generator must reproduce them), indicator values on the seeded series in StockData.h (NaN positions included), screenshot pixel-diff thresholds from run_tests.py.

10. Module map (C++ → Rust)

Proposed Cargo workspace lightgui_rust (crate names provisional):

C++ module Rust crate / module Notes
src/model.h + src/props.h + src/events.h lightgui-core::{model, props, events} Pure data + validation; serde for .fdj; property/event tables as generated const tables
src/project_io.cpp lightgui-core::project_io serde_json, identical .fdj v1 schema
src/preferences.cpp + src/theme.cpp lightgui-core::{preferences, theme} Settings persistence; theme data
src/generator.cpp lightgui-gen Emit C++/GTK first (byte-identical target); Rust emitter later
src/cmake_build.cpp lightgui-gen::cmake_build std::process::Command wrapping cmake/make
src/codeview.cpp lightgui-designer::codeview Highlight/fold over generated text; keep algorithm, re-skin in gtk-rs
src/debugger.cpp lightgui-debug::{session, mi} Command + pipes + MI parser; highest-risk hand port
src/debugger_ui.cpp lightgui-designer::debugger_ui gtk-rs window on top of lightgui-debug
src/main.cpp + ui/designer.ui lightgui-designer (binary lightgui) gtk-rs 0.18 (GTK 3), reuse designer.ui via Builder; canvas/inspector/bulk ops/rebuilders
src/xframe_palette.h lightgui-core::xframe_palette (generated) Generated from section data by build.rs / codegen
src/indicators.h xframe-indicators Pure functions; de-duplicate sma/ema/wilder/stddev; registry of 250 modules
src/drawings.h xframe-indicators::drawings (or xframe-drawings) Drawing enum, parse_spec, data→pixel Map
widgets/core/xframe_core.h xframe-core::{style, draw, canvas} x11rb backend; SStyle/SStyle_Manager; draw_polished etc.
widgets/components/StockData.h xframe-indicators::data OHLCV, seeded xorshift64* series (bit-identical output required)
widgets/components/InstData.h xframe-widgets::inst_data Clamps, alarm bands, switch/lamp state
widgets/components/<Name>.h (547) xframe-widgets::{gtk, t, ind, stock, inst} + Widget trait Trait + archetype impls + codegen; NOT 547 hand files
widgets/components/main_<Name>.cpp (547) xframe-demo (one binary) Generic runner: xframe-demo <Name>; driven by registry
widgets/common/registry.h xframe-widgets::registry (generated) WidgetKind enum + create() factory + default sizes
widgets/common/ico.h xframe-core::ico BMP ICO decoder (port, ~100 lines)
widgets/common/ipc.h xframe-core::ipc Selection/state files, same paths + env vars
widgets/palette/main_palette.cpp xframe-palette (binary) X11 palette window
widgets/layout/main_layout.cpp xframe-layout (binary) X11 layout window
widgets/tools/*.py + tools/*.py lightgui-tools (Rust codegen) + keep Python glyph tools until ported Registry/palette/icon generation; glyph scripts last
tests/* tests/ in each crate + workspace integration tests Port per §9; Xvfb-gated tests marked #[ignore]-free but run under xvfb-run -a cargo test

Suggested external crates (verify availability first, §0): gtk 0.18 (GTK 3) + gdk + glib, x11rb, serde/serde_json, clap, anyhow/thiserror. Avoid relm / GTK 4 — the .ui file and the generated code are GTK 3, and Glade has no GTK 4 target.

11. Order of work

  1. Probe (blocking): cargo new probe + gtk/x11rb/serde dependencies; cargo build on hot_newyork. If crates.io is blocked, resolve vendoring/offline mirror before anything else.
  2. Core data crates: lightgui-core (model/props/events/project_io)
    • registry codegen from sections.py data. Port .fdj round-trip tests first; existing .fdj fixtures must load identically.
  3. xframe-core: styles + draw primitives on x11rb, verified by pixel-diff against C++ demos under Xvfb (start with GtkButton).
  4. Generic demo runner + trait: xframe-demo + Widget trait; port one archetype end-to-end (button-like), then batch the rest by archetype with the run_tests.py pixel-diff oracle.
  5. xframe-indicators: pure-function port with numeric golden tests (seeded series; NaN warm-up positions are part of the contract). drawings + StockChart rendering next; XSpreadsheet/XGraph last (largest, most stateful).
  6. lightgui-gen: reproduce C++ output byte-identically; gate on the 21-check run matrix (16 gen cases + 5 render checks) with generated output diffed against tests/out/ fixtures.
  7. lightgui-designer: gtk-rs shell reusing designer.ui; canvas, inspector, bulk ops, rebuilders; gate on LIGHTGUI_SELFTEST equivalent
    • palette self-test (583).
  8. lightgui-debug: MI parser + session; gate on the 46-check harness (port dbg_harness.cpp to Rust, same targets).
  9. Palette/layout apps + seam converter + tools: port ipc, palette, layout, layout_to_lightgui.py; glyph/icon generators last.
  10. Publish: article to lightgui.com only after the workspace builds clean (cargo clippy, zero warnings, like the C++ -Wall -Wextra rule) and the ported suites pass.

12. Risks

  1. Crate availability — crates.io HEAD returned 403; gtk-rs 0.18 is GTK-3-only and lightly maintained. Mitigation: probe first; fallback to vendored sources or direct gtk-sys FFI.
  2. Pixel fidelity — X11 draw_polished (arcs + rects) and font metrics (XTextWidth, ascent/descent) must match the C++ demos pixel-for-pixel or the screenshot-diff tests fail. Mitigation: golden screenshots from the C++ demos before porting each archetype.
  3. NaN / warm-up semantics — indicator outputs are length-preserving with leading NaNs; any off-by-one changes every downstream indicator. Mitigation: numeric golden tests on the seeded series, NaN positions asserted explicitly.
  4. 775k lines, mostly template — hand-translating is infeasible and unnecessary. Mitigation: archetype classification + codegen from the C++ headers; treat the C++ headers as the spec.
  5. GDB/MI edge cases — the MI parser handles gdb 13 quirks (plain value lines, logpoint dprintf without trailing newline). Mitigation: port the harness first; do not rewrite the parser from the spec.
  6. Two runtimes, one binary story — the designer (GTK) and the widgets (X11) must not be conflated; the combined palette is the only bridge. Mitigation: separate crates with a narrow IPC boundary (same files/env vars as ipc.h).
  7. Generated-code compatibility — users' existing generated C++ projects and .fdj files must keep working. Mitigation: byte-identical generator output as the Phase-5 gate; .fdj v1 schema frozen.
  8. Scope creep into the live blogs — out of scope. This repo touches no Ghost/NPM/mailserver/GoAccess state (per task instruction).

13. Decisions needed from the user (do not assume)

  1. Generated-code target: keep emitting C++/GTK (recommended first) or switch the generator to emit Rust/gtk-rs?
  2. Designer toolkit: gtk-rs 0.18 (GTK 3, reuses designer.ui) — assumed; confirm no GTK 4 move.
  3. Widget backend: x11rb (recommended) vs raw Xlib FFI vs a Cairo-based redraw — affects pixel fidelity work.
  4. Should the Python tooling (gen_registry.py, glyph generators) stay Python, or be fully ported to Rust codegen?
  5. Publish gate: is the lightgui.com article wanted after Phase 5 (generator parity) or only after the full designer parity (Phase 6+)?