ZenitUI
Retained-mode C++20 UI framework
Loading...
Searching...
No Matches
MockPlatform.hpp
1#pragma once
2
3#include "UIContext.hpp"
4
5#include <string>
6#include <string_view>
7
8namespace ZenitUI::Test
9{
13
20 class MockPlatform final : public IPlatform
21 {
22 public:
23 Vec2 viewport{800.0f, 600.0f};
24 double currentTime{0.0};
25 ModifierState mods{};
26 PointerState nextPointer{};
27 InputEvents nextEvents{};
28 EdgeInsets safe{};
29 std::string clipboardData;
30 CursorShape currentCursor{CursorShape::Default};
31 int setCursorCount{0};
32 Rect textInputRect{0.0f, 0.0f, 0.0f, 0.0f};
33 float textInputCursorOffset{0.0f};
34 int setTextInputRectCount{0};
35
36 void reset();
37
40 Vec2 viewportSize() override;
41 double time() override;
42 float dpiScale() override;
43 EdgeInsets safeArea() override;
45 void setCursor(CursorShape cursor) override;
48 void setClipboardText(const std::string &text) override;
49 std::string getClipboardText() override;
50 void setTextInputRect(Rect r, float cursorXOffset = 0.0f) override;
52
55 void setComposition(std::string text, int cursor = -1, int selectionLen = 0);
56 void commitComposition(std::string_view utf8);
57 void cancelComposition();
58
59 void moveMouse(Vec2 pos);
60 void pressLeft(Vec2 pos);
61 void holdLeft(Vec2 pos);
62 void releaseLeft(Vec2 pos);
63 void pressRight(Vec2 pos);
64 void releaseRight(Vec2 pos);
65 void pressMiddle(Vec2 pos);
66 void holdMiddle(Vec2 pos);
67 void releaseMiddle(Vec2 pos);
68 void scrollWheel(float delta);
69 void pressKey(int key);
70 void holdKey(int key);
71 void typeChar(int codepoint);
73
74 private:
75 void setButton(MouseButton btn, Vec2 pos, bool down, bool pressed, bool released);
76 };
77
79} // namespace ZenitUI::Test
Per-application state: renderer, platform, pointer, focus, portals.
Abstract windowing, timing, input, and clipboard backend.
Definition UIContext.hpp:383
Programmable IPlatform for injecting deterministic pointer, keyboard, IME, viewport,...
Definition MockPlatform.hpp:21
ModifierState modifiers() override
Return the current state of modifier keys (shift, ctrl, alt, super).
double time() override
Return a monotonic clock timestamp in seconds.
EdgeInsets safeArea() override
Return screen safe-area insets in logical pixels (notches, rounded corners, system bars).
PointerState pointer() override
Return the current pointer position (logical pixels), scroll wheel delta, and button states.
void setClipboardText(const std::string &text) override
Copy UTF-8 text to the operating system clipboard.
void setTextInputRect(Rect r, float cursorXOffset=0.0f) override
Inform the OS IME of the active text-input rect and caret offset (in logical window coordinates) so c...
std::string getClipboardText() override
Read UTF-8 text from the operating system clipboard (empty string if unavailable).
InputEvents pollInputEvents() override
Drain and return keyboard events queued since the previous frame.
Vec2 viewportSize() override
Return the current window/surface dimensions in logical pixels.
void setCursor(CursorShape cursor) override
Request the OS/windowing system to display the given cursor shape.
float dpiScale() override
Return the physical-to-logical DPI scale factor (e.g.
MouseButton
Mouse buttons tracked by the input system.
Definition CoreTypes.hpp:361
CursorShape
Standard OS cursor shapes requested via ZStyle cursor: and IPlatform::setCursor.
Definition UIEnums.hpp:61
@ Default
Standard arrow cursor.
Definition UIEnums.hpp:63
Four-sided edge inset (used for padding, margin, borders).
Definition CoreTypes.hpp:62
One frame's worth of keyboard input.
Definition CoreTypes.hpp:437
Keyboard modifier snapshot.
Definition CoreTypes.hpp:390
Pointer position, wheel delta, and per-button state for one frame.
Definition CoreTypes.hpp:378
Axis-aligned rectangle in screen coordinates.
Definition CoreTypes.hpp:46
2D vector with component-wise arithmetic.
Definition CoreTypes.hpp:25