Skip to main content

PlatformWindow

Trait PlatformWindow 

Source
pub trait PlatformWindow: HasWindowHandle + HasDisplayHandle {
Show 102 methods // Required methods fn bounds(&self) -> Bounds<Pixels>; fn is_maximized(&self) -> bool; fn window_bounds(&self) -> WindowBounds; fn content_size(&self) -> Size<Pixels>; fn resize(&mut self, size: Size<Pixels>); fn scale_factor(&self) -> f32; fn appearance(&self) -> WindowAppearance; fn display(&self) -> Option<Rc<dyn PlatformDisplay>>; fn mouse_position(&self) -> Point<Pixels>; fn modifiers(&self) -> Modifiers; fn capslock(&self) -> Capslock; fn set_input_handler(&mut self, input_handler: PlatformInputHandler); fn take_input_handler(&mut self) -> Option<PlatformInputHandler>; fn prompt( &self, level: PromptLevel, msg: &str, detail: Option<&str>, answers: &[PromptButton], ) -> Option<Receiver<usize>>; fn activate(&self, token: Option<&str>) -> bool; fn is_active(&self) -> bool; fn visibility(&self) -> WindowVisibility; fn is_hovered(&self) -> bool; fn background_appearance(&self) -> WindowBackgroundAppearance; fn set_title(&mut self, title: &str); fn set_background_appearance( &self, background_appearance: WindowBackgroundAppearance, ); fn minimize(&self); fn zoom(&self); fn toggle_fullscreen(&self); fn is_fullscreen(&self) -> bool; fn on_request_frame(&self, callback: Box<dyn FnMut(RequestFrameOptions)>); fn on_input( &self, callback: Box<dyn FnMut(PlatformInput) -> DispatchEventResult>, ); fn on_active_status_change(&self, callback: Box<dyn FnMut(bool)>); fn on_visibility_change(&self, callback: Box<dyn FnMut(WindowVisibility)>); fn on_hover_status_change(&self, callback: Box<dyn FnMut(bool)>); fn on_resize(&self, callback: Box<dyn FnMut(Size<Pixels>, f32)>); fn on_moved(&self, callback: Box<dyn FnMut()>); fn on_display_changed(&self, callback: Box<dyn FnMut()>); fn on_should_close(&self, callback: Box<dyn FnMut() -> bool>); fn on_hit_test_window_control( &self, callback: Box<dyn FnMut() -> Option<WindowControlArea>>, ); fn on_close(&self, callback: Box<dyn FnOnce()>); fn on_appearance_changed(&self, callback: Box<dyn FnMut()>); fn draw(&self, scene: &Scene); fn sprite_atlas(&self) -> Arc<dyn PlatformAtlas> ⓘ; fn is_subpixel_rendering_supported(&self) -> bool; fn gpu_specs(&self) -> Option<GpuSpecs>; fn update_ime_position(&self, _bounds: Bounds<Pixels>); // Provided methods fn visual_viewport_bounds(&self) -> Bounds<Pixels> { ... } fn on_visual_viewport_changed(&self, _callback: Box<dyn FnMut()>) { ... } fn prepare_frame(&self) -> bool { ... } fn set_text_input_configuration( &mut self, _configuration: TextInputConfiguration, ) { ... } fn request_attention(&self) { ... } fn set_visible(&self, _visible: bool) { ... } fn frame_waker(&self) -> Option<Rc<dyn Fn()>> { ... } fn on_button_layout_changed(&self, _callback: Box<dyn FnMut()>) { ... } fn schedule_frame(&self) { ... } fn get_title(&self) -> String { ... } fn tabbed_windows(&self) -> Option<Vec<SystemWindowTab>> { ... } fn tab_bar_visible(&self) -> bool { ... } fn set_edited(&mut self, _edited: bool) { ... } fn set_document_path(&self, _path: Option<&Path>) { ... } fn toggle_simple_fullscreen(&self) { ... } fn is_simple_fullscreen(&self) -> bool { ... } fn show_character_palette(&self) { ... } fn titlebar_double_click(&self, _is_resizable: bool, _is_minimizable: bool) { ... } fn on_move_tab_to_new_window(&self, _callback: Box<dyn FnMut()>) { ... } fn on_merge_all_windows(&self, _callback: Box<dyn FnMut()>) { ... } fn on_select_previous_tab(&self, _callback: Box<dyn FnMut()>) { ... } fn on_select_next_tab(&self, _callback: Box<dyn FnMut()>) { ... } fn on_toggle_tab_bar(&self, _callback: Box<dyn FnMut()>) { ... } fn merge_all_windows(&self) { ... } fn move_tab_to_new_window(&self) { ... } fn toggle_window_tab_overview(&self) { ... } fn set_tabbing_identifier(&self, _identifier: Option<String>) { ... } fn native_window_state(&self) -> Option<Vec<u8>> { ... } fn restore_native_window_state(&self, _state: &[u8]) { ... } fn inner_window_bounds(&self) -> WindowBounds { ... } fn request_decorations(&self, _decorations: WindowDecorations) { ... } fn show_window_menu(&self, _position: Point<Pixels>) { ... } fn start_window_move(&self) { ... } fn can_start_external_drag(&self) -> bool { ... } fn start_external_drag(&self, _payload: &ExternalDragPayload) -> bool { ... } fn start_window_resize(&self, _edge: ResizeEdge) { ... } fn set_exclusive_zone(&self, _zone: Pixels) { ... } fn set_exclusive_edge(&self, _edge: Anchor) { ... } fn set_input_region(&self, _region: Option<&[Bounds<Pixels>]>) { ... } fn window_decorations(&self) -> Decorations { ... } fn set_app_id(&mut self, _app_id: &str) { ... } fn map_window(&mut self) -> Result<()> { ... } fn window_controls(&self) -> WindowControls { ... } fn set_client_inset(&self, _inset: Pixels) { ... } fn gpu_context(&self) -> Option<Box<dyn Any>> { ... } fn gpu_context_info(&self) -> Option<Box<dyn Any>> { ... } fn gpu_device_lost(&self) -> Option<bool> { ... } fn insets(&self) -> WindowInsets { ... } fn on_insets_changed(&self, _callback: Box<dyn FnMut(WindowInsets)>) { ... } fn set_back_handler(&self, _callback: Box<dyn FnMut()>) { ... } fn set_back_enabled(&self, _enabled: bool) { ... } fn show_soft_keyboard(&self) { ... } fn hide_soft_keyboard(&self) { ... } fn text_input_state_changed(&self, _change: TextInputStateChange) { ... } fn play_system_bell(&self) { ... } fn a11y_init(&self, _callbacks: A11yCallbacks) { ... } fn a11y_tree_update(&self, _tree_update: TreeUpdate) { ... } fn a11y_update_window_bounds(&self) { ... } fn as_test(&mut self) -> Option<&mut TestWindow> { ... } fn render_to_image(&self, _scene: &Scene) -> Result<RgbaImage> { ... }
}
Expand description

