LayoutEngine #15

Closed
opened 2026-04-16 20:06:42 +00:00 by sebastian · 0 comments
Owner

Problem für Tests:

UiPositioner hält eine Referenz auf UiComponent, und UiComponent zieht ClickableUiComponent (→ Application::getInstance().mouse) mit rein. D.h. für einen Test bräuchtest du ein laufendes Fenster.
Die Lösung ist eine kleine Vorab-Änderung: Den Layout-Algorithmus in eine reine Funktion extrahieren:

// Neu: LayoutEngine.h (keine Abhängigkeit zu UiComponent)
namespace LayoutEngine {
    struct NodeLayout {
        LayoutStyle style;
        std::vector<NodeLayout> children;
    };

    struct ComputedLayout {
        Dimensions self;
        std::vector<ComputedLayout> children;
    };

    ComputedLayout compute(const NodeLayout& node, const Dimensions& parent);
}

Dann kann UiPositioner intern LayoutEngine::compute() aufrufen – und die Tests testen nur LayoutEngine.

Problem für Tests: UiPositioner hält eine Referenz auf UiComponent, und UiComponent zieht ClickableUiComponent (→ Application::getInstance().mouse) mit rein. D.h. für einen Test bräuchtest du ein laufendes Fenster. Die Lösung ist eine kleine Vorab-Änderung: Den Layout-Algorithmus in eine reine Funktion extrahieren: ``` // Neu: LayoutEngine.h (keine Abhängigkeit zu UiComponent) namespace LayoutEngine { struct NodeLayout { LayoutStyle style; std::vector<NodeLayout> children; }; struct ComputedLayout { Dimensions self; std::vector<ComputedLayout> children; }; ComputedLayout compute(const NodeLayout& node, const Dimensions& parent); } ``` Dann kann UiPositioner intern LayoutEngine::compute() aufrufen – und die Tests testen nur LayoutEngine.
sebastian added the
refactoring
engine
labels 2026-04-16 20:06:42 +00:00
sebastian added this to the Dicewars project 2026-04-16 21:02:14 +00:00
sebastian self-assigned this 2026-04-17 08:04:35 +00:00
sebastian started working 2026-04-17 08:04:52 +00:00
sebastian stopped working 2026-04-17 09:52:35 +00:00
1 hour 47 minutes
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Total Time Spent: 1 hour 47 minutes
sebastian
1 hour 47 minutes
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Reference: sebastian/Dicewars-Siedler#15
No description provided.