Phase 3: root Inspector window rows + SELFTEST Phase 7c + gen_matrix Phase 3 enum cases

This commit is contained in:
cnmcdee committed 2026-11-30 11:57:57 +00:00
1 parent 5135985b93
commit 31e180c2b2
2 files changed
+389

No files matched your search

+358
View File
@@ -1909,6 +1909,9 @@ static void on_xframe_enum_changed(GtkComboBoxText*, gpointer binding);
static void on_xframe_event_toggled(GtkToggleButton*, gpointer binding);
static void on_win_entry_changed(GtkEntry*, gpointer which);
static void on_win_spin_changed(GtkSpinButton*, gpointer which);
static void on_win_combo_changed(GtkComboBoxText*, gpointer which);
static GtkWidget* make_win_enum(const char* labels, int active,
const char* which);
static void on_edit_menus_clicked(GtkButton*, gpointer);
static void on_win_bg_pick_clicked(GtkButton*, gpointer entry_ptr);
@@ -2256,6 +2259,24 @@ static void refresh_props() {
g_signal_connect(menus, "clicked",
G_CALLBACK(on_edit_menus_clicked), nullptr);
add_row(row++, "menu bar", menus);
// Phase 3 (§2.20): window-level props (stored on g_project,
// emitted by the generator for the root window).
GtkWidget* bs = make_win_enum("Default|None|Single|Dialog",
g_project.border_style, "border-style");
add_row(row++, "border-style", bs);
GtkWidget* ic = gtk_entry_new();
gtk_entry_set_text(GTK_ENTRY(ic), g_project.icon.c_str());
g_signal_connect(ic, "changed", G_CALLBACK(on_win_entry_changed),
(gpointer) "icon");
add_row(row++, "icon", ic);
GtkWidget* wp = make_win_enum(
"Default|Center|ScreenCenter|MainFormCenter|Designed",
g_project.position, "position");
add_row(row++, "position", wp);
GtkWidget* ws = make_win_enum(
"Normal|Minimized|Maximized|Fullscreen",
g_project.window_state, "window-state");
add_row(row++, "window-state", ws);
// Border for XFrame widgets placed from here (the layout
// window). Applies to widgets placed after it is set; the
// designer widgets' own border is on each widget's properties.
@@ -2939,6 +2960,7 @@ static void on_win_entry_changed(GtkEntry* e, gpointer which) {
if (std::strcmp(w, "title") == 0) set_project_title(text);
if (std::strcmp(w, "class") == 0) set_project_class(text);
if (std::strcmp(w, "background") == 0) set_project_background(text);
if (std::strcmp(w, "icon") == 0) g_project.icon = text;
if (std::strcmp(w, "xframe-border-color") == 0) {
GdkRGBA rgba;
if (gdk_rgba_parse(&rgba, text)) {
@@ -2951,6 +2973,38 @@ static void on_win_entry_changed(GtkEntry* e, gpointer which) {
}
}
// Phase 3 (§2.20): enum combo for the root window rows.
static void on_win_combo_changed(GtkComboBoxText* c, gpointer which) {
if (g_syncing_props) return;
int v = gtk_combo_box_get_active(GTK_COMBO_BOX(c));
if (v < 0) return;
const char* w = (const char*)which;
if (std::strcmp(w, "border-style") == 0) g_project.border_style = v;
if (std::strcmp(w, "position") == 0) g_project.position = v;
if (std::strcmp(w, "window-state") == 0) g_project.window_state = v;
}
static GtkWidget* make_win_enum(const char* labels, int active,
const char* which) {
GtkWidget* c = gtk_combo_box_text_new();
std::string lab = labels;
size_t pos = 0;
int idx = 0;
while (true) {
size_t bar = lab.find('|', pos);
std::string one =
lab.substr(pos, bar == std::string::npos ? bar : bar - pos);
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(c), one.c_str());
if (bar == std::string::npos) break;
pos = bar + 1;
++idx;
}
gtk_combo_box_set_active(GTK_COMBO_BOX(c), active);
g_signal_connect(c, "changed", G_CALLBACK(on_win_combo_changed),
(gpointer)which);
return c;
}
static void on_win_spin_changed(GtkSpinButton* s, gpointer which) {
if (g_syncing_props) return;
int v = gtk_spin_button_get_value_as_int(s);
@@ -5286,6 +5340,310 @@ static gboolean selftest_step(gpointer) {
}
// Phase 7c: Proposal Phase 3 — containers + remaining families
// (§2.11–§2.22) and the six inventoried widgets (§2.19): place one
// widget of each type, live-apply props through the Inspector path
// (xframe_canvas_apply_prop), check the stored model, and verify the
// generated code carries the new setters.
{
auto place_p3 = [](const char* cls, int x, int y) {
int idx = -1;
for (int i = 0; i < kXFramePaletteCount; ++i)
if (std::strcmp(kXFramePalette[i].name, cls) == 0) {
idx = kXFramePalette[i].index;
break;
}
if (idx < 0) return -1;
return xframe_canvas_place(idx, x, y, 0, 0);
};
auto stored3 = [](int id, const char* name) {
for (const XFramePlacedInfo& info : xframe_canvas_placed())
if (info.id == id) {
auto it = info.props.find(name);
return it == info.props.end() ? std::string()
: it->second;
}
return std::string("\x01missing");
};
int gx3 = 10, gy3 = 10;
auto next_xy3 = [&]() {
int x = gx3, y = gy3;
gx3 += 190;
if (gx3 > 600) { gx3 = 10; gy3 += 130; }
return std::pair<int, int>(x, y);
};
// Frame / GroupBox / Panel (§2.11).
int pfrm = -1;
{
auto xy = next_xy3();
pfrm = place_p3("GtkFrame", xy.first, xy.second);
}
check(pfrm > 0);
check(xframe_canvas_apply_prop(pfrm, "label-xalign", "0.5"));
check(stored3(pfrm, "label-xalign") == "0.5");
check(xframe_canvas_apply_prop(pfrm, "inset", "12"));
check(xframe_canvas_apply_prop(pfrm, "top-inset", "20"));
// Image (§2.12).
int pimg = -1;
{
auto xy = next_xy3();
pimg = place_p3("GtkImage", xy.first, xy.second);
}
check(pimg > 0);
check(xframe_canvas_apply_prop(pimg, "stretch", "true"));
check(xframe_canvas_apply_prop(pimg, "proportional", "false"));
check(xframe_canvas_apply_prop(pimg, "center", "false"));
check(xframe_canvas_apply_prop(pimg, "transparent", "true"));
check(xframe_canvas_apply_prop(pimg, "pixel-size", "48"));
// ProgressBar (§2.13).
int ppb = -1;
{
auto xy = next_xy3();
ppb = place_p3("GtkProgressBar", xy.first, xy.second);
}
check(ppb > 0);
check(xframe_canvas_apply_prop(ppb, "minimum", "10"));
check(xframe_canvas_apply_prop(ppb, "maximum", "90"));
check(xframe_canvas_apply_prop(ppb, "position", "60"));
check(stored3(ppb, "position") == "60");
check(xframe_canvas_apply_prop(ppb, "step", "5"));
check(xframe_canvas_apply_prop(ppb, "show-text", "true"));
check(xframe_canvas_apply_prop(ppb, "pulsing", "true"));
check(xframe_canvas_apply_prop(ppb, "inverted", "true"));
check(xframe_canvas_apply_prop(ppb, "bar-color", "#336699"));
check(xframe_canvas_apply_prop(ppb, "trough-color", "#336699"));
// SpinEdit (§2.14).
int pspin = -1;
{
auto xy = next_xy3();
pspin = place_p3("GtkSpinButton", xy.first, xy.second);
}
check(pspin > 0);
check(xframe_canvas_apply_prop(pspin, "editor-enabled", "false"));
check(stored3(pspin, "editor-enabled") == "false");
// Calendar / DateTimePicker (§2.15).
int pcal = -1;
{
auto xy = next_xy3();
pcal = place_p3("GtkCalendar", xy.first, xy.second);
}
check(pcal > 0);
check(xframe_canvas_apply_prop(pcal, "date", "2026-11-30"));
check(stored3(pcal, "date") == "2026-11-30");
check(xframe_canvas_apply_prop(pcal, "show-week-numbers", "true"));
check(xframe_canvas_apply_prop(pcal, "grid-color", "#336699"));
// Colour picker (§2.16).
int pcol = -1;
{
auto xy = next_xy3();
pcol = place_p3("GtkColorButton", xy.first, xy.second);
}
check(pcol > 0);
check(xframe_canvas_apply_prop(pcol, "style", "2"));
check(xframe_canvas_apply_prop(pcol, "default-color", "#336699"));
check(xframe_canvas_apply_prop(pcol, "none-color", "#336699"));
// ListView (§2.17).
int plv = -1;
{
auto xy = next_xy3();
plv = place_p3("GtkListView", xy.first, xy.second);
}
check(plv > 0);
check(xframe_canvas_apply_prop(plv, "items", "A;B"));
check(xframe_canvas_apply_prop(plv, "item-index", "1"));
check(xframe_canvas_apply_prop(plv, "item-height", "30"));
check(xframe_canvas_apply_prop(plv, "view-style", "1"));
check(xframe_canvas_apply_prop(plv, "grid-lines", "true"));
check(xframe_canvas_apply_prop(plv, "row-select", "false"));
check(xframe_canvas_apply_prop(plv, "multi-select", "true"));
check(xframe_canvas_apply_prop(plv, "sort-type", "1"));
// TreeView (§2.17).
int ptv = -1;
{
auto xy = next_xy3();
ptv = place_p3("GtkTreeView", xy.first, xy.second);
}
check(ptv > 0);
check(xframe_canvas_apply_prop(ptv, "items", "Root/Child"));
check(xframe_canvas_apply_prop(ptv, "headers-visible", "false"));
check(xframe_canvas_apply_prop(ptv, "header-height", "30"));
check(xframe_canvas_apply_prop(ptv, "indent", "24"));
check(xframe_canvas_apply_prop(ptv, "show-buttons", "false"));
check(xframe_canvas_apply_prop(ptv, "show-lines", "false"));
check(xframe_canvas_apply_prop(ptv, "show-root", "false"));
check(xframe_canvas_apply_prop(ptv, "sort-type", "2"));
check(xframe_canvas_apply_prop(ptv, "grid-lines", "true"));
// Notebook (§2.18).
int pnb = -1;
{
auto xy = next_xy3();
pnb = place_p3("GtkNotebook", xy.first, xy.second);
}
check(pnb > 0);
check(xframe_canvas_apply_prop(pnb, "pages", "One|Two"));
check(xframe_canvas_apply_prop(pnb, "page", "1"));
check(xframe_canvas_apply_prop(pnb, "tab-height", "32"));
check(xframe_canvas_apply_prop(pnb, "tab-position", "1"));
check(xframe_canvas_apply_prop(pnb, "tab-width", "80"));
// ToggleButton / SpeedButton (§2.21).
int ptb = -1;
{
auto xy = next_xy3();
ptb = place_p3("GtkToggleButton", xy.first, xy.second);
}
check(ptb > 0);
check(xframe_canvas_apply_prop(ptb, "active", "true"));
check(xframe_canvas_apply_prop(ptb, "group-index", "2"));
check(xframe_canvas_apply_prop(ptb, "allow-all-up", "true"));
check(xframe_canvas_apply_prop(ptb, "flat", "true"));
// Splitter (§2.19).
int psp = -1;
{
auto xy = next_xy3();
psp = place_p3("GtkPaned", xy.first, xy.second);
}
check(psp > 0);
check(xframe_canvas_apply_prop(psp, "position", "150"));
check(xframe_canvas_apply_prop(psp, "orientation", "1"));
check(xframe_canvas_apply_prop(psp, "min-size", "60"));
check(xframe_canvas_apply_prop(psp, "resize-style", "1"));
check(xframe_canvas_apply_prop(psp, "auto-snap", "true"));
// StatusBar (§2.19).
int psb = -1;
{
auto xy = next_xy3();
psb = place_p3("GtkStatusbar", xy.first, xy.second);
}
check(psb > 0);
check(xframe_canvas_apply_prop(psb, "panels", "A|B"));
check(stored3(psb, "panels") == "A|B");
check(xframe_canvas_apply_prop(psb, "size-grip", "false"));
// ToolBar (§2.19).
int ptl = -1;
{
auto xy = next_xy3();
ptl = place_p3("GtkToolbar", xy.first, xy.second);
}
check(ptl > 0);
check(xframe_canvas_apply_prop(ptl, "items", "New|Open"));
check(xframe_canvas_apply_prop(ptl, "show-captions", "false"));
check(xframe_canvas_apply_prop(ptl, "flat", "true"));
check(xframe_canvas_apply_prop(ptl, "button-width", "60"));
check(xframe_canvas_apply_prop(ptl, "button-height", "40"));
// MenuBar (§2.19).
int pmb = -1;
{
auto xy = next_xy3();
pmb = place_p3("GtkMenuBar", xy.first, xy.second);
}
check(pmb > 0);
check(xframe_canvas_apply_prop(pmb, "menus", "File|Edit"));
// Shape (§2.19).
int psh = -1;
{
auto xy = next_xy3();
psh = place_p3("TShape", xy.first, xy.second);
}
check(psh > 0);
check(xframe_canvas_apply_prop(psh, "shape", "6"));
check(xframe_canvas_apply_prop(psh, "fill-color", "#336699"));
check(xframe_canvas_apply_prop(psh, "pen-color", "#336699"));
check(xframe_canvas_apply_prop(psh, "pen-width", "5"));
// StringGrid / Spreadsheet (§2.19).
int psg = -1;
{
auto xy = next_xy3();
psg = place_p3("XSpreadsheet", xy.first, xy.second);
}
check(psg > 0);
check(xframe_canvas_apply_prop(psg, "rows", "3"));
check(xframe_canvas_apply_prop(psg, "columns", "2"));
check(xframe_canvas_apply_prop(psg, "fixed-cols", "1"));
check(xframe_canvas_apply_prop(psg, "fixed-rows", "1"));
check(xframe_canvas_apply_prop(psg, "default-col-width", "100"));
check(xframe_canvas_apply_prop(psg, "default-row-height", "30"));
check(xframe_canvas_apply_prop(psg, "grid-line-width", "2"));
// Generate and check the setters are emitted.
Project snap3 = snapshot_project();
GenResult gr3 = generate_project(snap3, snap3.widgets,
"/tmp/lightgui_gen_test_p3");
check(gr3.ok && gr3.files.size() == 4);
auto read_file_p3 = [](const std::string& path) {
gchar* t = nullptr;
if (!g_file_get_contents(path.c_str(), &t, nullptr, nullptr) ||
!t)
return std::string();
std::string s3 = t;
g_free(t);
return s3;
};
std::string code3 = read_file_p3("/tmp/lightgui_gen_test_p3/main.cpp");
check(!code3.empty());
check(code3.find("set_label_xalign(0.5)") != std::string::npos);
check(code3.find("set_inset(12)") != std::string::npos);
check(code3.find("set_top_inset(20)") != std::string::npos);
check(code3.find("set_stretch(true)") != std::string::npos);
check(code3.find("set_proportional(false)") != std::string::npos);
check(code3.find("set_pixel_size(48)") != std::string::npos);
check(code3.find("set_min(10") != std::string::npos);
check(code3.find("set_max(90") != std::string::npos);
check(code3.find("set_position(60") != std::string::npos);
check(code3.find("set_step(5") != std::string::npos);
check(code3.find("set_show_text(true)") != std::string::npos);
check(code3.find("set_pulsing(true)") != std::string::npos);
check(code3.find("set_inverted(true)") != std::string::npos);
check(code3.find("set_bar_color_rgb(51, 102, 153)") !=
std::string::npos);
check(code3.find("set_editable(false)") != std::string::npos);
check(code3.find("set_date(2026, 11, 30)") != std::string::npos);
check(code3.find("set_show_week_numbers(true)") !=
std::string::npos);
check(code3.find("set_grid_color_rgb(51, 102, 153)") !=
std::string::npos);
check(code3.find("set_style(2)") != std::string::npos);
check(code3.find("set_default_color_rgb(51, 102, 153)") !=
std::string::npos);
check(code3.find("add_item(\"A\")") != std::string::npos);
check(code3.find("set_selected_row(1)") != std::string::npos);
check(code3.find("set_view_style(1)") != std::string::npos);
check(code3.find("set_grid_lines(true)") != std::string::npos);
check(code3.find("set_sort_type(1)") != std::string::npos);
check(code3.find("set_headers_visible(false)") !=
std::string::npos);
check(code3.find("set_header_height(30)") != std::string::npos);
check(code3.find("set_indent(24)") != std::string::npos);
check(code3.find("append_page(\"One\")") != std::string::npos);
check(code3.find("set_current_page(1)") != std::string::npos);
check(code3.find("set_tab_height(32)") != std::string::npos);
check(code3.find("set_tab_position(1)") != std::string::npos);
check(code3.find("set_tab_width(80)") != std::string::npos);
check(code3.find("set_group_index(2)") != std::string::npos);
check(code3.find("set_allow_all_up(true)") != std::string::npos);
check(code3.find("set_position(150)") != std::string::npos);
check(code3.find("set_orientation(1)") != std::string::npos);
check(code3.find("set_min_size(60)") != std::string::npos);
check(code3.find("set_resize_style(1)") != std::string::npos);
check(code3.find("set_auto_snap(true)") != std::string::npos);
check(code3.find("set_items(\"A|B\")") != std::string::npos);
check(code3.find("set_show_captions(false)") != std::string::npos);
check(code3.find("set_button_width(60)") != std::string::npos);
check(code3.find("set_button_height(40)") != std::string::npos);
check(code3.find("set_shape(6)") != std::string::npos);
check(code3.find("set_fill_color(Srgb{51, 102, 153})") !=
std::string::npos);
check(code3.find("set_pen_color(Srgb{51, 102, 153})") !=
std::string::npos);
check(code3.find("set_pen_width(5)") != std::string::npos);
check(code3.find("set_size(2, 3)") != std::string::npos);
check(code3.find("set_frozen_cols(1)") != std::string::npos);
check(code3.find("set_frozen_rows(1)") != std::string::npos);
check(code3.find("set_default_col_width(100)") !=
std::string::npos);
check(code3.find("set_row_height(30)") != std::string::npos);
check(code3.find("set_grid_line_width(2)") != std::string::npos);
std::printf("GENERATED_P3 /tmp/lightgui_gen_test_p3\n");
}
// Phase 8: event handlers — connect every natural signal on every
// widget on the canvas, generate, and check the emitted code carries
// a stub handler + a std::function wiring line for each; types with no natural
+31
View File
@@ -185,6 +185,37 @@ int main(int argc, char** argv) {
for (int v = 0; v <= 3; ++v)
add("TrackBar", "Trk_ticks_" + std::to_string(v), "tick-marks",
std::to_string(v));
// Phase 3 enums: every value of every new enum prop.
for (int v = 0; v <= 3; ++v)
add("ListView", "Lst_view_" + std::to_string(v), "view-style",
std::to_string(v));
for (int v = 0; v <= 2; ++v)
add("ListView", "Lst_sort_" + std::to_string(v), "sort-type",
std::to_string(v));
for (int v = 0; v <= 2; ++v)
add("TreeView", "Tre_sort_" + std::to_string(v), "sort-type",
std::to_string(v));
for (int v = 0; v <= 3; ++v)
add("Notebook", "Nbk_pos_" + std::to_string(v), "tab-position",
std::to_string(v));
for (int v = 0; v <= 1; ++v)
add("Splitter", "Spl_rs_" + std::to_string(v), "resize-style",
std::to_string(v));
for (int v = 0; v <= 3; ++v)
add("ColorBox", "Clr_style_" + std::to_string(v), "style",
std::to_string(v));
for (int v = 0; v <= 9; ++v)
add("Shape", "Shp_shape_" + std::to_string(v), "shape",
std::to_string(v));
for (int v = 0; v <= 3; ++v)
add("Toplevel", "Top_border_" + std::to_string(v),
"border-style", std::to_string(v));
for (int v = 0; v <= 4; ++v)
add("Toplevel", "Top_pos_" + std::to_string(v), "position",
std::to_string(v));
for (int v = 0; v <= 3; ++v)
add("Toplevel", "Top_state_" + std::to_string(v),
"window-state", std::to_string(v));
emit("04_enum_values", p);
}