pub struct MockToolkit {
pub state: Rc<RefCell<MockState>>,
}Expand description
The mock backend. Cloneable observer half: construct with MockToolkit::new and keep the
returned MockProbe to inspect state after day-core takes ownership of the toolkit.
Fields§
§state: Rc<RefCell<MockState>>Implementations§
Trait Implementations§
Source§impl Platform for MockToolkit
impl Platform for MockToolkit
Source§const TARGET: &'static str = "mock-mock"
const TARGET: &'static str = "mock-mock"
e.g.
"macos-appkit" — the process-constant target id.fn run( self, options: WindowOptions, ready: Box<dyn FnOnce(Self, MockHandle, Size)>, )
Source§fn post(f: Box<dyn FnOnce() + Send>)
fn post(f: Box<dyn FnOnce() + Send>)
Post a closure onto the native main loop. Callable from ANY thread; this is the
single door the reactive scheduler and
Setter deliveries ride (§3.3).§fn post_delayed(ms: u32, f: Box<dyn FnOnce() + Send>)
fn post_delayed(ms: u32, f: Box<dyn FnOnce() + Send>)
Post
f onto the native main loop after (at least) ms milliseconds — the timer
door behind day::sleep (docs/async.md). The default spawns a helper thread that
sleeps and rides [Platform::post] home, which is correct on every threaded
platform with zero backend code; a single-threaded host (web) overrides it with
the platform’s own timer.§fn request_frame(_cb: Box<dyn FnOnce(f64)>)
fn request_frame(_cb: Box<dyn FnOnce(f64)>)
Request a single main-thread callback aligned to the next display refresh (vsync), carrying
the frame timestamp in seconds. The day-core animation driver re-arms it each tick while
animations / game frame-clocks are live and stops requesting when none remain (no idle
wakeups → battery). Main-thread only. A backend without a display link may approximate with a
~16 ms timer. Defaulted no-op: the canvas/self-driven animation path is inert until a backend
provides it (native-widget animation via
AnimSpec is unaffected). (§8.4)§fn locale_hints(&self) -> Vec<String>
fn locale_hints(&self) -> Vec<String>
Ordered OS locale preference list (BCP-47), for fluent-langneg (§12.2).
Source§impl Toolkit for MockToolkit
impl Toolkit for MockToolkit
type Handle = MockHandle
fn capability(&self, cap: Cap) -> Support
fn realize( &mut self, kind: PieceKind, props: &dyn Any, id: NodeId, ) -> MockHandle
fn update( &mut self, h: &MockHandle, kind: PieceKind, patch: &dyn Any, anim: Option<&AnimSpec>, )
Source§fn release(&mut self, h: MockHandle)
fn release(&mut self, h: MockHandle)
Called from the turn-boundary release queue; backends may defer destruction further.
fn insert(&mut self, parent: &MockHandle, child: &MockHandle, index: usize)
fn remove(&mut self, parent: &MockHandle, child: &MockHandle)
fn move_child(&mut self, parent: &MockHandle, child: &MockHandle, to: usize)
fn measure(&mut self, h: &MockHandle, kind: PieceKind, p: Proposal) -> Size
fn set_frame(&mut self, h: &MockHandle, frame: Rect, anim: Option<&AnimSpec>)
fn set_opacity(&mut self, h: &MockHandle, opacity: f64, anim: Option<&AnimSpec>)
fn set_transform( &mut self, h: &MockHandle, t: Transform, _size: Size, anim: Option<&AnimSpec>, )
fn set_selectable(&mut self, h: &MockHandle, selectable: bool)
fn set_scroll_content(&mut self, h: &MockHandle, content: Size)
fn scroll_to(&mut self, h: &MockHandle, target: Rect, _animated: bool)
fn scroll_offset(&mut self, h: &MockHandle) -> Point
fn enable_gesture(&mut self, h: &MockHandle, _node: NodeId, kind: GestureKind)
fn focus(&mut self, h: &MockHandle, _node: NodeId, focused: bool)
fn set_event_sink(&mut self, sink: EventSink)
fn attach_list(&mut self, host: &MockHandle, source: ListSource)
fn adopt(&mut self, raw: RawHandle) -> MockHandle
fn set_a11y(&mut self, h: &MockHandle, a11y: &A11yProps)
fn replay(&mut self, h: &MockHandle, ops: &[DrawOp], size: Size)
fn snapshot_window(&mut self) -> Result<Vec<u8>, String>
Source§fn open_window(
&mut self,
id: NodeId,
options: &WindowOptions,
kind: WindowKind,
) -> WindowOpenReply<MockHandle>
fn open_window( &mut self, id: NodeId, options: &WindowOptions, kind: WindowKind, ) -> WindowOpenReply<MockHandle>
Open a native OS window per
options + kind: create and show the window, wire ITS
events to id — WindowResized (content size, points), WindowClosed (after the
native close), WindowFocused (key/active changes) — and answer with its CONTENT
container handle, the same contract as the ready root container. Backends whose
window creation is asynchronous (a scene, an activity, an ability) answer
[WindowOpenReply::Pending] and complete later through
day_core::finish_window_open(id, raw, size) (the [Toolkit::adopt] seam).
The default answers Unsupported — day-core then presents the content as a
fullscreen cover in the primary window instead.Source§fn close_window(&mut self, host: &MockHandle)
fn close_window(&mut self, host: &MockHandle)
Close the native window whose CONTENT container is
host (a handle open_window
produced). Asynchronous: the platform confirms with Event::WindowClosed on the
window’s root node, and day-core tears the subtree down THEN. Idempotent; unknown
hosts are ignored. Never called with the primary window’s container.Source§fn focus_window(&mut self, host: &MockHandle)
fn focus_window(&mut self, host: &MockHandle)
Bring the window whose CONTENT container is
host to front and make it key/active —
the focus half of open-or-focus singleton windows. Default no-op.Source§fn set_window_title(&mut self, host: &MockHandle, title: &str)
fn set_window_title(&mut self, host: &MockHandle, title: &str)
Retitle the window whose CONTENT container is
host. Default no-op.Source§fn snapshot_window_of(&mut self, host: &MockHandle) -> Result<Vec<u8>, String>
fn snapshot_window_of(&mut self, host: &MockHandle) -> Result<Vec<u8>, String>
Snapshot the window whose CONTENT container is
host (the dayscript screenshot
step’s window: target). The default answers the primary snapshot, so backends that
never open windows stay correct without changes.fn present(&mut self, req: u64, spec: &PresentSpec)
fn dismiss(&mut self, req: u64)
Source§fn open_url(&mut self, url: &str)
fn open_url(&mut self, url: &str)
Open
url in the platform’s default handler — the system browser for http(s), the mail
client for mailto:, etc. Backs the link piece. Fire and
forget: there is no result, and an unopenable URL is ignored. The default no-ops so a
backend that hasn’t wired it up still compiles.Source§fn defer_system_gestures(&mut self, edges: Edges)
fn defer_system_gestures(&mut self, edges: Edges)
Ask the OS to require a second swipe for its edge gestures on
edges (docs/cover.md) —
the union requested by every mounted defers_system_gestures modifier, re-sent whenever
that set changes (Edges::NONE when the last one unmounts). iOS defers the home
indicator / notification edges; Android enters swipe-to-reveal immersive mode while
non-empty. The default no-ops (desktop has no system edge gestures).The application menu (macOS/Windows/Linux menu bar; the app-bar overflow on Android; the
UIMenuBuilder main menu on iPadOS/Catalyst). Replaces any previous app menu.
A context menu for
h, shown on secondary-click (desktop) or long-press (mobile). Passing an
empty slice removes it.fn supports_lifecycle(&self, _phase: Lifecycle) -> bool
Source§fn read_a11y(&self, h: &MockHandle) -> A11ySnapshot
fn read_a11y(&self, h: &MockHandle) -> A11ySnapshot
Read a widget’s ACTUAL native accessibility properties for
a11y_audit (§14.2) to diff
against Day’s expectation. Default: unsupported (found = false) — the audit skips the node.Source§fn ui_idle(&mut self) -> bool
fn ui_idle(&mut self) -> bool
Whether the UI has settled — no native transition (modal present/dismiss, nav push)
still animating. The dayscript
screenshot step polls this before capturing so shots
never catch a half-faded dialog or half-pushed page. Backends without async
transitions (or without a way to know) report true.fn on_suspend(&mut self)
fn on_resume(&mut self)
fn on_memory_warning(&mut self)
fn set_route(&mut self, _route: &str)
§fn set_toolbar(&mut self, _h: &Self::Handle, _items: &[ToolbarItem])
fn set_toolbar(&mut self, _h: &Self::Handle, _items: &[ToolbarItem])
Install
items as the window’s toolbar, replacing any previous one. An empty slice removes
it. Items are identified by [ToolbarItem::id]; a backend that can reuse the native item
already carrying an id should, so a replace does not drop the search field’s focus.§fn update_toolbar(&mut self, _h: &Self::Handle, _patch: &ToolbarPatch)
fn update_toolbar(&mut self, _h: &Self::Handle, _patch: &ToolbarPatch)
Apply a targeted change to one live toolbar item — the path a bound signal writes through,
so syncing a search field does not rebuild the bar. No-op if the item is not present.
§fn dark_mode(&mut self) -> bool
fn dark_mode(&mut self) -> bool
Whether the platform is rendering in DARK appearance right now. Apps painting
custom surfaces (opaque overlay panels, scrims) branch on this so their fills track
the theme the DEFAULT text colors already follow — hardcoding either theme’s
surface produces dark-on-dark or light-on-light text on the other. Queried at
build time (a piece rebuilt after a theme change re-queries). The default honors a
DAY_THEME launch override and otherwise answers light.§fn set_appearance(&mut self, _dark: Option<bool>)
fn set_appearance(&mut self, _dark: Option<bool>)
App-level appearance override:
Some(true) forces dark, Some(false) forces light,
None returns to following the system. Backends restyle their native widgets in
place and answer the override from dark_mode; app-painted
surfaces pick it up on their next rebuild. Cap::Appearance reports whether the
backend honors this; the default ignores the call.Auto Trait Implementations§
impl Freeze for MockToolkit
impl !RefUnwindSafe for MockToolkit
impl !Send for MockToolkit
impl !Sync for MockToolkit
impl Unpin for MockToolkit
impl UnsafeUnpin for MockToolkit
impl !UnwindSafe for MockToolkit
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more