Fix M9.8c review findings in the engineering client
Resolve pointer ownership per SDL event so same-batch panel clicks, wheel and click-to-focus typing never reach the world; keep the Tab toggle independent of idempotent external capture release; own launcher phase and remote session together so Local fixture ends any remote attempt; wrap notices beside a reserved close column within a bounded stack. Adds client-panels test and host/session, same-batch and host-order Tab regressions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
// M9.8c: the production engineering panels through the real adapter (dummy driver,
|
||||
// software renderer, pinned toolkit). Notices fit their fixed-width window with a
|
||||
// visible close button; clicking it (move + press + release in one batch, no settling
|
||||
// frame) dismisses exactly that notice and never reaches the world.
|
||||
#include "evo/client/application.hpp"
|
||||
#include "panels.hpp"
|
||||
#include <SDL3/SDL.h>
|
||||
#include <array>
|
||||
#include <cstdio>
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
#include <source_location>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
using namespace evo;
|
||||
using namespace evo::client;
|
||||
using namespace evo::client_app;
|
||||
void check(bool ok, std::source_location at = std::source_location::current()) {
|
||||
if (!ok)
|
||||
throw std::runtime_error("client panels line " + std::to_string(at.line()));
|
||||
}
|
||||
#define CHECK(...) check(static_cast<bool>(__VA_ARGS__))
|
||||
SDL_Window* window() {
|
||||
int count{};
|
||||
SDL_Window** windows = SDL_GetWindows(&count);
|
||||
SDL_Window* result = count == 1 ? windows[0] : nullptr;
|
||||
SDL_free(static_cast<void*>(windows));
|
||||
CHECK(result);
|
||||
return result;
|
||||
}
|
||||
void mouse(SDL_WindowID id, SDL_EventType type, float x, float y) {
|
||||
SDL_Event event{};
|
||||
event.type = type;
|
||||
if (type == SDL_EVENT_MOUSE_MOTION) {
|
||||
event.motion.windowID = id;
|
||||
event.motion.x = x;
|
||||
event.motion.y = y;
|
||||
} else {
|
||||
event.button.windowID = id;
|
||||
event.button.button = SDL_BUTTON_LEFT;
|
||||
event.button.down = type == SDL_EVENT_MOUSE_BUTTON_DOWN;
|
||||
event.button.clicks = 1;
|
||||
event.button.x = x;
|
||||
event.button.y = y;
|
||||
}
|
||||
CHECK(SDL_PushEvent(&event));
|
||||
}
|
||||
ImGuiWindow* notice_window(std::uint64_t id) {
|
||||
return ImGui::FindWindowByName((notice_window_prefix + std::to_string(id)).c_str());
|
||||
}
|
||||
|
||||
void notices() {
|
||||
const std::array<render::Rectangle, 1> boxes{{{0, 0, 32, 32, {40, 40, 40, 255}}}};
|
||||
auto frame = render::Frame::create(boxes);
|
||||
CHECK(frame);
|
||||
auto opened = Application::open({960, 640, false, "software"});
|
||||
CHECK(opened);
|
||||
auto app = std::move(*opened);
|
||||
const auto id = SDL_GetWindowID(window());
|
||||
SDL_Event focus{};
|
||||
focus.type = SDL_EVENT_WINDOW_FOCUS_GAINED;
|
||||
focus.window.windowID = id;
|
||||
CHECK(SDL_PushEvent(&focus) && app->poll_events());
|
||||
|
||||
UiState ui;
|
||||
EnvironmentLayer environment;
|
||||
OrganismLayer organisms;
|
||||
Selection selection;
|
||||
Launcher launcher;
|
||||
FormBuffers form;
|
||||
render::EnvironmentDisplay display;
|
||||
PanelView view;
|
||||
view.mode = Mode::fixture;
|
||||
view.launcher = &launcher;
|
||||
view.environment = &environment;
|
||||
view.organisms = &organisms;
|
||||
view.selection = &selection;
|
||||
view.ui = &ui;
|
||||
std::optional<std::uint64_t> dismissed;
|
||||
app->set_overlay([&] {
|
||||
if (const auto a = draw_panels(view, form, display); a.dismiss_notice)
|
||||
dismissed = a.dismiss_notice;
|
||||
});
|
||||
// The application's real notices plus a maximal 240-byte message of wide glyphs.
|
||||
const std::string longest(UiState::max_text, 'W');
|
||||
std::vector<std::uint64_t> ids;
|
||||
for (const auto* text :
|
||||
{"Connected to the dev region (fresh baseline).", "Connection lost; views are stale.",
|
||||
"Session event backlog; reconnecting after draining.", longest.c_str()}) {
|
||||
const auto made = ui.notify(text, NoticeLevel::warning, 600000);
|
||||
CHECK(made);
|
||||
ids.push_back(*made);
|
||||
}
|
||||
for (int i = 0; i < 2; ++i)
|
||||
CHECK(app->poll_events() && app->present(*frame) == Step::rendered);
|
||||
const auto& style = ImGui::GetStyle();
|
||||
for (const auto n : ids) {
|
||||
const auto* w = notice_window(n);
|
||||
CHECK(w != nullptr && w->Active);
|
||||
// Nothing wider than the window: no clipped text, no horizontal scrolling.
|
||||
CHECK(w->ContentSize.x <= w->Size.x - (2 * style.WindowPadding.x) + 0.5F);
|
||||
CHECK(w->ScrollMax.x == 0 && w->Pos.x >= 0 && w->Pos.x + w->Size.x <= 960);
|
||||
CHECK(w->Pos.y >= 0 && w->Pos.y + w->Size.y <= 640);
|
||||
}
|
||||
// Close the longest notice: pointer last over the world, then one batch.
|
||||
const auto* target = notice_window(ids.back());
|
||||
const float x = target->Pos.x + target->Size.x - style.WindowPadding.x - style.CellPadding.x -
|
||||
(notice_close_width / 2);
|
||||
const float y = target->Pos.y + style.WindowPadding.y + style.CellPadding.y +
|
||||
style.FramePadding.y + (ImGui::GetFontSize() / 2);
|
||||
mouse(id, SDL_EVENT_MOUSE_MOTION, 480, 320);
|
||||
CHECK(app->poll_events() && app->present(*frame) == Step::rendered);
|
||||
static_cast<void>(app->take_navigation());
|
||||
mouse(id, SDL_EVENT_MOUSE_MOTION, x, y);
|
||||
mouse(id, SDL_EVENT_MOUSE_BUTTON_DOWN, x, y);
|
||||
mouse(id, SDL_EVENT_MOUSE_BUTTON_UP, x, y);
|
||||
CHECK(app->poll_events() && !app->take_navigation().click);
|
||||
for (int i = 0; i < 5 && !dismissed; ++i)
|
||||
CHECK(app->present(*frame) == Step::rendered && app->poll_events());
|
||||
CHECK(dismissed == ids.back() && ui.dismiss(*dismissed) && ui.notices().size() == 3);
|
||||
CHECK(!app->take_navigation().click);
|
||||
CHECK(app->present(*frame) == Step::rendered && app->poll_events());
|
||||
const auto* gone = notice_window(ids.back());
|
||||
CHECK(gone == nullptr || !gone->Active);
|
||||
for (std::size_t k = 0; k + 1 < ids.size(); ++k)
|
||||
CHECK(notice_window(ids[k])->Active);
|
||||
// A full stack stays inside the lower part of the viewport and counts the rest.
|
||||
for (int k = 0; k < 8; ++k)
|
||||
CHECK(ui.notify(longest, NoticeLevel::info, 600000));
|
||||
for (int i = 0; i < 2; ++i)
|
||||
CHECK(app->present(*frame) == Step::rendered && app->poll_events());
|
||||
for (const auto& n : ui.notices())
|
||||
if (const auto* w = notice_window(n.id); w != nullptr && w->Active)
|
||||
CHECK(w->Pos.y >= 0 && w->Pos.y + w->Size.y <= 640);
|
||||
const auto* more = ImGui::FindWindowByName("##evicted");
|
||||
CHECK(more != nullptr && more->Active && more->Pos.y >= 0);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main() try {
|
||||
notices();
|
||||
std::puts("client panel tests passed");
|
||||
return 0;
|
||||
} catch (const std::exception& e) {
|
||||
std::fprintf(stderr, "%s: %s\n", e.what(), SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user