Window

Struct Window 

Source
pub struct Window { /* private fields */ }
Expand description

Holds the state for a specific window.

Implementations§

Source§

impl Window

Source

pub fn observe_window_appearance( &self, callback: impl FnMut(&mut Window, &mut App) + 'static, ) -> Subscription

Registers a callback to be invoked when the window appearance changes.

Source

pub fn replace_root<E>( &mut self, cx: &mut App, build_view: impl FnOnce(&mut Window, &mut Context<'_, E>) -> E, ) -> Entity<E>
where E: 'static + Render,

Replaces the root entity of the window with a new one.

Source

pub fn root<E>(&self) -> Option<Option<Entity<E>>>
where E: 'static + Render,

Returns the root entity of the window, if it has one.

Source

pub fn window_handle(&self) -> AnyWindowHandle

Obtain a handle to the window that belongs to this context.

Source

pub fn refresh(&mut self)

Mark the window as dirty, scheduling it to be redrawn on the next frame.

Source

pub fn remove_window(&mut self)

Close this window.

Source

pub fn focused(&self, cx: &App) -> Option<FocusHandle>

Obtain the currently focused FocusHandle. If no elements are focused, returns None.

Source

pub fn focus(&mut self, handle: &FocusHandle)

Move focus to the element associated with the given FocusHandle.

Source

pub fn blur(&mut self)

Remove focus from all elements within this context’s window.

Source

pub fn disable_focus(&mut self)

Blur the window and don’t allow anything in it to be focused again.

Source

pub fn focus_next(&mut self)

Move focus to next tab stop.

Source

pub fn focus_prev(&mut self)

Move focus to previous tab stop.

Source

pub fn text_system(&self) -> &Arc<WindowTextSystem>

Accessor for the text system.

Source

pub fn text_style(&self) -> TextStyle

The current text style. Which is composed of all the style refinements provided to with_text_style.

Source

pub fn is_maximized(&self) -> bool

Check if the platform window is maximized.

On some platforms (namely Windows) this is different than the bounds being the size of the display

Source

pub fn request_decorations(&self, decorations: WindowDecorations)

request a certain window decoration (Wayland)

Source

pub fn start_window_resize(&self, edge: ResizeEdge)

Start a window resize operation (Wayland)

Source

pub fn window_bounds(&self) -> WindowBounds

Return the WindowBounds to indicate that how a window should be opened after it has been closed

Source

pub fn inner_window_bounds(&self) -> WindowBounds

Return the WindowBounds excluding insets (Wayland and X11)

Source

pub fn dispatch_action(&mut self, action: Box<dyn Action>, cx: &mut App)

Dispatch the given action on the currently focused element.

Source

pub fn defer( &self, cx: &mut App, f: impl FnOnce(&mut Window, &mut App) + 'static, )

Schedules the given function to be run at the end of the current effect cycle, allowing entities that are currently on the stack to be returned to the app.

Source

pub fn observe<T: 'static>( &mut self, observed: &Entity<T>, cx: &mut App, on_notify: impl FnMut(Entity<T>, &mut Window, &mut App) + 'static, ) -> Subscription

Subscribe to events emitted by a entity. The entity to which you’re subscribing must implement the EventEmitter trait. The callback will be invoked a handle to the emitting entity, the event, and a window context for the current window.

Source

pub fn subscribe<Emitter, Evt>( &mut self, entity: &Entity<Emitter>, cx: &mut App, on_event: impl FnMut(Entity<Emitter>, &Evt, &mut Window, &mut App) + 'static, ) -> Subscription
where Emitter: EventEmitter<Evt>, Evt: 'static,

Subscribe to events emitted by a entity. The entity to which you’re subscribing must implement the EventEmitter trait. The callback will be invoked a handle to the emitting entity, the event, and a window context for the current window.

Source

pub fn observe_release<T>( &self, entity: &Entity<T>, cx: &mut App, on_release: impl FnOnce(&mut T, &mut Window, &mut App) + 'static, ) -> Subscription
where T: 'static,

Register a callback to be invoked when the given Entity is released.

Source

pub fn to_async(&self, cx: &App) -> AsyncWindowContext

Creates an AsyncWindowContext, which has a static lifetime and can be held across await points in async code.

Source

pub fn on_next_frame( &self, callback: impl FnOnce(&mut Window, &mut App) + 'static, )

Schedule the given closure to be run directly after the current frame is rendered.

Source

pub fn request_animation_frame(&self)

Schedule a frame to be drawn on the next animation frame.

This is useful for elements that need to animate continuously, such as a video player or an animated GIF. It will cause the window to redraw on the next frame, even if no other changes have occurred.

If called from within a view, it will notify that view on the next frame. Otherwise, it will refresh the entire window.

Source

pub fn spawn<AsyncFn, R>(&self, cx: &App, f: AsyncFn) -> Task<R>
where R: 'static, AsyncFn: AsyncFnOnce(&mut AsyncWindowContext) -> R + 'static,

Spawn the future returned by the given closure on the application thread pool. The closure is provided a handle to the current window and an AsyncWindowContext for use within your future.

Source

pub fn spawn_with_priority<AsyncFn, R>( &self, priority: Priority, cx: &App, f: AsyncFn, ) -> Task<R>
where R: 'static, AsyncFn: AsyncFnOnce(&mut AsyncWindowContext) -> R + 'static,

Spawn the future returned by the given closure on the application thread pool, with the given priority. The closure is provided a handle to the current window and an AsyncWindowContext for use within your future.

Source

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

Returns the bounds of the current window in the global coordinate space, which could span across multiple displays.

Source

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

Set the content size of the window.

Source

pub fn is_fullscreen(&self) -> bool

Returns whether or not the window is currently fullscreen

Source

pub fn appearance(&self) -> WindowAppearance

Returns the appearance of the current window.

Source

pub fn viewport_size(&self) -> Size<Pixels>

Returns the size of the drawable area within the window.

Source

pub fn is_window_active(&self) -> bool

Returns whether this window is focused by the operating system (receiving key events).

Source

pub fn is_window_hovered(&self) -> bool

Returns whether this window is considered to be the window that currently owns the mouse cursor. On mac, this is equivalent to is_window_active.

Source

pub fn zoom_window(&self)

Toggle zoom on the window.

Source

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

Opens the native title bar context menu, useful when implementing client side decorations (Wayland and X11)

Source

pub fn start_window_move(&self)

Handle window movement for Linux and macOS. Tells the compositor to take control of window movement (Wayland and X11)

Events may not be received during a move operation.

Source

pub fn set_client_inset(&mut self, inset: Pixels)

When using client side decorations, set this to the width of the invisible decorations (Wayland and X11)

Source

pub fn client_inset(&self) -> Option<Pixels>

Returns the client_inset value by Self::set_client_inset.

Source

pub fn window_decorations(&self) -> Decorations

Returns whether the title bar window controls need to be rendered by the application (Wayland and X11)

Source

pub fn window_controls(&self) -> WindowControls

Returns which window controls are currently visible (Wayland)

Source

pub fn set_window_title(&mut self, title: &str)

Updates the window’s title at the platform level.

Source

pub fn set_app_id(&mut self, app_id: &str)

Sets the application identifier.

Source

pub fn set_background_appearance( &self, background_appearance: WindowBackgroundAppearance, )

Sets the window background appearance.

Source

pub fn set_window_edited(&mut self, edited: bool)

Mark the window as dirty at the platform level.

Source

pub fn display(&self, cx: &App) -> Option<Rc<dyn PlatformDisplay>>

Determine the display on which the window is visible.

Source

pub fn show_character_palette(&self)

Show the platform character palette.

Source

pub fn scale_factor(&self) -> f32

The scale factor of the display associated with the window. For example, it could return 2.0 for a “retina” display, indicating that each logical pixel should actually be rendered as two pixels on screen.

Source

pub fn rem_size(&self) -> Pixels

The size of an em for the base font of the application. Adjusting this value allows the UI to scale, just like zooming a web page.

Source

pub fn set_rem_size(&mut self, rem_size: impl Into<Pixels>)

Sets the size of an em for the base font of the application. Adjusting this value allows the UI to scale, just like zooming a web page.

Source

pub fn with_global_id<R>( &mut self, element_id: ElementId, f: impl FnOnce(&GlobalElementId, &mut Self) -> R, ) -> R

Acquire a globally unique identifier for the given ElementId. Only valid for the duration of the provided closure.

Source

pub fn with_rem_size<F, R>( &mut self, rem_size: Option<impl Into<Pixels>>, f: F, ) -> R
where F: FnOnce(&mut Self) -> R,

Executes the provided function with the specified rem size.

This method must only be called as part of element drawing.

Source

pub fn line_height(&self) -> Pixels

The line height associated with the current text style.

Source

pub fn prevent_default(&mut self)

Call to prevent the default action of an event. Currently only used to prevent parent elements from becoming focused on mouse down.

Source

pub fn default_prevented(&self) -> bool

Obtain whether default has been prevented for the event currently being dispatched.

Source

pub fn is_action_available(&self, action: &dyn Action, cx: &mut App) -> bool

Determine whether the given action is available along the dispatch path to the currently focused element.

Source

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

The position of the mouse relative to the window.

Source

pub fn modifiers(&self) -> Modifiers

The current state of the keyboard’s modifiers

Source

pub fn last_input_was_keyboard(&self) -> bool

Returns true if the last input event was keyboard-based (key press, tab navigation, etc.) This is used for focus-visible styling to show focus indicators only for keyboard navigation.

Source

pub fn capslock(&self) -> Capslock

The current state of the keyboard’s capslock

Source

pub fn draw(&mut self, cx: &mut App) -> ArenaClearNeeded

Produces a new frame and assigns it to rendered_frame. To actually show the contents of the new [Scene], use Self::present.

Source

pub fn with_text_style<F, R>( &mut self, style: Option<TextStyleRefinement>, f: F, ) -> R
where F: FnOnce(&mut Self) -> R,

Push a text style onto the stack, and call a function with that style active. Use Window::text_style to get the current, combined text style. This method should only be called as part of element drawing.

Source

pub fn set_cursor_style(&mut self, style: CursorStyle, hitbox: &Hitbox)

Updates the cursor style at the platform level. This method should only be called during the paint phase of element drawing.

Source

pub fn set_window_cursor_style(&mut self, style: CursorStyle)

Updates the cursor style for the entire window at the platform level. A cursor style using this method will have precedence over any cursor style set using set_cursor_style. This method should only be called during the paint phase of element drawing.

Source

pub fn set_tooltip(&mut self, tooltip: AnyTooltip) -> TooltipId

Sets a tooltip to be rendered for the upcoming frame. This method should only be called during the paint phase of element drawing.

Source

pub fn with_content_mask<R>( &mut self, mask: Option<ContentMask<Pixels>>, f: impl FnOnce(&mut Self) -> R, ) -> R

Invoke the given function with the given content mask after intersecting it with the current mask. This method should only be called during element drawing.

Source

pub fn with_element_offset<R>( &mut self, offset: Point<Pixels>, f: impl FnOnce(&mut Self) -> R, ) -> R

Updates the global element offset relative to the current offset. This is used to implement scrolling. This method should only be called during the prepaint phase of element drawing.

Source

pub fn with_absolute_element_offset<R>( &mut self, offset: Point<Pixels>, f: impl FnOnce(&mut Self) -> R, ) -> R

Updates the global element offset based on the given offset. This is used to implement drag handles and other manual painting of elements. This method should only be called during the prepaint phase of element drawing.

Source

pub fn transact<T, U>( &mut self, f: impl FnOnce(&mut Self) -> Result<T, U>, ) -> Result<T, U>

Perform prepaint on child elements in a “retryable” manner, so that any side effects of prepaints can be discarded before prepainting again. This is used to support autoscroll where we need to prepaint children to detect the autoscroll bounds, then adjust the element offset and prepaint again. See crate::List for an example. This method should only be called during the prepaint phase of element drawing.

Source

pub fn request_autoscroll(&mut self, bounds: Bounds<Pixels>)

When you call this method during Element::prepaint, containing elements will attempt to scroll to cause the specified bounds to become visible. When they decide to autoscroll, they will call Element::prepaint again with a new set of bounds. See crate::List for an example of an element that supports this method being called on the elements it contains. This method should only be called during the prepaint phase of element drawing.

Source

pub fn take_autoscroll(&mut self) -> Option<Bounds<Pixels>>

This method can be called from a containing element such as crate::List to support the autoscroll behavior described in Self::request_autoscroll.

Source

pub fn use_asset<A: Asset>( &mut self, source: &A::Source, cx: &mut App, ) -> Option<A::Output>

Asynchronously load an asset, if the asset hasn’t finished loading this will return None. Your view will be re-drawn once the asset has finished loading.

Note that the multiple calls to this method will only result in one Asset::load call at a time.

Source

pub fn get_asset<A: Asset>( &mut self, source: &A::Source, cx: &mut App, ) -> Option<A::Output>

Asynchronously load an asset, if the asset hasn’t finished loading or doesn’t exist this will return None. Your view will not be re-drawn once the asset has finished loading.

Note that the multiple calls to this method will only result in one Asset::load call at a time.

Source

pub fn element_offset(&self) -> Point<Pixels>

Obtain the current element offset. This method should only be called during the prepaint phase of element drawing.

Source

pub fn content_mask(&self) -> ContentMask<Pixels>

Obtain the current content mask. This method should only be called during element drawing.

Source

pub fn with_element_namespace<R>( &mut self, element_id: impl Into<ElementId>, f: impl FnOnce(&mut Self) -> R, ) -> R

Provide elements in the called function with a new namespace in which their identifiers must be unique. This can be used within a custom element to distinguish multiple sets of child elements.

Source

pub fn use_keyed_state<S: 'static>( &mut self, key: impl Into<ElementId>, cx: &mut App, init: impl FnOnce(&mut Self, &mut Context<'_, S>) -> S, ) -> Entity<S>

Use a piece of state that exists as long this element is being rendered in consecutive frames.

Source

pub fn with_id<R>( &mut self, id: impl Into<ElementId>, f: impl FnOnce(&mut Self) -> R, ) -> R

Immediately push an element ID onto the stack. Useful for simplifying IDs in lists

Source

pub fn use_state<S: 'static>( &mut self, cx: &mut App, init: impl FnOnce(&mut Self, &mut Context<'_, S>) -> S, ) -> Entity<S>

Use a piece of state that exists as long this element is being rendered in consecutive frames, without needing to specify a key

NOTE: This method uses the location of the caller to generate an ID for this state. If this is not sufficient to identify your state (e.g. you’re rendering a list item), you can provide a custom ElementID using the use_keyed_state method.

Source

pub fn with_element_state<S, R>( &mut self, global_id: &GlobalElementId, f: impl FnOnce(Option<S>, &mut Self) -> (R, S), ) -> R
where S: 'static,

Updates or initializes state for an element with the given id that lives across multiple frames. If an element with this ID existed in the rendered frame, its state will be passed to the given closure. The state returned by the closure will be stored so it can be referenced when drawing the next frame. This method should only be called as part of element drawing.

Source

pub fn with_optional_element_state<S, R>( &mut self, global_id: Option<&GlobalElementId>, f: impl FnOnce(Option<Option<S>>, &mut Self) -> (R, Option<S>), ) -> R
where S: 'static,

A variant of with_element_state that allows the element’s id to be optional. This is a convenience method for elements where the element id may or may not be assigned. Prefer using with_element_state when the element is guaranteed to have an id.

The first option means ‘no ID provided’ The second option means ‘not yet initialized’

Source

pub fn with_tab_group<R>( &mut self, index: Option<isize>, f: impl FnOnce(&mut Self) -> R, ) -> R

Executes the given closure within the context of a tab group.

Source

pub fn defer_draw( &mut self, element: AnyElement, absolute_offset: Point<Pixels>, priority: usize, )

Defers the drawing of the given element, scheduling it to be painted on top of the currently-drawn tree at a later time. The priority parameter determines the drawing order relative to other deferred elements, with higher values being drawn on top.

This method should only be called as part of the prepaint phase of element drawing.

Source

pub fn paint_layer<R>( &mut self, bounds: Bounds<Pixels>, f: impl FnOnce(&mut Self) -> R, ) -> R

Creates a new painting layer for the specified bounds. A “layer” is a batch of geometry that are non-overlapping and have the same draw order. This is typically used for performance reasons.

This method should only be called as part of the paint phase of element drawing.

Source

pub fn paint_shadows( &mut self, bounds: Bounds<Pixels>, corner_radii: Corners<Pixels>, shadows: &[BoxShadow], )

Paint one or more drop shadows into the scene for the next frame at the current z-index.

This method should only be called as part of the paint phase of element drawing.

Source

pub fn paint_quad(&mut self, quad: PaintQuad)

Paint one or more quads into the scene for the next frame at the current stacking context. Quads are colored rectangular regions with an optional background, border, and corner radius. see fill, outline, and quad to construct this type.

This method should only be called as part of the paint phase of element drawing.

Note that the quad.corner_radii are allowed to exceed the bounds, creating sharp corners where the circular arcs meet. This will not display well when combined with dashed borders. Use Corners::clamp_radii_for_quad_size if the radii should fit within the bounds.

Source

pub fn paint_path(&mut self, path: Path<Pixels>, color: impl Into<Background>)

Paint the given Path into the scene for the next frame at the current z-index.

This method should only be called as part of the paint phase of element drawing.

Source

pub fn paint_underline( &mut self, origin: Point<Pixels>, width: Pixels, style: &UnderlineStyle, )

Paint an underline into the scene for the next frame at the current z-index.

This method should only be called as part of the paint phase of element drawing.

Source

pub fn paint_strikethrough( &mut self, origin: Point<Pixels>, width: Pixels, style: &StrikethroughStyle, )

Paint a strikethrough into the scene for the next frame at the current z-index.

This method should only be called as part of the paint phase of element drawing.

Source

pub fn paint_glyph( &mut self, origin: Point<Pixels>, font_id: FontId, glyph_id: GlyphId, font_size: Pixels, color: Hsla, ) -> Result<()>

Paints a monochrome (non-emoji) glyph into the scene for the next frame at the current z-index.

The y component of the origin is the baseline of the glyph. You should generally prefer to use the ShapedLine::paint or WrappedLine::paint methods in the TextSystem. This method is only useful if you need to paint a single glyph that has already been shaped.

This method should only be called as part of the paint phase of element drawing.

Source

pub fn paint_emoji( &mut self, origin: Point<Pixels>, font_id: FontId, glyph_id: GlyphId, font_size: Pixels, ) -> Result<()>

Paints an emoji glyph into the scene for the next frame at the current z-index.

The y component of the origin is the baseline of the glyph. You should generally prefer to use the ShapedLine::paint or WrappedLine::paint methods in the TextSystem. This method is only useful if you need to paint a single emoji that has already been shaped.

This method should only be called as part of the paint phase of element drawing.

Source

pub fn paint_svg( &mut self, bounds: Bounds<Pixels>, path: SharedString, data: Option<&[u8]>, transformation: TransformationMatrix, color: Hsla, cx: &App, ) -> Result<()>

Paint a monochrome SVG into the scene for the next frame at the current stacking context.

This method should only be called as part of the paint phase of element drawing.

Source

pub fn paint_image( &mut self, bounds: Bounds<Pixels>, corner_radii: Corners<Pixels>, data: Arc<RenderImage>, frame_index: usize, grayscale: bool, ) -> Result<()>

Paint an image into the scene for the next frame at the current z-index. This method will panic if the frame_index is not valid

This method should only be called as part of the paint phase of element drawing.

Source

pub fn drop_image(&mut self, data: Arc<RenderImage>) -> Result<()>

Removes an image from the sprite atlas.

Source

pub fn request_layout( &mut self, style: Style, children: impl IntoIterator<Item = LayoutId>, cx: &mut App, ) -> LayoutId

Add a node to the layout tree for the current frame. Takes the Style of the element for which layout is being requested, along with the layout ids of any children. This method is called during calls to the Element::request_layout trait method and enables any element to participate in layout.

This method should only be called as part of the request_layout or prepaint phase of element drawing.

Source

pub fn request_measured_layout<F>( &mut self, style: Style, measure: F, ) -> LayoutId
where F: Fn(Size<Option<Pixels>>, Size<AvailableSpace>, &mut Window, &mut App) -> Size<Pixels> + 'static,

Add a node to the layout tree for the current frame. Instead of taking a Style and children, this variant takes a function that is invoked during layout so you can use arbitrary logic to determine the element’s size. One place this is used internally is when measuring text.

The given closure is invoked at layout time with the known dimensions and available space and returns a Size.

This method should only be called as part of the request_layout or prepaint phase of element drawing.

Source

pub fn compute_layout( &mut self, layout_id: LayoutId, available_space: Size<AvailableSpace>, cx: &mut App, )

Compute the layout for the given id within the given available space. This method is called for its side effect, typically by the framework prior to painting. After calling it, you can request the bounds of the given layout node id or any descendant.

This method should only be called as part of the prepaint phase of element drawing.

Source

pub fn layout_bounds(&mut self, layout_id: LayoutId) -> Bounds<Pixels>

Obtain the bounds computed for the given LayoutId relative to the window. This method will usually be invoked by GPUI itself automatically in order to pass your element its Bounds automatically.

This method should only be called as part of element drawing.

Source

pub fn insert_hitbox( &mut self, bounds: Bounds<Pixels>, behavior: HitboxBehavior, ) -> Hitbox

This method should be called during prepaint. You can use the returned Hitbox during paint or in an event handler to determine whether the inserted hitbox was the topmost.

This method should only be called as part of the prepaint phase of element drawing.

Source

pub fn insert_window_control_hitbox( &mut self, area: WindowControlArea, hitbox: Hitbox, )

Set a hitbox which will act as a control area of the platform window.

This method should only be called as part of the paint phase of element drawing.

Source

pub fn set_key_context(&mut self, context: KeyContext)

Sets the key context for the current element. This context will be used to translate keybindings into actions.

This method should only be called as part of the paint phase of element drawing.

Source

pub fn set_focus_handle(&mut self, focus_handle: &FocusHandle, _: &App)

Sets the focus handle for the current element. This handle will be used to manage focus state and keyboard event dispatch for the element.

This method should only be called as part of the prepaint phase of element drawing.

Source

pub fn set_view_id(&mut self, view_id: EntityId)

Sets the view id for the current element, which will be used to manage view caching.

This method should only be called as part of element prepaint. We plan on removing this method eventually when we solve some issues that require us to construct editor elements directly instead of always using editors via views.

Source

pub fn current_view(&self) -> EntityId

Get the entity ID for the currently rendering view

Source

pub fn with_image_cache<F, R>( &mut self, image_cache: Option<AnyImageCache>, f: F, ) -> R
where F: FnOnce(&mut Self) -> R,

Executes the provided function with the specified image cache.

Source

pub fn handle_input( &mut self, focus_handle: &FocusHandle, input_handler: impl InputHandler, cx: &App, )

Sets an input handler, such as ElementInputHandler, which interfaces with the platform to receive textual input with proper integration with concerns such as IME interactions. This handler will be active for the upcoming frame until the following frame is rendered.

This method should only be called as part of the paint phase of element drawing.

Source

pub fn on_mouse_event<Event: MouseEvent>( &mut self, listener: impl FnMut(&Event, DispatchPhase, &mut Window, &mut App) + 'static, )

Register a mouse event listener on the window for the next frame. The type of event is determined by the first parameter of the given listener. When the next frame is rendered the listener will be cleared.

This method should only be called as part of the paint phase of element drawing.

Source

pub fn on_key_event<Event: KeyEvent>( &mut self, listener: impl Fn(&Event, DispatchPhase, &mut Window, &mut App) + 'static, )

Register a key event listener on this node for the next frame. The type of event is determined by the first parameter of the given listener. When the next frame is rendered the listener will be cleared.

This is a fairly low-level method, so prefer using event handlers on elements unless you have a specific need to register a listener yourself.

This method should only be called as part of the paint phase of element drawing.

Source

pub fn on_modifiers_changed( &mut self, listener: impl Fn(&ModifiersChangedEvent, &mut Window, &mut App) + 'static, )

Register a modifiers changed event listener on the window for the next frame.

This is a fairly low-level method, so prefer using event handlers on elements unless you have a specific need to register a global listener.

This method should only be called as part of the paint phase of element drawing.

Source

pub fn on_focus_in( &mut self, handle: &FocusHandle, cx: &mut App, listener: impl FnMut(&mut Window, &mut App) + 'static, ) -> Subscription

Register a listener to be called when the given focus handle or one of its descendants receives focus. This does not fire if the given focus handle - or one of its descendants - was previously focused. Returns a subscription and persists until the subscription is dropped.

Source

pub fn on_focus_out( &mut self, handle: &FocusHandle, cx: &mut App, listener: impl FnMut(FocusOutEvent, &mut Window, &mut App) + 'static, ) -> Subscription

Register a listener to be called when the given focus handle or one of its descendants loses focus. Returns a subscription and persists until the subscription is dropped.

Source

pub fn dispatch_keystroke(&mut self, keystroke: Keystroke, cx: &mut App) -> bool

Dispatch a given keystroke as though the user had typed it. You can create a keystroke with Keystroke::parse(“”).

Source

pub fn keystroke_text_for(&self, action: &dyn Action) -> String

Return a key binding string for an action, to display in the UI. Uses the highest precedence binding for the action (last binding added to the keymap).

Source

pub fn dispatch_event( &mut self, event: PlatformInput, cx: &mut App, ) -> DispatchEventResult

Dispatch a mouse or keyboard event on the window.

Source

pub fn has_pending_keystrokes(&self) -> bool

Determine whether a potential multi-stroke key binding is in progress on this window.

Source

pub fn pending_input_keystrokes(&self) -> Option<&[Keystroke]>

Returns the currently pending input keystrokes that might result in a multi-stroke key binding.

Source

pub fn observe_global<G: Global>( &mut self, cx: &mut App, f: impl Fn(&mut Window, &mut App) + 'static, ) -> Subscription

Register the given handler to be invoked whenever the global of the given type is updated.

Source

pub fn activate_window(&self)

Focus the current window and bring it to the foreground at the platform level.

Source

pub fn minimize_window(&self)

Minimize the current window at the platform level.

Source

pub fn toggle_fullscreen(&self)

Toggle full screen status on the current window at the platform level.

Source

pub fn invalidate_character_coordinates(&self)

Updates the IME panel position suggestions for languages like japanese, chinese.

Source

pub fn prompt<T>( &mut self, level: PromptLevel, message: &str, detail: Option<&str>, answers: &[T], cx: &mut App, ) -> Receiver<usize>
where T: Clone + Into<PromptButton>,

Present a platform dialog. The provided message will be presented, along with buttons for each answer. When a button is clicked, the returned Receiver will receive the index of the clicked button.

Source

pub fn context_stack(&self) -> Vec<KeyContext>

Returns the current context stack.

Source

pub fn available_actions(&self, cx: &App) -> Vec<Box<dyn Action>>

Returns all available actions for the focused element.

Source

pub fn bindings_for_action(&self, action: &dyn Action) -> Vec<KeyBinding>

Returns key bindings that invoke an action on the currently focused element. Bindings are returned in the order they were added. For display, the last binding should take precedence.

Source

pub fn highest_precedence_binding_for_action( &self, action: &dyn Action, ) -> Option<KeyBinding>

Returns the highest precedence key binding that invokes an action on the currently focused element. This is more efficient than getting the last result of bindings_for_action.

Source

pub fn bindings_for_action_in_context( &self, action: &dyn Action, context: KeyContext, ) -> Vec<KeyBinding>

Returns the key bindings for an action in a context.

Source

pub fn highest_precedence_binding_for_action_in_context( &self, action: &dyn Action, context: KeyContext, ) -> Option<KeyBinding>

Returns the highest precedence key binding for an action in a context. This is more efficient than getting the last result of bindings_for_action_in_context.

Source

pub fn bindings_for_action_in( &self, action: &dyn Action, focus_handle: &FocusHandle, ) -> Vec<KeyBinding>

Returns any bindings that would invoke an action on the given focus handle if it were focused. Bindings are returned in the order they were added. For display, the last binding should take precedence.

Source

pub fn highest_precedence_binding_for_action_in( &self, action: &dyn Action, focus_handle: &FocusHandle, ) -> Option<KeyBinding>

Returns the highest precedence key binding that would invoke an action on the given focus handle if it were focused. This is more efficient than getting the last result of bindings_for_action_in.

Source

pub fn listener_for<T: 'static, E>( &self, view: &Entity<T>, f: impl Fn(&mut T, &E, &mut Window, &mut Context<'_, T>) + 'static, ) -> impl Fn(&E, &mut Window, &mut App) + 'static

Returns a generic event listener that invokes the given listener with the view and context associated with the given view handle.

Source

pub fn handler_for<E: 'static, Callback: Fn(&mut E, &mut Window, &mut Context<'_, E>) + 'static>( &self, entity: &Entity<E>, f: Callback, ) -> impl Fn(&mut Window, &mut App) + 'static

Returns a generic handler that invokes the given handler with the view and context associated with the given view handle.

Source

pub fn on_window_should_close( &self, cx: &App, f: impl Fn(&mut Window, &mut App) -> bool + 'static, )

Register a callback that can interrupt the closing of the current window based the returned boolean. If the callback returns false, the window won’t be closed.

Source

pub fn on_action( &mut self, action_type: TypeId, listener: impl Fn(&dyn Any, DispatchPhase, &mut Window, &mut App) + 'static, )

Register an action listener on this node for the next frame. The type of action is determined by the first parameter of the given listener. When the next frame is rendered the listener will be cleared.

This is a fairly low-level method, so prefer using action handlers on elements unless you have a specific need to register a listener yourself.

This method should only be called as part of the paint phase of element drawing.

Source

pub fn on_action_when( &mut self, condition: bool, action_type: TypeId, listener: impl Fn(&dyn Any, DispatchPhase, &mut Window, &mut App) + 'static, )

Register a capturing action listener on this node for the next frame if the condition is true. The type of action is determined by the first parameter of the given listener. When the next frame is rendered the listener will be cleared.

This is a fairly low-level method, so prefer using action handlers on elements unless you have a specific need to register a listener yourself.

This method should only be called as part of the paint phase of element drawing.

Source

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

Read information about the GPU backing this window. Currently returns None on Mac and Windows.

Source

pub fn titlebar_double_click(&self)

Perform titlebar double-click action. This is macOS specific.

Source

pub fn window_title(&self) -> String

Gets the window’s title at the platform level. This is macOS specific.

Source

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

Returns a list of all tabbed windows and their titles. This is macOS specific.

Source

pub fn tab_bar_visible(&self) -> bool

Returns the tab bar visibility. This is macOS specific.

Source

pub fn merge_all_windows(&self)

Merges all open windows into a single tabbed window. This is macOS specific.

Source

pub fn move_tab_to_new_window(&self)

Moves the tab to a new containing window. This is macOS specific.

Source

pub fn toggle_window_tab_overview(&self)

Shows or hides the window tab overview. This is macOS specific.

Source

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

Sets the tabbing identifier for the window. This is macOS specific.

Source

pub fn toggle_inspector(&mut self, cx: &mut App)

Toggles the inspector mode on this window.

Source

pub fn is_inspector_picking(&self, _cx: &App) -> bool

Returns true if the window is in inspector mode.

Source

pub fn with_inspector_state<T: 'static, R>( &mut self, _inspector_id: Option<&InspectorElementId>, cx: &mut App, f: impl FnOnce(&mut Option<T>, &mut Self) -> R, ) -> R

Executes the provided function with mutable access to an inspector state.

Source

pub fn insert_inspector_hitbox( &mut self, hitbox_id: HitboxId, inspector_id: Option<&InspectorElementId>, cx: &App, )

Registers a hitbox that can be used for inspector picking mode, allowing users to select and inspect UI elements by clicking on them.

Trait Implementations§

Source§

impl HasDisplayHandle for Window

Source§

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

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

impl HasWindowHandle for Window

Source§

fn window_handle(&self) -> Result<WindowHandle<'_>, HandleError>

Get a handle to the window.

Auto Trait Implementations§

§

impl Freeze for Window

§

impl !RefUnwindSafe for Window

§

impl !Send for Window

§

impl !Sync for Window

§

impl Unpin for Window

§

impl !UnwindSafe for Window

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> HasRawDisplayHandle for T
where T: HasDisplayHandle + ?Sized,

Source§

fn raw_display_handle(&self) -> Result<RawDisplayHandle, HandleError>

👎Deprecated: Use HasDisplayHandle instead
Source§

impl<T> HasRawWindowHandle for T
where T: HasWindowHandle + ?Sized,

Source§

fn raw_window_handle(&self) -> Result<RawWindowHandle, HandleError>

👎Deprecated: Use HasWindowHandle instead
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more