ZenitUI
Retained-mode C++20 UI framework
Loading...
Searching...
No Matches
MockBackend.hpp
Go to the documentation of this file.
1#pragma once
2
3// @backend_name Mock (Headless)
4// @backend_target ZenitUI::MockBackend
5// @backend_role Deterministic headless backend & test fixture (no GPU/window)
6// @backend_features Configurable (Effects, NestedTargets, TargetSubRect)
7// @backend_classes ZenitUI::Test::MockBackend ZenitUI::Test::MockPlatform ZenitUI::Test::MockRenderer ZenitUI::Test::MockAssetProvider ZenitUI::Test::Env
8
15
16#include "ZenitUI.hpp"
17#include "Backend.hpp"
18#include "MockPlatform.hpp"
19#include "MockRenderer.hpp"
20#include "MockAssetProvider.hpp"
21
22#include <memory>
23
24namespace ZenitUI::Test
25{
29
37 struct Env
38 {
39 MockRenderer renderer;
40 MockPlatform platform;
41 MockAssetProvider assets;
42 UIContext ctx;
43
44 Env();
45 ~Env();
46
47 void reset();
48 void frame(std::shared_ptr<Layout> root, float dt = 1.0f / 60.0f);
49 void click(std::shared_ptr<Layout> root, Vec2 pos);
50 };
51
58 class MockBackend final : public IBackend
59 {
60 public:
61 MockPlatform mockPlatform;
62 MockRenderer mockRenderer;
63 MockAssetProvider mockAssets;
64 float fixedDt{1.0f / 60.0f};
65 int maxFrames{1};
66
67 bool init(const WindowConfig &config) override;
68 void shutdown() override;
69 bool pollFrame() override;
70 float deltaTime() const override;
71 void beginDraw(Color clearColor) override;
72 void endDraw() override;
73 std::string_view name() const override;
74
75 IPlatform &platform() override;
76 IRenderer &renderer() override;
78
79 private:
80 int framesPolled_{0};
81 bool running_{false};
82 };
83
85} // namespace ZenitUI::Test
Unified host interface (IBackend) for backend-agnostic ZenitUI apps.
Umbrella include for the whole framework.
Abstract name-based lookup and runtime lifecycle for textures and shaders.
Definition UIContext.hpp:449
Unified window, frame-loop, and subsystem host for interchangeable backends.
Definition Backend.hpp:49
Abstract windowing, timing, input, and clipboard backend.
Definition UIContext.hpp:383
Abstract 2D rendering backend.
Definition UIContext.hpp:106
In-memory IAssetProvider that mints synthetic texture and shader handles without touching the filesys...
Definition MockAssetProvider.hpp:23
Headless IBackend host wrapping MockPlatform, MockRenderer, and MockAssetProvider.
Definition MockBackend.hpp:59
std::string_view name() const override
Short human-readable backend identifier (e.g.
IAssetProvider & assets() override
Access the underlying asset provider.
void endDraw() override
Finish the frame and swap buffers.
IPlatform & platform() override
Access the underlying platform adapter.
bool init(const WindowConfig &config) override
Create the window and graphics context, and bind subsystems to UIContext.
IRenderer & renderer() override
Access the underlying renderer adapter.
void shutdown() override
Release pooled targets, unbind UIContext, and tear down the window/context.
bool pollFrame() override
Pump OS events for the next frame; returns false when the window should close.
float deltaTime() const override
Return the elapsed time in seconds since the previous pollFrame().
void beginDraw(Color clearColor) override
Begin presenting a frame and clear the main framebuffer to clearColor.
Programmable IPlatform for injecting deterministic pointer, keyboard, IME, viewport,...
Definition MockPlatform.hpp:21
Recording IRenderer that tracks draw counts, clip stacks, render targets, dynamic textures,...
Definition MockRenderer.hpp:24
8-bit-per-channel RGBA color, non-premultiplied.
Definition CoreTypes.hpp:78
Per-instance UI context: backends, theme, text engine, frame state, and routing.
Definition UIContext.hpp:725
2D vector with component-wise arithmetic.
Definition CoreTypes.hpp:25
Backend-agnostic window and graphics-context creation parameters.
Definition Backend.hpp:31