The native window that GPUI draws into, implemented by each backend.

App::open_window creates one through Platform::open_window for each Window. Application code doesn’t call these methods directly. Window and the Platform wrap them. Each backend implements the trait for its windowing system. Methods with a default body are optional, and the default is the behavior for a platform that lacks the feature.

Methods that a platform doesn’t support are commented with the platform that does.

Required Methods§

Source

fn bounds(&self) -> Bounds<Pixels>

Returns the window’s frame in screen coordinates, in logical pixels.

Source

fn is_maximized(&self) -> bool

Returns whether the window is maximized.

Source

fn window_bounds(&self) -> WindowBounds

Returns the window’s state, and the bounds to restore when it leaves that state.

Source

fn content_size(&self) -> Size<Pixels>

Returns the drawable size, excluding the titlebar, in logical pixels.

Source

fn resize(&mut self, size: Size<Pixels>)

Resizes the window’s content area to size, in logical pixels.

Source

fn scale_factor(&self) -> f32

Returns the number of device pixels per logical pixel.

Source

fn appearance(&self) -> WindowAppearance

Returns the window’s light or dark appearance.

Source

fn display(&self) -> Option<Rc<dyn PlatformDisplay>>

Returns the display the window is on, or None if the platform can’t tell.

Source

fn mouse_position(&self) -> Point<Pixels>

Returns the mouse position in window coordinates, in logical pixels.

Source

fn modifiers(&self) -> Modifiers

Returns the modifier keys currently held down.

Source

fn capslock(&self) -> Capslock

Returns the state of the Caps Lock key.

Source

fn set_input_handler(&mut self, input_handler: PlatformInputHandler)

Installs the handler that receives text input for the focused element.

Source

fn take_input_handler(&mut self) -> Option<PlatformInputHandler>

Removes and returns the installed input handler.

Source

fn prompt( &self, level: PromptLevel, msg: &str, detail: Option<&str>, answers: &[PromptButton], ) -> Option<Receiver<usize>>

