diff --git a/editor/CMakeLists.txt b/editor/CMakeLists.txt index 9166f95..9f03213 100644 --- a/editor/CMakeLists.txt +++ b/editor/CMakeLists.txt @@ -3469,3 +3469,13 @@ target_link_libraries(step509_test PRIVATE tree_sitter_javascript tree_sitter_typescript tree_sitter_java tree_sitter_rust tree_sitter_go) +add_executable(step510_test tests/step510_test.cpp) +target_include_directories(step510_test PRIVATE src) +target_link_libraries(step510_test PRIVATE + nlohmann_json::nlohmann_json + unofficial::tree-sitter::tree-sitter + tree_sitter_python tree_sitter_cpp tree_sitter_elisp + tree_sitter_javascript tree_sitter_typescript + tree_sitter_java tree_sitter_rust tree_sitter_go) + +# Step 12: Dear ImGui shell scaffolding created (main.cpp exists but not built due to dependencies) diff --git a/editor/src/PanelBoundaryReliability.h b/editor/src/PanelBoundaryReliability.h new file mode 100644 index 0000000..36fb11d --- /dev/null +++ b/editor/src/PanelBoundaryReliability.h @@ -0,0 +1,140 @@ +#pragma once +// Step 510: Panel Boundaries, Resizers, and Hit-Target Corrections +// Headless geometry model for deterministic resize hit-testing and split-bar +// correction without GUI dependencies. + +#include +#include +#include + +struct PanelRect { + std::string id; + float x = 0.0f; + float y = 0.0f; + float w = 0.0f; + float h = 0.0f; +}; + +struct SplitBar { + std::string id; + bool vertical = true; // vertical split bar between left/right panes + float pos = 0.0f; // x when vertical, y when horizontal + float thickness = 6.0f; + std::string firstPanel; + std::string secondPanel; +}; + +struct HitTargetResult { + bool hit = false; + bool resizeHit = false; + std::string targetId; + std::string reason; +}; + +struct BoundaryFixResult { + std::vector panels; + std::vector bars; + std::vector notes; +}; + +class PanelBoundaryReliability { +public: + static HitTargetResult resolveClick(float mouseX, + float mouseY, + const std::vector& panels, + const std::vector& bars, + float resizePriorityMargin = 2.0f) { + HitTargetResult out; + + for (const auto& bar : bars) { + float half = bar.thickness * 0.5f + resizePriorityMargin; + bool inBand = bar.vertical + ? (mouseX >= bar.pos - half && mouseX <= bar.pos + half) + : (mouseY >= bar.pos - half && mouseY <= bar.pos + half); + if (inBand) { + out.hit = true; + out.resizeHit = true; + out.targetId = bar.id; + out.reason = "resize-priority"; + return out; + } + } + + for (const auto& p : panels) { + if (contains(p, mouseX, mouseY)) { + out.hit = true; + out.resizeHit = false; + out.targetId = p.id; + out.reason = "panel-content"; + return out; + } + } + + out.reason = "none"; + return out; + } + + static BoundaryFixResult normalizeGeometry(const std::vector& inputPanels, + const std::vector& inputBars, + float minPanelSize = 120.0f, + float minBarThickness = 5.0f, + float maxBarThickness = 14.0f) { + BoundaryFixResult out; + out.panels = inputPanels; + out.bars = inputBars; + + for (auto& p : out.panels) { + if (p.w < minPanelSize) { + p.w = minPanelSize; + out.notes.push_back("panel-width-clamped:" + p.id); + } + if (p.h < minPanelSize) { + p.h = minPanelSize; + out.notes.push_back("panel-height-clamped:" + p.id); + } + } + + for (auto& b : out.bars) { + float old = b.thickness; + b.thickness = std::max(minBarThickness, + std::min(maxBarThickness, b.thickness)); + if (b.thickness != old) { + out.notes.push_back("bar-thickness-clamped:" + b.id); + } + } + + return out; + } + + static SplitBar keyboardResize(const SplitBar& bar, + float delta, + float minPos, + float maxPos, + bool fineStep) { + SplitBar out = bar; + float scale = fineStep ? 0.5f : 1.0f; + out.pos = std::max(minPos, std::min(maxPos, bar.pos + delta * scale)); + return out; + } + + static std::vector navigationOrderByBarProximity( + const std::vector& panels, + const SplitBar& bar) { + std::vector> ranked; + for (const auto& p : panels) { + float center = bar.vertical ? (p.x + p.w * 0.5f) : (p.y + p.h * 0.5f); + float dist = std::abs(center - bar.pos); + ranked.push_back({dist, p.id}); + } + std::sort(ranked.begin(), ranked.end(), + [](const auto& a, const auto& b) { return a.first < b.first; }); + std::vector ids; + for (const auto& r : ranked) ids.push_back(r.second); + return ids; + } + +private: + static bool contains(const PanelRect& p, float mx, float my) { + return mx >= p.x && mx <= p.x + p.w && my >= p.y && my <= p.y + p.h; + } +}; diff --git a/editor/tests/step510_test.cpp b/editor/tests/step510_test.cpp new file mode 100644 index 0000000..e7da483 --- /dev/null +++ b/editor/tests/step510_test.cpp @@ -0,0 +1,146 @@ +// Step 510: Panel Boundaries, Resizers, and Hit-Target Corrections (12 tests) + +#include "PanelBoundaryReliability.h" + +#include + +static int passed = 0, failed = 0; +#define TEST(name) { std::cout << " " << #name << "... "; } +#define PASS() { std::cout << "PASS\n"; ++passed; } +#define FAIL(msg) { std::cout << "FAIL: " << msg << "\n"; ++failed; } +#define CHECK(cond, msg) if (!(cond)) { FAIL(msg); return; } else {} + +static std::vector basePanels() { + return { + {"left", 0, 0, 220, 800}, + {"editor", 220, 0, 760, 800}, + {"right", 980, 0, 220, 800} + }; +} + +static std::vector baseBars() { + return { + {"left-editor", true, 220, 6, "left", "editor"}, + {"editor-right", true, 980, 6, "editor", "right"} + }; +} + +void test_resize_band_takes_priority_over_content() { + TEST(resize_band_takes_priority_over_content); + auto hit = PanelBoundaryReliability::resolveClick(221, 100, basePanels(), baseBars()); + CHECK(hit.hit && hit.resizeHit, "expected resize hit"); + CHECK(hit.targetId == "left-editor", "wrong bar target"); + PASS(); +} + +void test_content_hit_when_away_from_split_bar() { + TEST(content_hit_when_away_from_split_bar); + auto hit = PanelBoundaryReliability::resolveClick(400, 100, basePanels(), baseBars()); + CHECK(hit.hit && !hit.resizeHit, "expected content hit"); + CHECK(hit.targetId == "editor", "expected editor panel hit"); + PASS(); +} + +void test_miss_returns_none() { + TEST(miss_returns_none); + auto hit = PanelBoundaryReliability::resolveClick(1300, 900, basePanels(), baseBars()); + CHECK(!hit.hit, "expected miss"); + CHECK(hit.reason == "none", "expected reason none"); + PASS(); +} + +void test_panel_width_is_clamped_to_min() { + TEST(panel_width_is_clamped_to_min); + auto panels = basePanels(); + panels[0].w = 20; + auto fixed = PanelBoundaryReliability::normalizeGeometry(panels, baseBars(), 120); + CHECK(fixed.panels[0].w == 120, "width should be clamped"); + PASS(); +} + +void test_panel_height_is_clamped_to_min() { + TEST(panel_height_is_clamped_to_min); + auto panels = basePanels(); + panels[1].h = 80; + auto fixed = PanelBoundaryReliability::normalizeGeometry(panels, baseBars(), 120); + CHECK(fixed.panels[1].h == 120, "height should be clamped"); + PASS(); +} + +void test_split_bar_thickness_clamped_low() { + TEST(split_bar_thickness_clamped_low); + auto bars = baseBars(); + bars[0].thickness = 1; + auto fixed = PanelBoundaryReliability::normalizeGeometry(basePanels(), bars); + CHECK(fixed.bars[0].thickness == 5, "bar thickness should clamp to min"); + PASS(); +} + +void test_split_bar_thickness_clamped_high() { + TEST(split_bar_thickness_clamped_high); + auto bars = baseBars(); + bars[1].thickness = 40; + auto fixed = PanelBoundaryReliability::normalizeGeometry(basePanels(), bars); + CHECK(fixed.bars[1].thickness == 14, "bar thickness should clamp to max"); + PASS(); +} + +void test_keyboard_resize_moves_split_bar() { + TEST(keyboard_resize_moves_split_bar); + auto moved = PanelBoundaryReliability::keyboardResize(baseBars()[0], 10, 100, 400, false); + CHECK(moved.pos == 230, "split bar should move by delta"); + PASS(); +} + +void test_keyboard_resize_respects_bounds() { + TEST(keyboard_resize_respects_bounds); + auto moved = PanelBoundaryReliability::keyboardResize(baseBars()[0], -500, 150, 400, false); + CHECK(moved.pos == 150, "split bar should clamp to min bound"); + PASS(); +} + +void test_keyboard_resize_fine_step_halves_delta() { + TEST(keyboard_resize_fine_step_halves_delta); + auto moved = PanelBoundaryReliability::keyboardResize(baseBars()[0], 8, 100, 400, true); + CHECK(moved.pos == 224, "fine step should halve delta"); + PASS(); +} + +void test_navigation_order_prefers_panels_near_bar() { + TEST(navigation_order_prefers_panels_near_bar); + auto ids = PanelBoundaryReliability::navigationOrderByBarProximity(basePanels(), baseBars()[0]); + CHECK(!ids.empty(), "expected non-empty order"); + CHECK(ids[0] == "left" || ids[0] == "editor", "nearest should be left or editor"); + PASS(); +} + +void test_normalize_emits_fix_notes() { + TEST(normalize_emits_fix_notes); + auto panels = basePanels(); + auto bars = baseBars(); + panels[0].w = 50; + bars[0].thickness = 2; + auto fixed = PanelBoundaryReliability::normalizeGeometry(panels, bars, 120); + CHECK(!fixed.notes.empty(), "expected fix notes"); + PASS(); +} + +int main() { + std::cout << "Step 510: Panel Boundaries, Resizers, and Hit-Target Corrections\n"; + + test_resize_band_takes_priority_over_content(); // 1 + test_content_hit_when_away_from_split_bar(); // 2 + test_miss_returns_none(); // 3 + test_panel_width_is_clamped_to_min(); // 4 + test_panel_height_is_clamped_to_min(); // 5 + test_split_bar_thickness_clamped_low(); // 6 + test_split_bar_thickness_clamped_high(); // 7 + test_keyboard_resize_moves_split_bar(); // 8 + test_keyboard_resize_respects_bounds(); // 9 + test_keyboard_resize_fine_step_halves_delta(); // 10 + test_navigation_order_prefers_panels_near_bar(); // 11 + test_normalize_emits_fix_notes(); // 12 + + std::cout << "\nResults: " << passed << "/" << (passed + failed) << " passed\n"; + return failed == 0 ? 0 : 1; +} diff --git a/progress.md b/progress.md index c5ec12d..cb9852f 100644 --- a/progress.md +++ b/progress.md @@ -8038,3 +8038,37 @@ startup/session-restore normalization. - `editor/tests/step509_test.cpp` within test-file size guidance (`180` lines) - Header-only architecture and naming conventions remain aligned with `ARCHITECTURE.md` +### Step 510: Panel Boundaries, Resizers, and Hit-Target Corrections +**Status:** PASS (12/12 tests) + +Implements deterministic split-bar hit testing and geometry normalization to +reduce ambiguous click zones where content selection steals resize intent, and +to enforce reliable keyboard/mouse resize behavior. + +**Files added:** +- `editor/src/PanelBoundaryReliability.h` - panel boundary reliability module: + - resize-priority click resolution over overlapping content + - panel minimum-size enforcement and split-bar thickness clamping + - bounded keyboard-driven split-bar resizing with fine-step mode + - proximity-based navigation ordering for panel-focus traversal +- `editor/tests/step510_test.cpp` - 12 tests covering: + - resize-vs-content hit-target priority + - miss-path behavior + - panel width/height minimum clamping + - split-bar thickness lower/upper clamp behavior + - keyboard resize movement, bounds, and fine-step mode + - proximity navigation order and normalization note emission + +**Files modified:** +- `editor/CMakeLists.txt` - `step510_test` target + +**Verification run:** +- `cmake -S editor -B editor/build-native` - PASS +- `cmake --build editor/build-native --target step510_test` - PASS +- `./editor/build-native/step510_test` - PASS (12/12) +- `./editor/build-native/step509_test` - PASS (12/12) regression coverage + +**Architecture gate check:** +- `editor/src/PanelBoundaryReliability.h` within header-size limit (`140` <= `600`) +- `editor/tests/step510_test.cpp` within test-file size guidance (`146` lines) +- Header-only architecture and naming conventions remain aligned with `ARCHITECTURE.md`