Skip to main content

ActiveEventLoop

Trait ActiveEventLoop 

Source
pub trait ActiveEventLoop: Any + Debug {
Show 17 methods // Required methods fn create_proxy(&self) -> EventLoopProxy; fn create_window( &self, window_attributes: WindowAttributes, ) -> Result<Box<dyn Window>, RequestError>; fn create_custom_cursor( &self, custom_cursor: CustomCursorSource, ) -> Result<CustomCursor, RequestError>; fn available_monitors(&self) -> Box<dyn Iterator<Item = MonitorHandle>>; fn primary_monitor(&self) -> Option<MonitorHandle>; fn listen_device_events(&self, allowed: DeviceEvents); fn system_theme(&self) -> Option<Theme>; fn set_control_flow(&self, control_flow: ControlFlow); fn control_flow(&self) -> ControlFlow; fn exit(&self); fn exiting(&self) -> bool; fn owned_display_handle(&self) -> OwnedDisplayHandle; fn rwh_06_handle(&self) -> &dyn HasDisplayHandle; // Provided methods fn fetch_data_transfer( &self, id: DataTransferId, type_: &dyn TransferType, ) -> Result<AsyncRequestSerial, RequestError> { ... } fn data_transfer( &self, id: DataTransferId, ) -> Result<Box<dyn DataTransfer>, RequestError> { ... } fn set_valid_dnd_actions( &self, id: DataTransferId, actions: &[DndAction], ) -> Result<(), RequestError> { ... } fn start_drag( &self, source: WindowId, send_data: Box<dyn DataTransferSend>, actions: &[DndAction], icon: Option<DragIcon>, ) -> Result<DataTransferId, RequestError> { ... }
}

Required Methods§

Source

fn create_proxy(&self) -> EventLoopProxy

Creates an EventLoopProxy that can be used to dispatch user events to the main event loop, possibly from another thread.

Source

fn create_window( &self, window_attributes: WindowAttributes, ) -> Result<Box<dyn Window>, RequestError>

Create the window.

Possible causes of error include denied permission, incompatible system, and lack of memory.

§Platform-specific
  • Web: The window is created but not inserted into the Web page automatically. Please see the Web platform module for more information.
Source

fn create_custom_cursor( &self, custom_cursor: CustomCursorSource, ) -> Result<CustomCursor, RequestError>

Create custom cursor.

§Platform-specific

iOS / Android / Orbital: Unsupported.

Source

fn available_monitors(&self) -> Box<dyn Iterator<Item = MonitorHandle>>

Returns the list of all the monitors available on the system.

§Platform-specific

Web: Only returns the current monitor without detailed monitor permissions.

Source

fn primary_monitor(&self) -> Option<MonitorHandle>

Returns the primary monitor of the system.

Returns None if it can’t identify any monitor as a primary one.

§Platform-specific
  • Wayland: Always returns None.
  • Web: Always returns None without detailed monitor permissions.
Source

fn listen_device_events(&self, allowed: DeviceEvents)

Change if or when DeviceEvents are captured.

Since the DeviceEvent capture can lead to high CPU usage for unfocused windows, winit will ignore them by default for unfocused windows on Linux/BSD. This method allows changing this at runtime to explicitly capture them again.

§Platform-specific
  • Wayland / macOS / iOS / Android / Orbital: Unsupported.
Source

fn system_theme(&self) -> Option<Theme>

Returns the current system theme.

Returns None if it cannot be determined on the current platform.

§Platform-specific
  • iOS / Android / Wayland / x11 / Orbital: Unsupported.
Source

fn set_control_flow(&self, control_flow: ControlFlow)

Sets the ControlFlow.

Source

fn control_flow(&self) -> ControlFlow

Gets the current ControlFlow.

Source

fn exit(&self)

Stop the event loop.

§Platform-specific
§iOS

It is not possible to programmatically exit/quit an application on iOS, so this function is a no-op there. See also this technical Q&A.

Source

fn exiting(&self) -> bool

Returns whether the ActiveEventLoop is about to stop.

Set by exit().

Source

fn owned_display_handle(&self) -> OwnedDisplayHandle

Gets a persistent reference to the underlying platform display.

See the OwnedDisplayHandle type for more information.

Source

fn rwh_06_handle(&self) -> &dyn HasDisplayHandle

Get the raw-window-handle handle.

Provided Methods§

Source

