ZenitUI
Retained-mode C++20 UI framework
Loading...
Searching...
No Matches
ZenitUI::Test::MockPlatform Class Referencefinal

Programmable IPlatform for injecting deterministic pointer, keyboard, IME, viewport, and clipboard state in tests. More...

#include <MockPlatform.hpp>

Inheritance diagram for ZenitUI::Test::MockPlatform:
[legend]

Public Member Functions

void reset ()
IPlatform Overrides
Vec2 viewportSize () override
 Return the current window/surface dimensions in logical pixels.
double time () override
 Return a monotonic clock timestamp in seconds.
float dpiScale () override
 Return the physical-to-logical DPI scale factor (e.g.
EdgeInsets safeArea () override
 Return screen safe-area insets in logical pixels (notches, rounded corners, system bars).
ModifierState modifiers () override
 Return the current state of modifier keys (shift, ctrl, alt, super).
void setCursor (CursorShape cursor) override
 Request the OS/windowing system to display the given cursor shape.
PointerState pointer () override
 Return the current pointer position (logical pixels), scroll wheel delta, and button states.
InputEvents pollInputEvents () override
 Drain and return keyboard events queued since the previous frame.
void setClipboardText (const std::string &text) override
 Copy UTF-8 text to the operating system clipboard.
std::string getClipboardText () override
 Read UTF-8 text from the operating system clipboard (empty string if unavailable).
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 candidate windows appear at the caret.
Test Input Injection Helpers
void setComposition (std::string text, int cursor=-1, int selectionLen=0)
void commitComposition (std::string_view utf8)
void cancelComposition ()
void moveMouse (Vec2 pos)
void pressLeft (Vec2 pos)
void holdLeft (Vec2 pos)
void releaseLeft (Vec2 pos)
void pressRight (Vec2 pos)
void releaseRight (Vec2 pos)
void pressMiddle (Vec2 pos)
void holdMiddle (Vec2 pos)
void releaseMiddle (Vec2 pos)
void scrollWheel (float delta)
void pressKey (int key)
void holdKey (int key)
void typeChar (int codepoint)

Public Attributes

Vec2 viewport {800.0f, 600.0f}
double currentTime {0.0}
ModifierState mods {}
PointerState nextPointer {}
InputEvents nextEvents {}
EdgeInsets safe {}
std::string clipboardData
CursorShape currentCursor {CursorShape::Default}
int setCursorCount {0}
Rect textInputRect {0.0f, 0.0f, 0.0f, 0.0f}
float textInputCursorOffset {0.0f}
int setTextInputRectCount {0}

Detailed Description

Programmable IPlatform for injecting deterministic pointer, keyboard, IME, viewport, and clipboard state in tests.

Member Function Documentation

◆ dpiScale()

float ZenitUI::Test::MockPlatform::dpiScale ( )
overridevirtual

Return the physical-to-logical DPI scale factor (e.g.

1.0f on standard displays, 2.0f on Retina).

Implements ZenitUI::IPlatform.

◆ getClipboardText()

std::string ZenitUI::Test::MockPlatform::getClipboardText ( )
overridevirtual

Read UTF-8 text from the operating system clipboard (empty string if unavailable).

Implements ZenitUI::IPlatform.

◆ modifiers()

ModifierState ZenitUI::Test::MockPlatform::modifiers ( )
overridevirtual

Return the current state of modifier keys (shift, ctrl, alt, super).

Implements ZenitUI::IPlatform.

◆ pointer()

PointerState ZenitUI::Test::MockPlatform::pointer ( )
overridevirtual

Return the current pointer position (logical pixels), scroll wheel delta, and button states.

Edge-triggered fields (ButtonState::pressed, ButtonState::released, PointerState::wheelY) must fire for one frame only; ButtonState::down stays true while held.

Implements ZenitUI::IPlatform.

◆ pollInputEvents()

InputEvents ZenitUI::Test::MockPlatform::pollInputEvents ( )
overridevirtual

Drain and return keyboard events queued since the previous frame.

InputEvents::chars and InputEvents::keys are edge-triggered (one frame); InputEvents::held lists keys currently held down for repeat handling.

Implements ZenitUI::IPlatform.

◆ safeArea()

EdgeInsets ZenitUI::Test::MockPlatform::safeArea ( )
overridevirtual

Return screen safe-area insets in logical pixels (notches, rounded corners, system bars).

Implements ZenitUI::IPlatform.

◆ setClipboardText()

void ZenitUI::Test::MockPlatform::setClipboardText ( const std::string & text)
overridevirtual

Copy UTF-8 text to the operating system clipboard.

Implements ZenitUI::IPlatform.

◆ setCursor()

void ZenitUI::Test::MockPlatform::setCursor ( CursorShape )
overridevirtual

Request the OS/windowing system to display the given cursor shape.

Reimplemented from ZenitUI::IPlatform.

◆ setTextInputRect()

void ZenitUI::Test::MockPlatform::setTextInputRect ( Rect ,
float = 0.0f )
overridevirtual

Inform the OS IME of the active text-input rect and caret offset (in logical window coordinates) so candidate windows appear at the caret.

Pass an empty rect (width <= 0 || height <= 0) when no text widget is focused.

Reimplemented from ZenitUI::IPlatform.

◆ time()

double ZenitUI::Test::MockPlatform::time ( )
overridevirtual

Return a monotonic clock timestamp in seconds.

Implements ZenitUI::IPlatform.

◆ viewportSize()

Vec2 ZenitUI::Test::MockPlatform::viewportSize ( )
overridevirtual

Return the current window/surface dimensions in logical pixels.

Implements ZenitUI::IPlatform.


The documentation for this class was generated from the following file: