|
6 | 6 | class MainWindow : public Gtk::Window { |
7 | 7 |
|
8 | 8 | // --- Layout Containers --- |
9 | | - Gtk::Box m_mainLayout; |
10 | | - Gtk::Box m_topRowLayout; |
| 9 | + Gtk::Box m_mainLayout_; |
| 10 | + Gtk::Box m_topRowLayout_; |
11 | 11 |
|
12 | 12 | // --- Widgets --- |
13 | 13 | // We must declare everything here so that the buttons are accessible |
14 | 14 |
|
15 | 15 | // Editor |
16 | | - Gtk::Frame frame_Editor; |
17 | | - Gtk::Box m_boxEditor; |
18 | | - Gtk::Entry entry_Input; |
19 | | - Gtk::Button button_Update; |
| 16 | + Gtk::Frame frame_Editor_; |
| 17 | + Gtk::Box m_boxEditor_; |
| 18 | + Gtk::Entry entry_Input_; |
| 19 | + Gtk::Button button_Update_; |
20 | 20 |
|
21 | 21 | // Monitor A |
22 | | - Gtk::Frame frame_MonitorA; |
23 | | - Gtk::Box m_boxMonitorA; |
24 | | - Gtk::Label m_labelMonitorA; |
| 22 | + Gtk::Frame frame_MonitorA_; |
| 23 | + Gtk::Box m_boxMonitorA_; |
| 24 | + Gtk::Label m_labelMonitorA_; |
25 | 25 |
|
26 | 26 | // Monitor B |
27 | | - Gtk::Frame frame_MonitorB; |
28 | | - Gtk::Box m_boxMonitorB; |
29 | | - Gtk::Label m_labelMonitorB; |
| 27 | + Gtk::Frame frame_MonitorB_; |
| 28 | + Gtk::Box m_boxMonitorB_; |
| 29 | + Gtk::Label m_labelMonitorB_; |
30 | 30 |
|
31 | 31 | public: |
32 | 32 | MainWindow() |
33 | | - : m_mainLayout(Gtk::Orientation::VERTICAL), |
34 | | - m_topRowLayout(Gtk::Orientation::HORIZONTAL), |
35 | | - m_boxEditor(Gtk::Orientation::VERTICAL), |
36 | | - m_boxMonitorA(Gtk::Orientation::VERTICAL), |
37 | | - m_boxMonitorB(Gtk::Orientation::VERTICAL) { |
| 33 | + : m_mainLayout_(Gtk::Orientation::VERTICAL), |
| 34 | + m_topRowLayout_(Gtk::Orientation::HORIZONTAL), |
| 35 | + m_boxEditor_(Gtk::Orientation::VERTICAL), |
| 36 | + m_boxMonitorA_(Gtk::Orientation::VERTICAL), |
| 37 | + m_boxMonitorB_(Gtk::Orientation::VERTICAL) { |
38 | 38 | set_title("No-MVC (Coupled) Demo"); |
39 | 39 | set_default_size(600, 400); |
40 | 40 |
|
41 | 41 | // 1. SETUP UI (Visually identical to MVC) |
42 | 42 | // --- Monitor A --- |
43 | | - frame_MonitorA.set_label("ZONE 2: MONITOR A (Blue)"); |
44 | | - m_labelMonitorA.set_markup( |
| 43 | + frame_MonitorA_.set_label("ZONE 2: MONITOR A (Blue)"); |
| 44 | + m_labelMonitorA_.set_markup( |
45 | 45 | "<span foreground='blue' size='x-large'>Initial Data</span>"); |
46 | | - m_boxMonitorA.append(m_labelMonitorA); |
47 | | - frame_MonitorA.set_child(m_boxMonitorA); |
48 | | - frame_MonitorA.set_hexpand(true); // Stretch |
| 46 | + m_boxMonitorA_.append(m_labelMonitorA_); |
| 47 | + frame_MonitorA_.set_child(m_boxMonitorA_); |
| 48 | + frame_MonitorA_.set_hexpand(true); // Stretch |
49 | 49 |
|
50 | 50 | // --- Monitor B --- |
51 | | - frame_MonitorB.set_label("ZONE 3: MONITOR B (Red)"); |
52 | | - m_labelMonitorB.set_markup( |
| 51 | + frame_MonitorB_.set_label("ZONE 3: MONITOR B (Red)"); |
| 52 | + m_labelMonitorB_.set_markup( |
53 | 53 | "<span foreground='red' size='x-large'>Initial Data</span>"); |
54 | | - m_boxMonitorB.append(m_labelMonitorB); |
55 | | - frame_MonitorB.set_child(m_boxMonitorB); |
56 | | - frame_MonitorB.set_hexpand(true); |
| 54 | + m_boxMonitorB_.append(m_labelMonitorB_); |
| 55 | + frame_MonitorB_.set_child(m_boxMonitorB_); |
| 56 | + frame_MonitorB_.set_hexpand(true); |
57 | 57 |
|
58 | 58 | // --- Editor --- |
59 | | - frame_Editor.set_label("ZONE 1: EDITOR"); |
60 | | - entry_Input.set_text("Initial Data"); |
61 | | - button_Update.set_label("Direct Update"); // Live updates |
62 | | - m_boxEditor.append(entry_Input); |
63 | | - m_boxEditor.append(button_Update); |
64 | | - frame_Editor.set_child(m_boxEditor); |
| 59 | + frame_Editor_.set_label("ZONE 1: EDITOR"); |
| 60 | + entry_Input_.set_text("Initial Data"); |
| 61 | + button_Update_.set_label("Direct Update"); // Live updates |
| 62 | + m_boxEditor_.append(entry_Input_); |
| 63 | + m_boxEditor_.append(button_Update_); |
| 64 | + frame_Editor_.set_child(m_boxEditor_); |
65 | 65 |
|
66 | 66 | // --- Layout --- |
67 | | - m_topRowLayout.append(frame_MonitorA); |
68 | | - m_topRowLayout.append(frame_MonitorB); |
69 | | - m_mainLayout.append(m_topRowLayout); |
70 | | - m_mainLayout.append(frame_Editor); |
| 67 | + m_topRowLayout_.append(frame_MonitorA_); |
| 68 | + m_topRowLayout_.append(frame_MonitorB_); |
| 69 | + m_mainLayout_.append(m_topRowLayout_); |
| 70 | + m_mainLayout_.append(frame_Editor_); |
71 | 71 |
|
72 | 72 | // Margin for aesthetics |
73 | | - m_boxEditor.set_margin(10); |
74 | | - m_boxEditor.set_spacing(5); |
75 | | - m_boxMonitorA.set_margin(20); |
76 | | - m_boxMonitorB.set_margin(20); |
77 | | - set_child(m_mainLayout); |
| 73 | + m_boxEditor_.set_margin(10); |
| 74 | + m_boxEditor_.set_spacing(5); |
| 75 | + m_boxMonitorA_.set_margin(20); |
| 76 | + m_boxMonitorB_.set_margin(20); |
| 77 | + set_child(m_mainLayout_); |
78 | 78 |
|
79 | 79 | // 2. LOGIC HANDLING |
80 | 80 | // Here, the button must "know" exactly who m_labelMonitorA and m_labelMonitorB are. |
81 | 81 | // It directly controls the other widgets. |
82 | 82 | // (THE BAD PART) |
83 | | - button_Update.signal_clicked().connect([this]() { |
| 83 | + button_Update_.signal_clicked().connect([this]() { |
84 | 84 | // Step 1: Get data directly from UI (Entry) |
85 | | - std::string text = entry_Input.get_text(); |
| 85 | + std::string text = entry_Input_.get_text(); |
86 | 86 | // There may be processing logic here (Validating...) |
87 | 87 | if (text.empty()) |
88 | 88 | return; |
89 | 89 |
|
90 | 90 | // Step 2: Update Monitor A (Hard-coded) directly |
91 | | - m_labelMonitorA.set_markup("<span foreground='blue' size='x-large'>" + |
92 | | - text + "</span>"); |
| 91 | + m_labelMonitorA_.set_markup("<span foreground='blue' size='x-large'>" + |
| 92 | + text + "</span>"); |
93 | 93 |
|
94 | 94 | // Step 3: Update Monitor B (Hard-coded) directly |
95 | | - m_labelMonitorB.set_markup("<span foreground='red' size='x-large'>" + |
96 | | - text + "</span>"); |
| 95 | + m_labelMonitorB_.set_markup("<span foreground='red' size='x-large'>" + |
| 96 | + text + "</span>"); |
97 | 97 | std::cout << "Updated directly without Model!" << std::endl; |
98 | 98 | }); |
99 | 99 | } |
|
0 commit comments