fix(client): stabilize HUD and anchor draggable panels
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (postgres) (push) Successful in 4s
Foundation / checks (tsan) (push) Successful in 4s
Foundation / checks (deploy) (push) Successful in 4m29s
Foundation / postgres-tools (push) Successful in 20s
Foundation / server-image (push) Canceled after 1m43s
Foundation / image (push) Canceled after 1m43s

This commit is contained in:
dingo
2026-10-26 15:13:15 -04:00
parent 840816c541
commit d057374148
9 changed files with 334 additions and 31 deletions
+142
View File
@@ -500,6 +500,76 @@ void cellular_panels(const std::filesystem::path& review) {
if (width >= 880)
CHECK(fits(ImGui::FindWindowByName("Field notes")) &&
disjoint(vitals, ImGui::FindWindowByName("Field notes")));
// Live messages may change overflow, but never move/resize the cards or
// reflow their content width. Exercise every frame, including empty data.
struct Geometry {
ImGuiWindow* panel;
ImVec2 position, size;
float body_width;
};
std::vector<Geometry> geometry;
bool details_fit = false, details_overflow = false;
for (const auto* name : {"Vitals", "Nearby", "Actions", "Field notes"}) {
auto* panel = ImGui::FindWindowByName(name);
if (!panel || !panel->Active)
continue;
CHECK(panel->DC.ChildWindows.Size == 1);
geometry.push_back(
{panel, panel->Pos, panel->Size, panel->DC.ChildWindows[0]->InnerRect.GetWidth()});
}
for (int sample = 0; sample < 16; ++sample) {
auto changing = diagnostics;
changing.members = static_cast<std::uint16_t>(sample % 3 == 0 ? 8 : 1);
changing.growth_per_thousand = sample % 2 == 0 ? 1000 : 475;
changing.growth_limit = static_cast<std::uint8_t>(sample % 7);
changing.light_pj = sample % 2 == 0 ? 0 : 1'000'000;
changing.bud_cost_energy_pj = sample % 2 == 0 ? 0 : 1'000'000;
changing.bud_cost_matter_fg =
sample % 2 == 0 ? std::array<std::uint64_t, 4>{} : diagnostics.bud_cost_matter_fg;
perception.diagnostics =
sample % 4 == 0 ? std::optional<network::CellularLifeDiagnostics>{} : changing;
scene.at_edge = sample % 2 == 0;
scene.stale = sample % 2 != 0;
scene.region_cells = sample % 2 == 0 ? 0 : 256;
if (auto* notes = ImGui::FindWindowByName("Field notes"); notes && notes->Active) {
auto* body = notes->DC.ChildWindows[0];
for (const auto* heading : {"Food in range", "Burning reserve matter", "Body",
"Steering", "Recent actions", "Help"})
body->StateStorage.SetInt(body->GetID(heading), sample % 2);
}
draw();
for (const auto& card : geometry) {
CHECK(fits(card.panel));
CHECK(card.panel->Pos.x == card.position.x && card.panel->Pos.y == card.position.y);
CHECK(card.panel->Size.x == card.size.x && card.panel->Size.y == card.size.y);
CHECK(card.panel->DC.ChildWindows[0]->InnerRect.GetWidth() == card.body_width);
const auto* body = card.panel->DC.ChildWindows[0];
CHECK(body->ScrollMax.x == 0);
if (card.panel == dock) {
details_fit = details_fit || body->ScrollMax.y == 0;
details_overflow = details_overflow || body->ScrollMax.y > 0;
}
}
if (!review.empty() && sample == 15) {
std::filesystem::create_directories(review);
CHECK(app->request_screenshot(
(review / ("cellular-overflow-" + std::to_string(width) + ".bmp")).string()));
draw();
}
}
CHECK(details_fit && details_overflow);
perception.diagnostics = diagnostics;
scene.at_edge = false;
scene.stale = false;
scene.region_cells = 0;
if (auto* notes = ImGui::FindWindowByName("Field notes"); notes && notes->Active) {
auto* body = notes->DC.ChildWindows[0];
for (const auto* heading : {"Food in range", "Burning reserve matter", "Body",
"Steering", "Recent actions", "Help"})
body->StateStorage.SetInt(body->GetID(heading), 0);
}
for (int i = 0; i < 3; ++i)
draw();
// Minimize/restore stays local to the panel, including a same-batch click.
const auto toggle = [&](const char* name, bool& minimized) {
const auto* panel = ImGui::FindWindowByName(name);
@@ -526,6 +596,78 @@ void cellular_panels(const std::filesystem::path& review) {
toggle("Nearby", form.map_minimized);
if (width >= 880)
toggle("Field notes", form.notes_minimized);
if (width == 960) {
const auto handle = [](const ImGuiWindow* panel) {
const auto& style = ImGui::GetStyle();
const float small = ImGui::CalcTextSize(" + ").x + 2 * style.FramePadding.x;
const float grab = ImGui::CalcTextSize("::").x + 2 * style.FramePadding.x;
return ImVec2{panel->Pos.x + panel->Size.x - style.WindowPadding.x - 2 * small -
style.ItemSpacing.x + grab / 2,
panel->Pos.y + style.WindowPadding.y + ImGui::GetFrameHeight() / 2};
};
const auto drag = [&](const char* name, HudPanelPlacement& placement, float dx,
float dy) {
auto* panel = ImGui::FindWindowByName(name);
CHECK(panel);
const auto start = handle(panel);
const auto previous = panel->Pos;
mouse(id, SDL_EVENT_MOUSE_MOTION, start.x, start.y);
draw();
mouse(id, SDL_EVENT_MOUSE_BUTTON_DOWN, start.x, start.y);
draw();
CHECK(!app->take_navigation().click);
mouse(id, SDL_EVENT_MOUSE_MOTION, start.x + dx, start.y + dy);
draw();
mouse(id, SDL_EVENT_MOUSE_BUTTON_UP, start.x + dx, start.y + dy);
for (int i = 0; i < 3; ++i)
draw();
CHECK(!app->take_navigation().click && placement.anchor && fits(panel));
CHECK(panel->Pos.x != previous.x || panel->Pos.y != previous.y);
return panel->Pos;
};
const auto anchored = drag("Vitals", form.vitals_placement, 40, -30);
toggle("Vitals", form.vitals_minimized);
CHECK(vitals->Pos.x == anchored.x && vitals->Pos.y == anchored.y);
for (int i = 0; i < 4; ++i)
draw();
CHECK(vitals->Pos.x == anchored.x && vitals->Pos.y == anchored.y);
drag("Field notes", form.notes_placement, 30, 10);
drag("Nearby", form.map_placement, -35, 20);
if (!review.empty()) {
mouse(id, SDL_EVENT_MOUSE_MOTION, 5, 5);
draw();
CHECK(app->request_screenshot((review / "cellular-panels-moved.bmp").string()));
draw();
}
CHECK(SDL_SetWindowSize(window(), 640, 480));
for (int i = 0; i < 4; ++i)
draw();
for (const auto* name : {"Vitals", "Nearby"}) {
const auto* panel = ImGui::FindWindowByName(name);
const auto extent = ImGui::GetIO().DisplaySize;
CHECK(panel && panel->Pos.x >= 0 && panel->Pos.y >= 0 &&
panel->Pos.x + panel->Size.x <= extent.x &&
panel->Pos.y + panel->Size.y <= extent.y);
}
CHECK(SDL_SetWindowSize(window(), width, height));
for (int i = 0; i < 4; ++i)
draw();
drag("Nearby", form.map_placement, 10'000, 10'000);
// The reset gesture uses the same production handle, with no world click.
const auto reset_at = handle(ImGui::FindWindowByName("Nearby"));
for (int click = 0; click < 2; ++click) {
mouse(id, SDL_EVENT_MOUSE_MOTION, reset_at.x, reset_at.y);
mouse(id, SDL_EVENT_MOUSE_BUTTON_DOWN, reset_at.x, reset_at.y);
draw();
mouse(id, SDL_EVENT_MOUSE_BUTTON_UP, reset_at.x, reset_at.y);
draw();
}
CHECK(!form.map_placement.anchor && !app->take_navigation().click);
form.vitals_placement.anchor.reset();
form.notes_placement.anchor.reset();
for (int i = 0; i < 3; ++i)
draw();
}
mouse(id, SDL_EVENT_MOUSE_MOTION, 5, 5);
// A depleted channel vanishes independently. Stale observations retain the food
// silhouettes but never their fresh opacity. Inspect the world draw list, not HUD.