Skip to main content

PlatformBackend

Trait PlatformBackend 

Source
pub trait PlatformBackend: WindowController {
    // Required methods
    fn kind(&self) -> PlatformKind;
    fn capabilities(&self) -> PlatformCapabilities;
    fn create_window(
        &mut self,
        config: &WindowConfig,
    ) -> Result<WindowState, PlatformError>;
    fn window_state(&self, id: WindowId) -> Option<WindowState>;
    fn raw_window_handle(&self, id: WindowId) -> RawWindowHandle;
    fn poll_events(&mut self) -> Vec<WindowEvent>;
    fn present_framebuffer(
        &mut self,
        id: WindowId,
        framebuffer: &Framebuffer,
    ) -> Result<(), PlatformError>;
    fn read_clipboard(&self) -> Option<String>;
    fn write_clipboard(&mut self, text: &str) -> Result<(), PlatformError>;
    fn system_theme(&self) -> ThemeMode;

    // Provided method
    fn present_framebuffer_region(
        &mut self,
        id: WindowId,
        framebuffer: &Framebuffer,
        _damage: DamageRegion,
    ) -> Result<(), PlatformError> { ... }
}
Expand description

Unified system abstraction implemented directly over each OS native API (Web, Android, iOS, iPadOS, macOS, Windows, Linux, Headless).

Required Methods§

Source

fn kind(&self) -> PlatformKind

Returns the concrete PlatformKind served by this backend.

§Arguments
  • &Self - Backend reference.
§Returns
  • PlatformKind - Active platform kind.
Source

fn capabilities(&self) -> PlatformCapabilities

Returns the normalized capability matrix for this backend.

§Arguments
  • &Self - Backend reference.
§Returns
  • PlatformCapabilities - Hardware and OS capability flags.
Source

fn create_window( &mut self, config: &WindowConfig, ) -> Result<WindowState, PlatformError>

Creates a native or web window configured by config.

§Arguments
  • &Self - Mutable platform backend.
  • &WindowConfig - Declarative window configuration.
§Returns
  • Result<WindowState, PlatformError> - Initial live window state on success.
Source

fn window_state(&self, id: WindowId) -> Option<WindowState>

Returns the latest WindowState for id, if alive.

§Arguments
  • &Self - Backend reference.
  • WindowId - Window identifier.
§Returns
  • Option<WindowState> - Live window state.
Source

fn raw_window_handle(&self, id: WindowId) -> RawWindowHandle

Returns the ABI-stable RawWindowHandle for hardware GPU surface binding.

§Arguments
  • &Self - Backend reference.
  • WindowId - Window identifier.
§Returns
  • RawWindowHandle - Native OS surface pointer bundle.
Source

fn poll_events(&mut self) -> Vec<WindowEvent>

Drains all pending OS window, input, and lifecycle events since the last poll.

§Arguments
  • &Self - Mutable platform backend.
§Returns
  • Vec<WindowEvent> - Ordered pending events.
Source

fn present_framebuffer( &mut self, id: WindowId, framebuffer: &Framebuffer, ) -> Result<(), PlatformError>

Presents a CPU-rendered RGBA8 Framebuffer directly onto the native window surface.

§Arguments
  • &Self - Mutable platform backend.
  • WindowId - Target window handle.
  • &Framebuffer - Rendered RGBA8 framebuffer.
§Returns
  • Result<(), PlatformError> - Presentation status.
Source

fn read_clipboard(&self) -> Option<String>

Reads the current system clipboard text if available.

§Arguments
  • &Self - Backend reference.
§Returns
  • Option<String> - Clipboard UTF-8 contents.
Source

fn write_clipboard(&mut self, text: &str) -> Result<(), PlatformError>

Writes text into the system clipboard.

§Arguments
  • &Self - Mutable platform backend.
  • &str - UTF-8 text to store.
§Returns
  • Result<(), PlatformError> - Clipboard write status.
Source

fn system_theme(&self) -> ThemeMode

Queries the current operating system theme mode (Light / Dark).

§Arguments
  • &Self - Backend reference.
§Returns
  • ThemeMode - Detected OS appearance mode.

Provided Methods§

Source

fn present_framebuffer_region( &mut self, id: WindowId, framebuffer: &Framebuffer, _damage: DamageRegion, ) -> Result<(), PlatformError>

Presents a damaged sub-region of a CPU-rendered RGBA8 Framebuffer when supported by the backend.

§Arguments
  • &Self - Mutable platform backend.
  • WindowId - Target window handle.
  • &Framebuffer - Rendered RGBA8 framebuffer.
  • DamageRegion - Damaged pixel region updated this frame.
§Returns
  • Result<(), PlatformError> - Presentation status.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl PlatformBackend for HeadlessPlatform

PlatformBackend implementation for HeadlessPlatform.

Source§

impl PlatformBackend for LinuxPlatform

PlatformBackend implementation for native Linux.