Skip to content

Commit d0fbb3c

Browse files
committed
view_example: print the layout after every status change
On Linux WindowResizedEvent arrives before GTK lays the content out, so the layout printed for it is the old one; the line printed with the next status change is the settled one, which is what the GUI tests read.
1 parent c526044 commit d0fbb3c

1 file changed

Lines changed: 21 additions & 18 deletions

File tree

‎examples/view_example/main.cpp‎

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,31 @@ int main() {
6363
actions->AddSubview(clear);
6464
actions->AddSubview(sign_in);
6565

66+
// "[view] layout <name> x y w h" per control, in the root's coordinates; printed
67+
// at start-up, after every resize and after every status change, so the re-flow can be
68+
// checked from outside. (On Linux WindowResizedEvent comes before GTK has laid the
69+
// content out, so the line printed at the next status change is the settled one.)
70+
auto print_layout = [=] {
71+
const Rectangle actions_frame = actions->GetFrame();
72+
auto print = [&](const char* label, const std::shared_ptr<View>& view, double dx, double dy) {
73+
const Rectangle f = view->GetFrame();
74+
std::cout << "[view] layout " << label << " " << f.x + dx << " " << f.y + dy << " "
75+
<< f.width << " " << f.height << std::endl;
76+
};
77+
print("root", root, 0, 0);
78+
print("heading", heading, 0, 0);
79+
print("name", name, 0, 0);
80+
print("password", password, 0, 0);
81+
print("status", status, 0, 0);
82+
print("actions", actions, 0, 0);
83+
print("clear", clear, actions_frame.x, actions_frame.y);
84+
print("sign_in", sign_in, actions_frame.x, actions_frame.y);
85+
};
6686
// Every status change is echoed to stdout, so a GUI test can assert on it.
6787
auto set_status = [=](const std::string& text) {
6888
status->SetText(text);
6989
std::cout << "[view] status: " << text << std::endl;
90+
print_layout();
7091
};
7192
auto submit = [=](const ViewEvent&) {
7293
if (name->GetText().empty()) {
@@ -104,24 +125,6 @@ int main() {
104125
root->AddSubview(status);
105126
root->AddSubview(actions);
106127

107-
// "[view] layout <name> x y w h" per control, in the root's coordinates; printed
108-
// now and after every resize, so the re-flow can be checked from outside.
109-
auto print_layout = [=] {
110-
const Rectangle actions_frame = actions->GetFrame();
111-
auto print = [&](const char* label, const std::shared_ptr<View>& view, double dx, double dy) {
112-
const Rectangle f = view->GetFrame();
113-
std::cout << "[view] layout " << label << " " << f.x + dx << " " << f.y + dy << " "
114-
<< f.width << " " << f.height << std::endl;
115-
};
116-
print("root", root, 0, 0);
117-
print("heading", heading, 0, 0);
118-
print("name", name, 0, 0);
119-
print("password", password, 0, 0);
120-
print("status", status, 0, 0);
121-
print("actions", actions, 0, 0);
122-
print("clear", clear, actions_frame.x, actions_frame.y);
123-
print("sign_in", sign_in, actions_frame.x, actions_frame.y);
124-
};
125128
print_layout();
126129
WindowManager::GetInstance().AddListener<WindowResizedEvent>(
127130
[=](const WindowResizedEvent& event) {

0 commit comments

Comments
 (0)