feat(examples): drive a region through the glfw demo and verify its geometry

This commit is contained in:
Martino Ferrari committed 2026-09-28 13:54:59 +02:00
1 parent 4e0e0ae0b3
commit 4681d7015b
1 file changed
+27 -23
+27 -23
View File
@@ -512,15 +512,6 @@ int main() {
p.set_cursor_snap(cursor_b, plot::SnapMode::NearestSample);
const u32 measure = p.add_measure(cursor_a, cursor_b, trace);
// The region the direct-manipulation script drags and the pixels are counted from. Its
// bounds are placed by the script, once the view it is measured against has been frozen.
plot::Region region_desc;
region_desc.snap = plot::RegionSnap::Free;
region_desc.fill = kRegionFill;
region_desc.edge = kRegionEdge;
region_desc.label = "roi";
const u32 region = p.add_region(region_desc);
Meter meter;
/// The scripted live-follow verification, off unless `PLOT_DEMO_FOLLOW` asks for
/// it. It is the same shape as the headless smoke mode above: a driven run whose
@@ -529,6 +520,17 @@ int main() {
/// The scripted region sequence, off unless `PLOT_DEMO_REGIONS` asks for it. Same shape
/// as the follow script: a driven run whose verdict is carried out in its `failed`.
RegionScript region_script = RegionScript::from_env();
// The region that script drags, and the element the pixel counts are of. It exists only
// while the script is armed: the default run is the frame the four adapters copy, and an
// element nothing drives would be a change to it rather than a demonstration. The script
// places its bounds once the view it is measured against has been frozen.
plot::Region region_desc;
region_desc.snap = plot::RegionSnap::Free;
region_desc.fill = kRegionFill;
region_desc.edge = kRegionEdge;
region_desc.label = "roi";
const u32 region = region_script.enabled ? p.add_region(region_desc) : 0u;
// The cursors ride the live window until the user takes over: the first
// ctrl+drag on a cursor, or a pan/zoom that clears the x axis' auto scale,
// stops them where the user put them. Under `Live` the follow path owns the x
@@ -688,20 +690,22 @@ int main() {
stats.draw_calls, stats.lod_traces, stats.raw_traces);
std::printf("[glfw_demo] measurement %s dx %g s dy %g rms %g mean %g\n",
m.valid ? "valid:" : "INVALID", m.dx, m.dy, m.rms, m.mean);
std::printf("[glfw_demo] region x [%g, %g] s, snap %s, %s; checks %s\n",
p.region(region).x0, p.region(region).x1,
p.region(region).snap == plot::RegionSnap::Free ? "free" : "nearest sample",
region_script.enabled ? (region_script.hover ? "bound hovered at exit" : "pointer off the data area at exit") : "not driven",
region_script.enabled ? (region_script.failed ? "FAILED" : "passed") : "-");
if (const plot::RegionLayout* rl = region_layout(p, region); rl != nullptr) {
// The last frame's geometry, as the layout measured it: the rects the fills, bounds
// and pixel counts all have to agree with.
std::printf("[glfw_demo] region fill x %.1f y %.1f w %.1f h %.1f, bounds at %.1f and"
" %.1f, tab w %.1f, label w %.1f\n",
rl->fill.x, rl->fill.y, rl->fill.w, rl->fill.h,
static_cast<plot::f64>(plot::handle_column(rl->left_handle)),
static_cast<plot::f64>(plot::handle_column(rl->right_handle)),
rl->left_handle.w, rl->label.w);
if (region_script.enabled) {
std::printf("[glfw_demo] region %u: x [%g, %g] s, snap %s, %s; checks %s\n", region,
p.region(region).x0, p.region(region).x1,
p.region(region).snap == plot::RegionSnap::Free ? "free" : "nearest sample",
region_script.hover ? "bound hovered at exit" : "pointer off the data area at exit",
region_script.failed ? "FAILED" : "passed");
if (const plot::RegionLayout* rl = region_layout(p, region); rl != nullptr) {
// The last frame's geometry, as the layout measured it: the rect the fill, the bound
// strokes and the pixel counts all have to agree with.
std::printf("[glfw_demo] region fill x %.1f y %.1f w %.1f h %.1f, bounds at %.1f and"
" %.1f, tab w %.1f, label w %.1f\n",
rl->fill.x, rl->fill.y, rl->fill.w, rl->fill.h,
static_cast<plot::f64>(plot::handle_column(rl->left_handle)),
static_cast<plot::f64>(plot::handle_column(rl->right_handle)),
rl->left_handle.w, rl->label.w);
}
}
std::printf("[glfw_demo] upload path %s, gl error on the last frame %d\n",
r != nullptr && r->using_persistent_upload() ? "persistent-mapped ring" : "orphan",