Shows a native alert or prompt with answers as its buttons.

The returned receiver yields the index in answers of the button the user chose. Returns None when the platform can’t show a prompt. The web backend always returns None.

Source

fn activate(&self, token: Option<&str>) -> bool

Request activation, optionally using an externally supplied token. Returns whether a request was sent, not whether focus was granted.

Source

fn is_active(&self) -> bool

Returns whether this window has keyboard focus.

Source

fn visibility(&self) -> WindowVisibility

The current WindowVisibility. Read once when the window is created; afterwards changes arrive through Self::on_visibility_change.

Source

fn is_hovered(&self) -> bool

Returns whether the mouse is over this window.

Source

fn background_appearance(&self) -> WindowBackgroundAppearance

Returns how the window background is drawn.

Source

fn set_title(&mut self, title: &str)

Sets the window title.

Source

fn set_background_appearance( &self, background_appearance: WindowBackgroundAppearance, )

Sets how the window background is drawn: opaque, transparent or blurred.

Source

fn minimize(&self)

Minimizes the window. The web backend logs a warning and does nothing.

Source

fn zoom(&self)

Zooms the window with the platform’s zoom behavior. The web backend logs a warning and does nothing.

Source

fn toggle_fullscreen(&self)

Enters fullscreen, or leaves it if the window is already fullscreen.

Source

fn is_fullscreen(&self) -> bool

Returns whether the window is fullscreen.

Source

fn on_request_frame(&self, callback: Box<dyn FnMut(RequestFrameOptions)>)

Registers the callback that draws a frame when the platform asks for one.

Source

fn on_input( &self, callback: Box<dyn FnMut(PlatformInput) -> DispatchEventResult>, )

Registers the callback that receives input events. Its return value tells the platform whether GPUI handled the event.

Source

fn on_active_status_change(&self, callback: Box<dyn FnMut(bool)>)

Registers the callback run when the window gains or loses focus. It receives true when the window is active.

Source

fn on_visibility_change(&self, callback: Box<dyn FnMut(WindowVisibility)>)

Registers the callback invoked when Self::visibility changes. Only transitions are reported; the callback runs on the main thread outside of any window update.

Source

fn on_hover_status_change(&self, callback: Box<dyn FnMut(bool)>)

Registers the callback run when the mouse enters or leaves the window. It receives true on enter.

Source

fn on_resize(&self, callback: Box<dyn FnMut(Size<Pixels>, f32)>)

Registers the callback run when the content size or scale factor changes. It receives the new size and the scale factor.

Source

fn on_moved(&self, callback: Box<dyn FnMut()>)

Registers the callback run when the window moves.

Source

fn on_display_changed(&self, callback: Box<dyn FnMut()>)

Registers the callback invoked when the window moves to another display. Calls may be spurious. The callback runs on the main thread outside of any window update.

Source

fn on_should_close(&self, callback: Box<dyn FnMut() -> bool>)

Registers the callback run when the user asks to close the window. Return false to keep it open.

Source

fn on_hit_test_window_control( &self, callback: Box<dyn FnMut() -> Option<WindowControlArea>>, )

Registers the callback the platform calls to find out which titlebar control, if any, the mouse is over.

Source

fn on_close(&self, callback: Box<dyn FnOnce()>)

Registers the callback run once the window has closed.

Source

fn on_appearance_changed(&self, callback: Box<dyn FnMut()>)

Registers the callback run when the window’s appearance changes.

Source

fn draw(&self, scene: &Scene)

Draws scene into the window. GPUI calls this once per frame.

Source

fn sprite_atlas(&self) -> Arc<dyn PlatformAtlas> ⓘ

Returns the atlas that stores the glyph and image textures for this window.

Source

fn is_subpixel_rendering_supported(&self) -> bool

Returns whether the renderer supports subpixel (LCD) text antialiasing. macOS returns false.

Source

fn gpu_specs(&self) -> Option<GpuSpecs>

Returns the GPU’s name and driver details, or None if they’re unavailable.

Source

fn update_ime_position(&self, _bounds: Bounds<Pixels>)

Moves the input method’s candidate window next to bounds, in window coordinates.

Provided Methods§

Source

fn visual_viewport_bounds(&self) -> Bounds<Pixels>

Returns the visible viewport in logical pixels relative to the content origin.

This may be smaller or offset when a keyboard or zoom obscures content; it must not change the full layout size returned by content_size. Implementations should return a frame snapshot, not query platform layout here.

Source