fn fetch_data_transfer( &self, id: DataTransferId, type_: &dyn TransferType, ) -> Result<AsyncRequestSerial, RequestError>

Request to fetch a type from a data transfer.

This may be called multiple times on the same DataTransferId with different types, and may be called at any point during the drag operation, including during handling the DragDropped event. After that event has been received, though, the data transfer is not guaranteed to be available. The data is not guaranteed to be available during (or after) handling of `DragLeft.

Once available, the data will be supplied to the application with the DataTransferReceived event.

Source

fn data_transfer( &self, id: DataTransferId, ) -> Result<Box<dyn DataTransfer>, RequestError>

Get a data transfer by its ID.

If the ID is invalid (e.g. if the lifetime of the data transfer has expired), this will return an error.

Source

fn set_valid_dnd_actions( &self, id: DataTransferId, actions: &[DndAction], ) -> Result<(), RequestError>

Set a given set of DndActions as the valid actions for the given DataTransferId, if the transfer ID is from an incoming drag-and-drop operation.

This allows the OS/compositor to display the correct UI, indicating that the dragged data can be dropped. If the data transfer does not exist or is not from a drag-and-drop operation, will return an error.

The operating system will consider the drag either accepted or rejected based on the set of valid actions supplied using this method, combined with the set of valid actions on the drag source. If the drag is rejected at the point that the user finalizes the drop, the application will receive DragLeft instead of DragDropped.

Note that rejecting the drag is not the same as canceling the drag. A rejected drag can be accepted later and the user can continue dragging it over other potential targets. On most platforms, there is no way for an application to explicitly cancel a drag operation.

The set of actions is expected to be ordered by preference.

Source

fn start_drag( &self, source: WindowId, send_data: Box<dyn DataTransferSend>, actions: &[DndAction], icon: Option<DragIcon>, ) -> Result<DataTransferId, RequestError>

Initiate a new drag-and-drop operation.

See DataTransferSendBuilder for how to create a new cross-platform data transfer, or DataTransferSend for a generic trait which can be implemented manually.

The DataTransferId returned from this method, identifying the outgoing drag, is currently only used for identifying the drag in the OutgoingDragDropped event. In most cases, a drag will be started while the mouse is over the window which started it. This means that, directly after this method is called, the window will then receive a DragEntered event. However, the ID identifying the incoming drag is not guaranteed to be the same as the ID returned from this method.

For most cases, applications can treat all DragEntered events the same, whether they were initiated by the same application or a different application. However, if the user wants to have some kind of special handling for internal drag-and-drop, they will currently need to implement it via workaround. On all systems where drag-and-drop is implemented in Winit, the application can make the assumption that only a single drag operation can occur at one time. Therefore, if DragEntered is received between calling this method and receiving OutgoingDragDropped, then you can assume that it’s the same drag. In theory, Wayland allows multiple simultaneous drag operations at a time, but Winit does not currently guarantee that this is supported correctly for either internal or external drag.

§Arguments
  • source - The ID of the window that initiated the drag operation.
  • send_data - The data provided by this drag operation. See DataTransferSendBuilder.
  • actions - The set of valid actions for this drag operation. See DndAction. On Wayland, this is expected to be ordered by preference.
  • icon - The icon to show while dragging.

Some platforms have a more-expressive way of setting the visual component of a drag operation. For those platforms, consider using the platform-specific implementation of DataTransferSend for send_data and set this field to None.

§Returns

A unique identifier for this drag operation, which will be later supplied by OutgoingDragDropped.

Implementations§

Source§

impl dyn ActiveEventLoop + '_

Source

pub fn cast_ref<T: ActiveEventLoop>(&self) -> Option<&T>

Downcast to the backend concrete type.

Returns None if the object was not from that backend.

Source

pub fn cast_mut<T: ActiveEventLoop>(&mut self) -> Option<&mut T>

Mutable downcast to the backend concrete type.

Returns None if the object was not from that backend.

Source

pub fn cast<T: ActiveEventLoop>(self: Box<Self>) -> Result<Box<T>, Box<Self>>

Owned downcast to the backend concrete type.

Returns Err with self if the object was not from that backend.

Trait Implementations§

Source§

impl HasDisplayHandle for dyn ActiveEventLoop + '_

Source§

fn display_handle(&self) -> Result<DisplayHandle<'_>, HandleError>

Get a handle to the display controller of the windowing system.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§