Phase 2 per-widget props (C): Inspector tables for Button/Entry/Label/CheckBox/RadioButton/ComboBox/ListBox/ScrollBar/Scale/TrackBar/Text/Memo + CheckListBox; live-apply in xframe_core_apply_prop (kind syncs label/modal-result, active syncs ComboBox text only, integral-height snap, scale marks from tick-marks/frequency); generator emits all new setters incl. radio_group vectors, CheckListBox branch, scale marks
This commit is contained in:
1 parent
5c10871d15
commit
5ffcc269c6
3 files changed
+483
-2
No files matched your search
@@ -286,6 +286,7 @@ static const XFrameMap kXFrameMap[] = {
|
||||
{"Frame", "GtkFrame", "", "", false, false},
|
||||
{"Combobox", "GtkComboBoxText", "", "", false, false},
|
||||
{"Listbox", "GtkListBox", "set_frame_background_color_rgb", "", false, false},
|
||||
{"CheckListBox", "TCheckListBox", "", "", false, false},
|
||||
{"Menubutton", "GtkMenuButton", "", "", false, false},
|
||||
{"Canvas", "GtkDrawingArea", "", "", false, false},
|
||||
{"Scale", "GtkScale", "", "", false, false},
|
||||
@@ -490,6 +491,26 @@ static std::string tree_node_expr(const std::vector<std::string>& segs,
|
||||
return o.str();
|
||||
}
|
||||
|
||||
// Emit set_marks({v, v, ...}) for a Scale/TrackBar from tick-marks +
|
||||
// frequency over [mn, mx] (mirrors refresh_scale_marks in the canvas).
|
||||
static void emit_scale_marks(std::ostringstream& o, const Widget& w,
|
||||
const std::string& var, double mn, double mx) {
|
||||
if (prop_int(w, "tick-marks", 0) == 0) return;
|
||||
int freq = prop_int(w, "frequency", 10);
|
||||
if (freq <= 0 || mx <= mn) return;
|
||||
std::vector<double> marks;
|
||||
for (double v = mn; v <= mx; v += freq) marks.push_back(v);
|
||||
if (marks.empty() || marks.back() != mx) marks.push_back(mx);
|
||||
o << " " << var << ".w.set_marks({";
|
||||
bool first = true;
|
||||
for (double v : marks) {
|
||||
if (!first) o << ", ";
|
||||
first = false;
|
||||
o << fmt_double(std::to_string(v));
|
||||
}
|
||||
o << "});\n";
|
||||
}
|
||||
|
||||
static void emit_widget_props(std::ostringstream& o, const Widget& w,
|
||||
const XFrameMap& m, const std::string& var) {
|
||||
// Fix 6: snapshot projects carry the XFrame class name; the branches
|
||||
@@ -532,6 +553,27 @@ static void emit_widget_props(std::ostringstream& o, const Widget& w,
|
||||
o << " " << var << ".w.set_selectable("
|
||||
<< (prop_bool(w, "selectable", false) ? "true" : "false")
|
||||
<< ");\n";
|
||||
if (w.props.count("transparent"))
|
||||
o << " " << var << ".w.set_transparent("
|
||||
<< (prop_bool(w, "transparent", false) ? "true" : "false")
|
||||
<< ");\n";
|
||||
if (w.props.count("show-accel-char") &&
|
||||
!prop_bool(w, "show-accel-char", true))
|
||||
o << " " << var << ".w.set_show_accel_char(false);\n";
|
||||
} else if (t == "Button") {
|
||||
if (prop_bool(w, "default", false))
|
||||
o << " " << var << ".w.set_default(true);\n";
|
||||
if (prop_bool(w, "cancel", false))
|
||||
o << " " << var << ".w.set_cancel(true);\n";
|
||||
if (w.props.count("kind") && prop_int(w, "kind", 0) != 0)
|
||||
o << " " << var << ".w.set_kind(" << prop_int(w, "kind", 0)
|
||||
<< ");\n";
|
||||
if (w.props.count("modal-result") && prop_int(w, "modal-result", 0) != 0)
|
||||
o << " " << var << ".w.set_modal_result("
|
||||
<< prop_int(w, "modal-result", 0) << ");\n";
|
||||
if (w.props.count("layout") && prop_int(w, "layout", 0) != 0)
|
||||
o << " " << var << ".w.set_layout(" << prop_int(w, "layout", 0)
|
||||
<< ");\n";
|
||||
} else if (t == "Entry") {
|
||||
if (has("placeholder-text"))
|
||||
o << " " << var << ".w.set_placeholder_text(\""
|
||||
@@ -553,7 +595,21 @@ static void emit_widget_props(std::ostringstream& o, const Widget& w,
|
||||
o << " " << var << ".w.set_password(true);\n";
|
||||
if (prop_bool(w, "show-password", false))
|
||||
o << " " << var << ".w.set_show_password(true);\n";
|
||||
if (w.props.count("alignment") && prop_int(w, "alignment", 0) != 0)
|
||||
o << " " << var << ".w.set_alignment("
|
||||
<< prop_int(w, "alignment", 0) << ");\n";
|
||||
if (w.props.count("char-case") && prop_int(w, "char-case", 0) != 0)
|
||||
o << " " << var << ".w.set_char_case("
|
||||
<< prop_int(w, "char-case", 0) << ");\n";
|
||||
if (prop_bool(w, "numbers-only", false))
|
||||
o << " " << var << ".w.set_numbers_only(true);\n";
|
||||
if (prop_bool(w, "hide-selection", false))
|
||||
o << " " << var << ".w.set_hide_selection(true);\n";
|
||||
if (prop_bool(w, "auto-select", false))
|
||||
o << " " << var << ".w.set_auto_select(true);\n";
|
||||
} else if (t == "Checkbutton") {
|
||||
if (prop_bool(w, "allow-grayed", false))
|
||||
o << " " << var << ".w.set_allow_grayed(true);\n";
|
||||
if (w.props.count("active"))
|
||||
o << " " << var << ".w.set_active("
|
||||
<< (prop_bool(w, "active", false) ? "true" : "false") << ");\n";
|
||||
@@ -561,7 +617,21 @@ static void emit_widget_props(std::ostringstream& o, const Widget& w,
|
||||
o << " " << var << ".w.set_inconsistent("
|
||||
<< (prop_bool(w, "inconsistent", false) ? "true" : "false")
|
||||
<< ");\n";
|
||||
if (w.props.count("alignment") && prop_int(w, "alignment", 0) != 0)
|
||||
o << " " << var << ".w.set_alignment(1);\n";
|
||||
if (has("value-checked"))
|
||||
o << " " << var << ".w.set_value_checked(\""
|
||||
<< esc_c(prop_or(w, "value-checked", "")) << "\");\n";
|
||||
if (has("value-unchecked"))
|
||||
o << " " << var << ".w.set_value_unchecked(\""
|
||||
<< esc_c(prop_or(w, "value-unchecked", "")) << "\");\n";
|
||||
} else if (t == "Radiobutton") {
|
||||
int grp = prop_int(w, "group", 0);
|
||||
if (grp != 0) {
|
||||
o << " " << var << ".w.set_group_id(" << grp << ");\n";
|
||||
o << " " << var << ".w.set_group(&radio_group_" << grp
|
||||
<< ");\n";
|
||||
}
|
||||
if (w.props.count("active"))
|
||||
o << " " << var << ".w.set_active("
|
||||
<< (prop_bool(w, "active", false) ? "true" : "false") << ");\n";
|
||||
@@ -573,6 +643,29 @@ static void emit_widget_props(std::ostringstream& o, const Widget& w,
|
||||
if (w.props.count("active"))
|
||||
o << " " << var << ".w.set_active("
|
||||
<< prop_int(w, "active", 0) << ");\n";
|
||||
if (w.props.count("style") && prop_int(w, "style", 0) != 0)
|
||||
o << " " << var << ".w.set_style(" << prop_int(w, "style", 0)
|
||||
<< ");\n";
|
||||
if (w.props.count("drop-down-count") &&
|
||||
prop_int(w, "drop-down-count", 8) != 8)
|
||||
o << " " << var << ".w.set_drop_down_count("
|
||||
<< prop_int(w, "drop-down-count", 8) << ");\n";
|
||||
if (w.props.count("drop-down-width") &&
|
||||
prop_int(w, "drop-down-width", 0) != 0)
|
||||
o << " " << var << ".w.set_drop_down_width("
|
||||
<< prop_int(w, "drop-down-width", 0) << ");\n";
|
||||
if (prop_bool(w, "sorted", false))
|
||||
o << " " << var << ".w.set_sorted(true);\n";
|
||||
if (prop_bool(w, "read-only", false))
|
||||
o << " " << var << ".w.set_read_only(true);\n";
|
||||
if (w.props.count("max-length") && prop_int(w, "max-length", 0) != 0)
|
||||
o << " " << var << ".w.set_max_length("
|
||||
<< prop_int(w, "max-length", 0) << ");\n";
|
||||
if (prop_bool(w, "auto-complete", false))
|
||||
o << " " << var << ".w.set_auto_complete(true);\n";
|
||||
if (w.props.count("char-case") && prop_int(w, "char-case", 0) != 0)
|
||||
o << " " << var << ".w.set_char_case("
|
||||
<< prop_int(w, "char-case", 0) << ");\n";
|
||||
} else if (t == "Listbox") {
|
||||
if (has("items"))
|
||||
for (const std::string& item : split_on('|', prop_or(w, "items", "")))
|
||||
@@ -580,11 +673,39 @@ static void emit_widget_props(std::ostringstream& o, const Widget& w,
|
||||
if (w.props.count("selection-mode") &&
|
||||
prop_int(w, "selection-mode", 1) == 3)
|
||||
o << " " << var << ".w.set_multi_select(true);\n";
|
||||
if (w.props.count("item-index") && prop_int(w, "item-index", -1) >= 0)
|
||||
o << " " << var << ".w.set_selected_row("
|
||||
<< prop_int(w, "item-index", -1) << ");\n";
|
||||
if (prop_bool(w, "sorted", false))
|
||||
o << " " << var << ".w.set_sorted(true);\n";
|
||||
if (w.props.count("item-height") && prop_int(w, "item-height", 0) > 0)
|
||||
o << " " << var << ".w.set_row_height("
|
||||
<< prop_int(w, "item-height", 0) << ");\n";
|
||||
} else if (t == "CheckListBox") {
|
||||
if (has("items"))
|
||||
for (const std::string& item : split_on('|', prop_or(w, "items", "")))
|
||||
o << " " << var << ".w.add_item(\"" << esc_c(item)
|
||||
<< "\");\n";
|
||||
if (prop_bool(w, "sorted", false))
|
||||
o << " " << var << ".w.set_sorted(true);\n";
|
||||
if (has("checked-items"))
|
||||
o << " " << var << ".w.set_checked_items(\""
|
||||
<< esc_c(prop_or(w, "checked-items", "")) << "\");\n";
|
||||
if (w.props.count("item-index") && prop_int(w, "item-index", -1) >= 0)
|
||||
o << " " << var << ".w.set_selected_row("
|
||||
<< prop_int(w, "item-index", -1) << ");\n";
|
||||
if (w.props.count("item-height") && prop_int(w, "item-height", 0) > 0)
|
||||
o << " " << var << ".w.set_row_height("
|
||||
<< prop_int(w, "item-height", 0) << ");\n";
|
||||
} else if (t == "Menubutton") {
|
||||
if (w.props.count("direction") && prop_int(w, "direction", 1) != 1)
|
||||
o << " " << var << ".w.set_direction("
|
||||
<< prop_int(w, "direction", 1) << ");\n";
|
||||
} else if (t == "Scale") {
|
||||
if (w.props.count("minimum") || w.props.count("maximum"))
|
||||
o << " " << var << ".w.set_range("
|
||||
<< fmt_double(prop_or(w, "minimum", "0")) << ", "
|
||||
<< fmt_double(prop_or(w, "maximum", "100")) << ");\n";
|
||||
if (w.props.count("value"))
|
||||
o << " " << var << ".w.set_value("
|
||||
<< fmt_double(prop_or(w, "value", "0")) << ");\n";
|
||||
@@ -592,6 +713,23 @@ static void emit_widget_props(std::ostringstream& o, const Widget& w,
|
||||
o << " " << var << ".w.set_draw_value("
|
||||
<< (prop_bool(w, "draw-value", true) ? "true" : "false")
|
||||
<< ");\n";
|
||||
if (w.props.count("page-step") &&
|
||||
std::atof(prop_or(w, "page-step", "10").c_str()) != 10.0)
|
||||
o << " " << var << ".w.set_page_step("
|
||||
<< fmt_double(prop_or(w, "page-step", "10")) << ");\n";
|
||||
emit_scale_marks(o, w, var,
|
||||
std::atof(prop_or(w, "minimum", "0").c_str()),
|
||||
std::atof(prop_or(w, "maximum", "100").c_str()));
|
||||
if (prop_bool(w, "show-sel-range", false))
|
||||
o << " " << var << ".w.set_show_sel_range(true);\n";
|
||||
if (w.props.count("sel-start") &&
|
||||
std::atof(prop_or(w, "sel-start", "0").c_str()) != 0.0)
|
||||
o << " " << var << ".w.set_sel_start("
|
||||
<< fmt_double(prop_or(w, "sel-start", "0")) << ");\n";
|
||||
if (w.props.count("sel-end") &&
|
||||
std::atof(prop_or(w, "sel-end", "0").c_str()) != 0.0)
|
||||
o << " " << var << ".w.set_sel_end("
|
||||
<< fmt_double(prop_or(w, "sel-end", "0")) << ");\n";
|
||||
} else if (t == "Scrollbar") {
|
||||
if (w.props.count("lower") &&
|
||||
std::atof(prop_or(w, "lower", "0").c_str()) != 0.0)
|
||||
@@ -613,6 +751,12 @@ static void emit_widget_props(std::ostringstream& o, const Widget& w,
|
||||
if (w.props.count("value"))
|
||||
o << " " << var << ".w.set_value("
|
||||
<< fmt_double(prop_or(w, "value", "0")) << ");\n";
|
||||
if (w.props.count("orientation") && prop_int(w, "orientation", 0) != 0)
|
||||
o << " " << var << ".w.set_orientation_vertical(true);\n";
|
||||
if (w.props.count("large-change") &&
|
||||
std::atof(prop_or(w, "large-change", "10").c_str()) != 10.0)
|
||||
o << " " << var << ".w.set_page_increment("
|
||||
<< fmt_double(prop_or(w, "large-change", "10")) << ");\n";
|
||||
} else if (t == "Text") {
|
||||
if (w.props.count("editable"))
|
||||
o << " " << var << ".w.set_editable("
|
||||
@@ -625,7 +769,46 @@ static void emit_widget_props(std::ostringstream& o, const Widget& w,
|
||||
if (w.props.count("cursor-visible") &&
|
||||
!prop_bool(w, "cursor-visible", true))
|
||||
o << " " << var << ".w.set_cursor_visible(false);\n";
|
||||
if (w.props.count("max-length") && prop_int(w, "max-length", 0) != 0)
|
||||
o << " " << var << ".w.set_max_length("
|
||||
<< prop_int(w, "max-length", 0) << ");\n";
|
||||
if (w.props.count("scroll-bars") && prop_int(w, "scroll-bars", 0) != 0)
|
||||
o << " " << var << ".w.set_scroll_bars("
|
||||
<< prop_int(w, "scroll-bars", 0) << ");\n";
|
||||
if (w.props.count("want-tabs") && !prop_bool(w, "want-tabs", true))
|
||||
o << " " << var << ".w.set_want_tabs(false);\n";
|
||||
if (w.props.count("want-returns") &&
|
||||
!prop_bool(w, "want-returns", true))
|
||||
o << " " << var << ".w.set_want_returns(false);\n";
|
||||
if (prop_bool(w, "hide-selection", false))
|
||||
o << " " << var << ".w.set_hide_selection(true);\n";
|
||||
if (w.props.count("alignment") && prop_int(w, "alignment", 0) != 0)
|
||||
o << " " << var << ".w.set_alignment("
|
||||
<< prop_int(w, "alignment", 0) << ");\n";
|
||||
} else if (t == "Memo") {
|
||||
if (w.props.count("editable"))
|
||||
o << " " << var << ".w.set_editable("
|
||||
<< (prop_bool(w, "editable", true) ? "true" : "false")
|
||||
<< ");\n";
|
||||
if (w.props.count("cursor-visible") &&
|
||||
!prop_bool(w, "cursor-visible", true))
|
||||
o << " " << var << ".w.set_cursor_visible(false);\n";
|
||||
if (w.props.count("max-length") && prop_int(w, "max-length", 0) != 0)
|
||||
o << " " << var << ".w.set_max_length("
|
||||
<< prop_int(w, "max-length", 0) << ");\n";
|
||||
if (w.props.count("scroll-bars") && prop_int(w, "scroll-bars", 3) != 3)
|
||||
o << " " << var << ".w.set_scroll_bars("
|
||||
<< prop_int(w, "scroll-bars", 3) << ");\n";
|
||||
if (w.props.count("want-tabs") && !prop_bool(w, "want-tabs", true))
|
||||
o << " " << var << ".w.set_want_tabs(false);\n";
|
||||
if (w.props.count("want-returns") &&
|
||||
!prop_bool(w, "want-returns", true))
|
||||
o << " " << var << ".w.set_want_returns(false);\n";
|
||||
if (prop_bool(w, "hide-selection", false))
|
||||
o << " " << var << ".w.set_hide_selection(true);\n";
|
||||
if (w.props.count("alignment") && prop_int(w, "alignment", 0) != 0)
|
||||
o << " " << var << ".w.set_alignment("
|
||||
<< prop_int(w, "alignment", 0) << ");\n";
|
||||
if (w.props.count("wrap-mode"))
|
||||
o << " " << var << ".w.set_wordwrap("
|
||||
<< (prop_int(w, "wrap-mode", 0) != 0 ? "true" : "false")
|
||||
@@ -705,6 +888,22 @@ static void emit_widget_props(std::ostringstream& o, const Widget& w,
|
||||
o << " " << var << ".w.set_orientation_vertical("
|
||||
<< (prop_int(w, "orientation", 0) != 0 ? "true" : "false")
|
||||
<< ");\n";
|
||||
if (w.props.count("page-step") &&
|
||||
std::atof(prop_or(w, "page-step", "10").c_str()) != 10.0)
|
||||
o << " " << var << ".w.set_page_step("
|
||||
<< fmt_double(prop_or(w, "page-step", "10")) << ");\n";
|
||||
emit_scale_marks(o, w, var, prop_int(w, "minimum", 0),
|
||||
prop_int(w, "maximum", 100));
|
||||
if (prop_bool(w, "show-sel-range", false))
|
||||
o << " " << var << ".w.set_show_sel_range(true);\n";
|
||||
if (w.props.count("sel-start") &&
|
||||
std::atof(prop_or(w, "sel-start", "0").c_str()) != 0.0)
|
||||
o << " " << var << ".w.set_sel_start("
|
||||
<< fmt_double(prop_or(w, "sel-start", "0")) << ");\n";
|
||||
if (w.props.count("sel-end") &&
|
||||
std::atof(prop_or(w, "sel-end", "0").c_str()) != 0.0)
|
||||
o << " " << var << ".w.set_sel_end("
|
||||
<< fmt_double(prop_or(w, "sel-end", "0")) << ");\n";
|
||||
} else if (t == "ProgressBar") {
|
||||
if (w.props.count("fraction"))
|
||||
o << " " << var << ".w.set_fraction("
|
||||
@@ -869,6 +1068,17 @@ static void emit_widget_props(std::ostringstream& o, const Widget& w,
|
||||
notes.push_back("font-underline=true");
|
||||
if (prop_bool(w, "font-strikeout", false))
|
||||
notes.push_back("font-strikeout=true");
|
||||
if (has("glyph"))
|
||||
notes.push_back("glyph=\"" +
|
||||
esc_c(prop_or(w, "glyph", "")) + "\"");
|
||||
if (has("focus-control"))
|
||||
notes.push_back("focus-control=\"" +
|
||||
esc_c(prop_or(w, "focus-control", "")) + "\"");
|
||||
if (w.props.count("columns") && prop_int(w, "columns", 1) != 1)
|
||||
notes.push_back("columns=" +
|
||||
std::to_string(prop_int(w, "columns", 1)));
|
||||
if (prop_bool(w, "integral-height", false))
|
||||
notes.push_back("integral-height=true");
|
||||
if (!notes.empty()) {
|
||||
o << " // NOTE (model-only, no XFrame setter): ";
|
||||
for (size_t i = 0; i < notes.size(); ++i) {
|
||||
@@ -1410,6 +1620,25 @@ static std::string emit_main_cpp(const Project& project,
|
||||
<< " };\n";
|
||||
}
|
||||
|
||||
// RadioButton groups (Phase 2): one shared vector per group id;
|
||||
// each button in the group calls set_group on it, so turning one
|
||||
// on turns the others off (GtkRadioButton::set_active).
|
||||
{
|
||||
std::vector<int> groups;
|
||||
for (const Resolved& r : resolved) {
|
||||
std::string kind = xframe_type_key(r.w->type);
|
||||
if ((kind.empty() ? r.w->type : kind) == "Radiobutton") {
|
||||
int g = prop_int(*r.w, "group", 0);
|
||||
if (g != 0 &&
|
||||
std::find(groups.begin(), groups.end(), g) == groups.end())
|
||||
groups.push_back(g);
|
||||
}
|
||||
}
|
||||
for (int g : groups)
|
||||
o << " std::vector<GtkRadioButton*> radio_group_" << g
|
||||
<< ";\n";
|
||||
}
|
||||
|
||||
// Widgets, in design order (later = on top for event dispatch).
|
||||
for (const Resolved& r : resolved) {
|
||||
const Widget& w = *r.w;
|
||||
|
||||
+83
@@ -33,6 +33,13 @@ inline const int kOrientationValues[] = {0, 1}; // HORIZONTAL, VERTICAL
|
||||
inline const int kToolbarStyleValues[] = {0, 1, 2, 3}; // ICONS, TEXT, BOTH, BOTH_HORIZ
|
||||
inline const int kShapeValues[] = {0, 1, 2, 3}; // RECTANGLE, ELLIPSE, LINE, TRIANGLE
|
||||
inline const int kAlignValues[] = {0, 1, 2, 3, 4, 5}; // NONE, TOP, BOTTOM, LEFT, RIGHT, CLIENT
|
||||
inline const int kButtonKindValues[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; // NONE, OK, CANCEL, YES, NO, CLOSE, HELP, RETRY, IGNORE, ABORT
|
||||
inline const int kButtonLayoutValues[] = {0, 1, 2, 3}; // LEFT, RIGHT, TOP, BOTTOM
|
||||
inline const int kTextAlignValues[] = {0, 1, 2}; // LEFT, CENTER, RIGHT
|
||||
inline const int kCharCaseValues[] = {0, 1, 2}; // NORMAL, UPPER, LOWER
|
||||
inline const int kComboStyleValues[] = {0, 1, 2}; // DROPDOWN, SIMPLE, DROPDOWNLIST
|
||||
inline const int kTickMarksValues[] = {0, 1, 2, 3}; // NONE, TOPLEFT, BOTTOMRIGHT, BOTH
|
||||
inline const int kScrollBarsValues[] = {0, 1, 2, 3}; // NONE, HORIZONTAL, VERTICAL, BOTH
|
||||
|
||||
// Properties every widget gets (the original configures bg/fg on nearly
|
||||
// every widget type). Phase 1 (section 1): the generic set -- enabled /
|
||||
@@ -89,12 +96,23 @@ inline const std::vector<PropDef>& props_for(const std::string& type) {
|
||||
{"label", K::Str, ""},
|
||||
{"relief", K::Enum, "0", 0, 0, "Normal|Half|None", kReliefValues},
|
||||
{"focus-on-click", K::Bool, "true"},
|
||||
{"default", K::Bool, "false"},
|
||||
{"cancel", K::Bool, "false"},
|
||||
{"kind", K::Enum, "0", 0, 0, "None|OK|Cancel|Yes|No|Close|Help|Retry|Ignore|Abort",
|
||||
kButtonKindValues},
|
||||
{"modal-result", K::Int, "0", 0, 100},
|
||||
{"layout", K::Enum, "0", 0, 0, "Left|Right|Top|Bottom", kButtonLayoutValues},
|
||||
{"glyph", K::Str, ""},
|
||||
};
|
||||
static const std::vector<PropDef> label = {
|
||||
{"label", K::Str, ""},
|
||||
{"xalign", K::Double, "0.5", 0.0, 1.0},
|
||||
{"yalign", K::Double, "0.5", 0.0, 1.0},
|
||||
{"selectable", K::Bool, "false"},
|
||||
{"wrap", K::Bool, "false"},
|
||||
{"transparent", K::Bool, "false"},
|
||||
{"show-accel-char", K::Bool, "true"},
|
||||
{"focus-control", K::Str, ""},
|
||||
};
|
||||
static const std::vector<PropDef> entry = {
|
||||
{"text", K::Str, ""},
|
||||
@@ -104,15 +122,25 @@ inline const std::vector<PropDef>& props_for(const std::string& type) {
|
||||
{"editable", K::Bool, "true"},
|
||||
{"password", K::Bool, "false"},
|
||||
{"show-password", K::Bool, "false"},
|
||||
{"alignment", K::Enum, "0", 0, 0, "Left|Center|Right", kTextAlignValues},
|
||||
{"char-case", K::Enum, "0", 0, 0, "Normal|Upper|Lower", kCharCaseValues},
|
||||
{"numbers-only", K::Bool, "false"},
|
||||
{"hide-selection", K::Bool, "false"},
|
||||
{"auto-select", K::Bool, "false"},
|
||||
};
|
||||
static const std::vector<PropDef> checkbutton = {
|
||||
{"label", K::Str, ""},
|
||||
{"active", K::Bool, "false"},
|
||||
{"inconsistent", K::Bool, "false"},
|
||||
{"allow-grayed", K::Bool, "false"},
|
||||
{"alignment", K::Enum, "0", 0, 0, "Left|Right", kOrientationValues},
|
||||
{"value-checked", K::Str, ""},
|
||||
{"value-unchecked", K::Str, ""},
|
||||
};
|
||||
static const std::vector<PropDef> radiobutton = {
|
||||
{"label", K::Str, ""},
|
||||
{"active", K::Bool, "false"},
|
||||
{"group", K::Int, "0", 0, 100000},
|
||||
};
|
||||
static const std::vector<PropDef> frame = {
|
||||
{"label", K::Str, ""},
|
||||
@@ -122,11 +150,25 @@ inline const std::vector<PropDef>& props_for(const std::string& type) {
|
||||
static const std::vector<PropDef> combobox = {
|
||||
{"items", K::Str, "Item 1|Item 2|Item 3"},
|
||||
{"active", K::Int, "0", -1, 1000},
|
||||
{"text", K::Str, ""},
|
||||
{"style", K::Enum, "0", 0, 0, "DropDown|Simple|DropDownList", kComboStyleValues},
|
||||
{"drop-down-count", K::Int, "8", 1, 100},
|
||||
{"drop-down-width", K::Int, "0", 0, 10000},
|
||||
{"sorted", K::Bool, "false"},
|
||||
{"read-only", K::Bool, "false"},
|
||||
{"max-length", K::Int, "0", 0, 100000},
|
||||
{"auto-complete", K::Bool, "false"},
|
||||
{"char-case", K::Enum, "0", 0, 0, "Normal|Upper|Lower", kCharCaseValues},
|
||||
};
|
||||
static const std::vector<PropDef> listbox = {
|
||||
{"items", K::Str, "Item 1|Item 2|Item 3"},
|
||||
{"selection-mode", K::Enum, "1", 0, 0, "None|Single|Browse|Multiple",
|
||||
kSelModeValues},
|
||||
{"item-index", K::Int, "-1", -1, 100000},
|
||||
{"sorted", K::Bool, "false"},
|
||||
{"columns", K::Int, "1", 1, 100},
|
||||
{"item-height", K::Int, "0", 0, 1000},
|
||||
{"integral-height", K::Bool, "false"},
|
||||
};
|
||||
static const std::vector<PropDef> menubutton = {
|
||||
{"label", K::Str, ""},
|
||||
@@ -135,9 +177,18 @@ inline const std::vector<PropDef>& props_for(const std::string& type) {
|
||||
};
|
||||
static const std::vector<PropDef> scale = {
|
||||
{"value", K::Double, "0", 0, 100},
|
||||
{"minimum", K::Double, "0", -1000000, 1000000},
|
||||
{"maximum", K::Double, "100", -1000000, 1000000},
|
||||
{"digits", K::Int, "1", -1, 10},
|
||||
{"draw-value", K::Bool, "true"},
|
||||
{"inverted", K::Bool, "false"},
|
||||
{"page-step", K::Double, "10", 0, 1000000},
|
||||
{"tick-marks", K::Enum, "0", 0, 0, "None|TopLeft|BottomRight|Both",
|
||||
kTickMarksValues},
|
||||
{"frequency", K::Int, "10", 1, 1000000},
|
||||
{"show-sel-range", K::Bool, "false"},
|
||||
{"sel-start", K::Double, "0", -1000000, 1000000},
|
||||
{"sel-end", K::Double, "0", -1000000, 1000000},
|
||||
};
|
||||
static const std::vector<PropDef> scrollbar = {
|
||||
{"value", K::Double, "0", 0, 100},
|
||||
@@ -147,6 +198,9 @@ inline const std::vector<PropDef>& props_for(const std::string& type) {
|
||||
{"page-increment", K::Double, "10", 0, 1000000},
|
||||
{"page-size", K::Double, "10", 0, 1000000},
|
||||
{"inverted", K::Bool, "false"},
|
||||
{"orientation", K::Enum, "0", 0, 0, "Horizontal|Vertical",
|
||||
kOrientationValues},
|
||||
{"large-change", K::Double, "10", 0, 1000000},
|
||||
};
|
||||
static const std::vector<PropDef> text = {
|
||||
{"text", K::Str, ""},
|
||||
@@ -154,6 +208,13 @@ inline const std::vector<PropDef>& props_for(const std::string& type) {
|
||||
{"cursor-visible", K::Bool, "true"},
|
||||
{"wrap-mode", K::Enum, "0", 0, 0, "None|Char|Word|Word-char",
|
||||
kWrapValues},
|
||||
{"max-length", K::Int, "0", 0, 100000},
|
||||
{"scroll-bars", K::Enum, "0", 0, 0, "None|Horizontal|Vertical|Both",
|
||||
kScrollBarsValues},
|
||||
{"want-tabs", K::Bool, "true"},
|
||||
{"want-returns", K::Bool, "true"},
|
||||
{"hide-selection", K::Bool, "false"},
|
||||
{"alignment", K::Enum, "0", 0, 0, "Left|Center|Right", kTextAlignValues},
|
||||
};
|
||||
static const std::vector<PropDef> memo = {
|
||||
{"text", K::Str, ""},
|
||||
@@ -161,6 +222,20 @@ inline const std::vector<PropDef>& props_for(const std::string& type) {
|
||||
{"cursor-visible", K::Bool, "true"},
|
||||
{"wrap-mode", K::Enum, "0", 0, 0, "None|Char|Word|Word-char",
|
||||
kWrapValues},
|
||||
{"max-length", K::Int, "0", 0, 100000},
|
||||
{"scroll-bars", K::Enum, "3", 0, 0, "None|Horizontal|Vertical|Both",
|
||||
kScrollBarsValues},
|
||||
{"want-tabs", K::Bool, "true"},
|
||||
{"want-returns", K::Bool, "true"},
|
||||
{"hide-selection", K::Bool, "false"},
|
||||
{"alignment", K::Enum, "0", 0, 0, "Left|Center|Right", kTextAlignValues},
|
||||
};
|
||||
static const std::vector<PropDef> checklistbox = {
|
||||
{"items", K::Str, "Item 1|Item 2|Item 3"},
|
||||
{"checked-items", K::Str, ""},
|
||||
{"item-index", K::Int, "-1", -1, 100000},
|
||||
{"item-height", K::Int, "0", 0, 1000},
|
||||
{"sorted", K::Bool, "false"},
|
||||
};
|
||||
static const std::vector<PropDef> groupbox = {
|
||||
{"label", K::Str, ""},
|
||||
@@ -223,6 +298,13 @@ inline const std::vector<PropDef>& props_for(const std::string& type) {
|
||||
{"inverted", K::Bool, "false"},
|
||||
{"orientation", K::Enum, "0", 0, 0, "Horizontal|Vertical",
|
||||
kOrientationValues},
|
||||
{"page-step", K::Double, "10", 0, 1000000},
|
||||
{"tick-marks", K::Enum, "0", 0, 0, "None|TopLeft|BottomRight|Both",
|
||||
kTickMarksValues},
|
||||
{"frequency", K::Int, "10", 1, 1000000},
|
||||
{"show-sel-range", K::Bool, "false"},
|
||||
{"sel-start", K::Double, "0", -1000000, 1000000},
|
||||
{"sel-end", K::Double, "0", -1000000, 1000000},
|
||||
};
|
||||
static const std::vector<PropDef> progressbar = {
|
||||
{"fraction", K::Double, "0", 0, 1},
|
||||
@@ -265,6 +347,7 @@ inline const std::vector<PropDef>& props_for(const std::string& type) {
|
||||
if (type == "Frame") return frame;
|
||||
if (type == "Combobox") return combobox;
|
||||
if (type == "Listbox") return listbox;
|
||||
if (type == "CheckListBox") return checklistbox;
|
||||
if (type == "Menubutton") return menubutton;
|
||||
if (type == "Scale") return scale;
|
||||
if (type == "Scrollbar") return scrollbar;
|
||||
|
||||
+171
-2
@@ -680,6 +680,22 @@ int xframe_core_selected_id(XFrameCanvasCore* c) {
|
||||
// matching setter. Returns false only when there is no such widget,
|
||||
// or the named setter does not exist on this widget (the prop is
|
||||
// still stored and the generator still emits it).
|
||||
// Phase 2: recompute a Scale/TrackBar's tick marks from the model
|
||||
// (tick-marks mode, frequency, minimum, maximum) and push them
|
||||
// through set_marks.
|
||||
static void refresh_scale_marks(XFrameCanvasCore::Placed* p) {
|
||||
int mode = prop_int(p, "tick-marks", 0);
|
||||
int freq = prop_int(p, "frequency", 10);
|
||||
double mn = prop_double(p, "minimum", 0.0);
|
||||
double mx = prop_double(p, "maximum", 100.0);
|
||||
std::vector<double> marks;
|
||||
if (mode != 0 && freq > 0 && mx > mn) {
|
||||
for (double v = mn; v <= mx; v += freq) marks.push_back(v);
|
||||
if (marks.empty() || marks.back() != mx) marks.push_back(mx);
|
||||
}
|
||||
p->wdg->set_marks(marks);
|
||||
}
|
||||
|
||||
bool xframe_core_apply_prop(XFrameCanvasCore* c, int id,
|
||||
const std::string& name,
|
||||
const std::string& value) {
|
||||
@@ -742,7 +758,9 @@ bool xframe_core_apply_prop(XFrameCanvasCore* c, int id,
|
||||
if (cls == "GtkScale" || cls == "GtkSpinButton") {
|
||||
double mn = prop_double(p, "minimum", 0.0);
|
||||
double mx = prop_double(p, "maximum", 100.0);
|
||||
return p->wdg->set_range(mn, mx);
|
||||
bool ok = p->wdg->set_range(mn, mx);
|
||||
if (cls == "GtkScale") refresh_scale_marks(p);
|
||||
return ok;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -786,7 +804,17 @@ bool xframe_core_apply_prop(XFrameCanvasCore* c, int id,
|
||||
// Integer index first (ComboBox), else bool (CheckButton).
|
||||
int idx = 0;
|
||||
if (parse_int_strict(value, idx)) {
|
||||
if (p->wdg->set_active_index(idx)) return true;
|
||||
if (p->wdg->set_active_index(idx)) {
|
||||
// Keep the model text in sync with the selected item
|
||||
// (ComboBox: text is the selected row's text). Only
|
||||
// the ComboBox carries a text prop for the selection;
|
||||
// other set_active_index widgets (CheckButton etc.)
|
||||
// must not gain a spurious one.
|
||||
const std::string& cls = lg::kWidgetNames[p->type];
|
||||
if (cls == "GtkComboBoxText")
|
||||
p->props["text"] = p->wdg->get_text();
|
||||
return true;
|
||||
}
|
||||
return p->wdg->set_active(idx != 0);
|
||||
}
|
||||
return p->wdg->set_active(value == "true");
|
||||
@@ -852,6 +880,147 @@ bool xframe_core_apply_prop(XFrameCanvasCore* c, int id,
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// --- Phase 2 per-widget custom properties (proposal §2.1–§2.10) ---
|
||||
if (name == "default") return p->wdg->set_default(value == "true");
|
||||
if (name == "cancel") return p->wdg->set_cancel(value == "true");
|
||||
if (name == "kind") {
|
||||
int v = 0;
|
||||
if (parse_int_strict(value, v)) {
|
||||
bool ok = p->wdg->set_kind(v);
|
||||
// Kind sets the caption (and modal result): keep the model
|
||||
// in sync so the Inspector and snapshot show the real text.
|
||||
p->props["label"] = p->wdg->get_text();
|
||||
static const int kKindResults[] = {0, 1, 2, 6, 7, 8, 9, 4, 5, 3};
|
||||
if (v >= 1 && v <= 9)
|
||||
p->props["modal-result"] = std::to_string(kKindResults[v]);
|
||||
return ok;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (name == "modal-result") {
|
||||
int v = 0;
|
||||
if (parse_int_strict(value, v)) return p->wdg->set_modal_result(v);
|
||||
return true;
|
||||
}
|
||||
if (name == "layout") {
|
||||
int v = 0;
|
||||
if (parse_int_strict(value, v)) return p->wdg->set_layout(v);
|
||||
return true;
|
||||
}
|
||||
if (name == "glyph") return true; // model-only: no glyph rendering
|
||||
if (name == "yalign") {
|
||||
double v = 0;
|
||||
if (parse_double_strict(value, v)) return p->wdg->set_yalign(v);
|
||||
return true;
|
||||
}
|
||||
if (name == "transparent")
|
||||
return p->wdg->set_transparent(value == "true");
|
||||
if (name == "show-accel-char")
|
||||
return p->wdg->set_show_accel_char(value == "true");
|
||||
if (name == "focus-control") return p->wdg->set_focus_control(value);
|
||||
if (name == "alignment") {
|
||||
int v = 0;
|
||||
if (parse_int_strict(value, v)) return p->wdg->set_alignment(v);
|
||||
return true;
|
||||
}
|
||||
if (name == "char-case") {
|
||||
int v = 0;
|
||||
if (parse_int_strict(value, v)) return p->wdg->set_char_case(v);
|
||||
return true;
|
||||
}
|
||||
if (name == "numbers-only")
|
||||
return p->wdg->set_numbers_only(value == "true");
|
||||
if (name == "hide-selection")
|
||||
return p->wdg->set_hide_selection(value == "true");
|
||||
if (name == "auto-select") return p->wdg->set_auto_select(value == "true");
|
||||
if (name == "allow-grayed")
|
||||
return p->wdg->set_allow_grayed(value == "true");
|
||||
if (name == "value-checked") return p->wdg->set_value_checked(value);
|
||||
if (name == "value-unchecked") return p->wdg->set_value_unchecked(value);
|
||||
if (name == "group") {
|
||||
int v = 0;
|
||||
if (parse_int_strict(value, v)) return p->wdg->set_group_id(v);
|
||||
return true;
|
||||
}
|
||||
if (name == "style") {
|
||||
int v = 0;
|
||||
if (parse_int_strict(value, v)) return p->wdg->set_style(v);
|
||||
return true;
|
||||
}
|
||||
if (name == "drop-down-count") {
|
||||
int v = 0;
|
||||
if (parse_int_strict(value, v)) return p->wdg->set_drop_down_count(v);
|
||||
return true;
|
||||
}
|
||||
if (name == "drop-down-width") {
|
||||
int v = 0;
|
||||
if (parse_int_strict(value, v)) return p->wdg->set_drop_down_width(v);
|
||||
return true;
|
||||
}
|
||||
if (name == "sorted") return p->wdg->set_sorted(value == "true");
|
||||
if (name == "read-only") return p->wdg->set_read_only(value == "true");
|
||||
if (name == "auto-complete")
|
||||
return p->wdg->set_auto_complete(value == "true");
|
||||
if (name == "item-index") {
|
||||
int v = 0;
|
||||
if (parse_int_strict(value, v)) return p->wdg->set_selected_row(v);
|
||||
return true;
|
||||
}
|
||||
if (name == "item-height") {
|
||||
int v = 0;
|
||||
if (parse_int_strict(value, v) && v > 0)
|
||||
return p->wdg->set_row_height(v);
|
||||
return true;
|
||||
}
|
||||
if (name == "columns") return true; // model-only: single-column list
|
||||
if (name == "integral-height") {
|
||||
// Snap the widget height to a whole number of rows.
|
||||
int ih = prop_int(p, "item-height", 0);
|
||||
const std::string& cls = lg::kWidgetNames[p->type];
|
||||
int rh = ih > 0 ? ih : (cls == "TCheckListBox" ? 18 : 24);
|
||||
if (value == "true") {
|
||||
int rows = std::max(1, (p->h - 4) / rh);
|
||||
p->h = rows * rh + 4;
|
||||
p->wdg->set_bounds(p->x, p->y, p->w, p->h);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (name == "large-change") {
|
||||
double v = 0;
|
||||
if (parse_double_strict(value, v))
|
||||
return p->wdg->set_page_increment(v);
|
||||
return true;
|
||||
}
|
||||
if (name == "page-step") {
|
||||
double v = 0;
|
||||
if (parse_double_strict(value, v)) return p->wdg->set_page_step(v);
|
||||
return true;
|
||||
}
|
||||
if (name == "tick-marks" || name == "frequency") {
|
||||
refresh_scale_marks(p);
|
||||
return true;
|
||||
}
|
||||
if (name == "show-sel-range")
|
||||
return p->wdg->set_show_sel_range(value == "true");
|
||||
if (name == "sel-start") {
|
||||
double v = 0;
|
||||
if (parse_double_strict(value, v)) return p->wdg->set_sel_start(v);
|
||||
return true;
|
||||
}
|
||||
if (name == "sel-end") {
|
||||
double v = 0;
|
||||
if (parse_double_strict(value, v)) return p->wdg->set_sel_end(v);
|
||||
return true;
|
||||
}
|
||||
if (name == "scroll-bars") {
|
||||
int v = 0;
|
||||
if (parse_int_strict(value, v)) return p->wdg->set_scroll_bars(v);
|
||||
return true;
|
||||
}
|
||||
if (name == "want-tabs") return p->wdg->set_want_tabs(value == "true");
|
||||
if (name == "want-returns")
|
||||
return p->wdg->set_want_returns(value == "true");
|
||||
if (name == "checked-items") return p->wdg->set_checked_items(value);
|
||||
// Model-only (stored + emitted by the generator; no live setter):
|
||||
// anchor-top/left/right/bottom, align, tab-order, tab-stop,
|
||||
// cursor, tag, margin-*, show-hint, hint/tooltip-text.
|
||||
|
||||
Reference in new issue
Block a user