fn on_visual_viewport_changed(&self, _callback: Box<dyn FnMut()>)

Registers a callback when visible geometry may have changed.

This requests a frame; backends can sample the new viewport and safe-area geometry in prepare_frame rather than updating it inside the callback.

Source

fn prepare_frame(&self) -> bool

Samples platform geometry before a draw, returning whether view caches must be invalidated.

Geometry getters must remain consistent throughout the ensuing draw. Do not invoke callbacks here: GPUI is already updating this window.

Source

fn set_text_input_configuration( &mut self, _configuration: TextInputConfiguration, )

Apply the focused text region’s TextInputConfiguration to the platform’s text input session (e.g. attributes of the hidden editable element on web). Called only when the configuration changes, because reconfiguring a live input session can restart the IME connection.

Source

fn request_attention(&self)

Requests that the operating system draw attention to this window.

Source

fn set_visible(&self, _visible: bool)

Show or hide the window without explicitly requesting focus.

The default implementation does nothing for platforms that do not support changing window visibility at runtime.

Source

fn frame_waker(&self) -> Option<Rc<dyn Fn()>>

Returns a function that wakes the event loop to draw a frame, or None if the platform doesn’t provide one.

Source

fn on_button_layout_changed(&self, _callback: Box<dyn FnMut()>)

Registers the callback run when the titlebar button layout changes. The default does nothing.

Source

fn schedule_frame(&self)

Asks the platform to request another frame soon. The default does nothing.

Source

fn get_title(&self) -> String

Returns the window title. macOS and the Linux headless window override this. The default returns an empty string.

Source

fn tabbed_windows(&self) -> Option<Vec<SystemWindowTab>>

Returns the windows in this window’s native tab group, or None if the window isn’t tabbed. macOS only.

Source

fn tab_bar_visible(&self) -> bool

Returns whether the native tab bar is visible. macOS only.

Source

fn set_edited(&mut self, _edited: bool)

Marks the window’s document as edited or unedited. macOS only.

Source

fn set_document_path(&self, _path: Option<&Path>)

Sets the document path that the titlebar shows for the window. macOS only.

Source

fn toggle_simple_fullscreen(&self)

Toggles simple fullscreen, which fills the screen without creating a new Space. macOS only.

Source

fn is_simple_fullscreen(&self) -> bool

Returns whether the window is in simple fullscreen. macOS only.

Source

fn show_character_palette(&self)

Show the platform character palette.

The default implementation logs a warning when the backend does not support showing a character palette.

Source

fn titlebar_double_click(&self, _is_resizable: bool, _is_minimizable: bool)

Runs the titlebar double-click action. macOS only, and the default does nothing.

Source

fn on_move_tab_to_new_window(&self, _callback: Box<dyn FnMut()>)

Registers the callback for the Move Tab to New Window action. macOS only.

Source

fn on_merge_all_windows(&self, _callback: Box<dyn FnMut()>)

Registers the callback for the Merge All Windows action. macOS only.

Source

fn on_select_previous_tab(&self, _callback: Box<dyn FnMut()>)

Registers the callback for selecting the previous tab. macOS only.

Source

fn on_select_next_tab(&self, _callback: Box<dyn FnMut()>)

Registers the callback for selecting the next tab. macOS only.

Source

fn on_toggle_tab_bar(&self, _callback: Box<dyn FnMut()>)

Registers the callback for showing or hiding the tab bar. macOS only.

Source

fn merge_all_windows(&self)

Merges all windows into one tab group. macOS only.

Source

fn move_tab_to_new_window(&self)

Moves this window’s tab into a new window. macOS only.

Source

fn toggle_window_tab_overview(&self)

Shows or hides the tab overview. macOS only.

Source

fn set_tabbing_identifier(&self, _identifier: Option<String>)

Sets the identifier that groups windows into one native tab group. macOS only.

Source

fn native_window_state(&self) -> Option<Vec<u8>>

Captures opaque, platform-specific state for restoring this native window later.

Returns None when the backend has no restorable state. The bytes are only meaningful to the backend that produced them; the default implementation returns None.

Source

fn restore_native_window_state(&self, _state: &[u8])

Restores state previously returned by PlatformWindow::native_window_state.

The default implementation does nothing on platforms without native state restoration.

Source

fn inner_window_bounds(&self) -> WindowBounds

Returns the window’s state and bounds, excluding decorations. Defaults to PlatformWindow::window_bounds.

Source

fn request_decorations(&self, _decorations: WindowDecorations)

Asks for server-side or client-side decorations. Linux only.

Source

fn show_window_menu(&self, _position: Point<Pixels>)

Shows the window menu at position, in logical pixels. Linux only.

Source

fn start_window_move(&self)

Starts an interactive move, as if the user dragged the titlebar. Implemented on macOS, Windows and Linux; the web backend does nothing.

Source

fn can_start_external_drag(&self) -> bool

Returns whether this window can start a drag to another application.

Source

fn start_external_drag(&self, _payload: &ExternalDragPayload) -> bool

Starts a drag of payload to another application. Returns true if the drag started.

Source

fn start_window_resize(&self, _edge: ResizeEdge)

Starts an interactive resize from edge. Linux only.

Source

fn set_exclusive_zone(&self, _zone: Pixels)

Reserves zone logical pixels at the screen edge for a layer-shell surface. Wayland only.

Source

fn set_exclusive_edge(&self, _edge: Anchor)

Sets the screen edge that a layer-shell exclusive zone uses. Wayland only.

Source

fn set_input_region(&self, _region: Option<&[Bounds<Pixels>]>)

Limits input to region, in logical pixels. None lets the whole window take input. Linux only.

Source

fn window_decorations(&self) -> Decorations

Returns the decorations the window is using. The default is Decorations::Server.

Source

fn set_app_id(&mut self, _app_id: &str)

Sets the application id that the window manager uses to group windows and find the desktop entry. Linux only.

Source

fn map_window(&mut self) -> Result<()>

Maps the window so the platform shows it. The default does nothing and returns Ok(()).

Source

fn window_controls(&self) -> WindowControls

Returns which window controls the platform supports.

Source

fn set_client_inset(&self, _inset: Pixels)

Sets the width of the client-side shadow that surrounds the window, in logical pixels. Linux only.

Source

fn gpu_context(&self) -> Option<Box<dyn Any>>

Returns the GPU context for this window’s renderer. The returned Box contains (Arc<wgpu::Device>, Arc<wgpu::Queue>).

Source

fn gpu_context_info(&self) -> Option<Box<dyn Any>>

Returns typed backend-specific GPU context information for custom controls. The value is intentionally type-erased in this crate so the core UI crate does not depend on a rendering backend.

Source

fn gpu_device_lost(&self) -> Option<bool>

Whether this window’s GPU device has been lost (the platform renderer recovers it on a subsequent draw). None when the backend cannot know. Safe to call mid-recovery, unlike gpu_context. Embedders that captured the device from gpu_context should stop submitting while this is Some(true) and re-acquire the device once it reads Some(false) again.

Source

fn insets(&self) -> WindowInsets

The regions of this window currently obscured or reserved by the system. Zero on platforms without such regions.

Source

fn on_insets_changed(&self, _callback: Box<dyn FnMut(WindowInsets)>)

Registers a callback invoked whenever Self::insets change.

Contract: fires continuously during animated transitions (Android WindowInsetsAnimation progress; on iOS the platform interpolates the keyboard animation curve on frame ticks) and is exact at rest.

Source

fn set_back_handler(&self, _callback: Box<dyn FnMut()>)

Sets the handler for the system back action (Android back button/gesture; no source on iOS or desktop).

Source

fn set_back_enabled(&self, _enabled: bool)

Declares whether the application would currently handle the system back action (e.g. navigation depth > 0).

Source

fn show_soft_keyboard(&self)

Requests that the soft keyboard be shown. Mobile only.

Source

fn hide_soft_keyboard(&self)

Requests that the soft keyboard be hidden. Mobile only.

Source

fn text_input_state_changed(&self, _change: TextInputStateChange)

Tells the platform that the focused text input changed.

Source

fn play_system_bell(&self)

Plays the system alert sound.

Source

fn a11y_init(&self, _callbacks: A11yCallbacks)

Initialize the accessibility adapter with callbacks.

Source

fn a11y_tree_update(&self, _tree_update: TreeUpdate)

Provide a TreeUpdate to the accessibility adapter.

Source

fn a11y_update_window_bounds(&self)

Inform the adapter of updated window bounds.

Source

fn as_test(&mut self) -> Option<&mut TestWindow>

Returns this window as a TestWindow, if it is one. Only the test platform’s windows are.

Source

fn render_to_image(&self, _scene: &Scene) -> Result<RgbaImage>

Renders the given scene to a texture and returns the pixel data as an RGBA image. This does not present the frame to screen - useful for visual testing where we want to capture what would be rendered without displaying it or requiring the window to be visible.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§