Skip to main content

WindowExt

Trait WindowExt 

Source
pub trait WindowExt: Sized {
Show 16 methods // Required methods fn open_sheet<F>(&mut self, cx: &mut App, build: F) where F: Fn(Sheet, &mut Window, &mut App) -> Sheet + 'static; fn open_sheet_at<F>(&mut self, placement: Placement, cx: &mut App, build: F) where F: Fn(Sheet, &mut Window, &mut App) -> Sheet + 'static; fn has_active_sheet(&mut self, cx: &mut App) -> bool; fn close_sheet(&mut self, cx: &mut App); fn open_dialog<F>(&mut self, cx: &mut App, build: F) where F: Fn(Dialog, &mut Window, &mut App) -> Dialog + 'static; fn open_alert_dialog<F>(&mut self, cx: &mut App, build: F) where F: Fn(AlertDialog, &mut Window, &mut App) -> AlertDialog + 'static; fn has_active_dialog(&mut self, cx: &mut App) -> bool; fn close_dialog(&mut self, cx: &mut App); fn close_all_dialogs(&mut self, cx: &mut App); fn push_notification(&mut self, note: impl Into<Notification>, cx: &mut App); fn remove_notification<T: Sized + 'static>(&mut self, cx: &mut App); fn remove_notification1<T: Sized + 'static>( &mut self, key: impl Into<ElementId>, cx: &mut App, ); fn clear_notifications(&mut self, cx: &mut App); fn notifications(&mut self, cx: &mut App) -> Rc<Vec<Entity<Notification>>>; fn focused_input(&mut self, cx: &mut App) -> Option<AnyInputState>; fn has_focused_input(&mut self, cx: &mut App) -> bool;
}
Expand description

Extension trait for Window to add dialog, sheet .. functionality.

Required Methods§

Source

fn open_sheet<F>(&mut self, cx: &mut App, build: F)
where F: Fn(Sheet, &mut Window, &mut App) -> Sheet + 'static,

Opens a Sheet at right placement.

The builder follows the same rendering contract as WindowExt::open_dialog: it may run again when the sheet layer is rebuilt. Keep it cheap and create persistent entities before opening, not inside the builder.

Source

fn open_sheet_at<F>(&mut self, placement: Placement, cx: &mut App, build: F)
where F: Fn(Sheet, &mut Window, &mut App) -> Sheet + 'static,

Opens a Sheet at the given placement.

The builder follows the same rendering contract as WindowExt::open_dialog: it may run again when the sheet layer is rebuilt. Keep it cheap and create persistent entities before opening, not inside the builder.

Source

fn has_active_sheet(&mut self, cx: &mut App) -> bool

Return true, if there is an active Sheet.

Source

fn close_sheet(&mut self, cx: &mut App)

Closes the active Sheet.

Source

fn open_dialog<F>(&mut self, cx: &mut App, build: F)
where F: Fn(Dialog, &mut Window, &mut App) -> Dialog + 'static,

Opens a Dialog.

The builder is a render closure, not a one-shot constructor. It may run again when the dialog layer is rebuilt while the dialog is open. View caching means a displayed frame need not rebuild the layer; the builder is not a periodic update callback. Keep it cheap and idempotent.

Create persistent entities, such as an InputState or a child view, before opening and capture their handles in the builder. Creating them with cx.new(...) inside the builder replaces them on each rebuild and loses their editing state.

open_dialog initially focuses the dialog shell, replacing any focus set before the call. To choose initial content focus, set it only on the builder’s first invocation, with a guard captured separately for each opening. Never focus unconditionally on subsequent rebuilds: that would steal focus from another control or a nested dialog.

§Examples
ⓘ
use std::cell::Cell;
use gpui_kit::{AppContext as _, Focusable as _};
use gpui_kit::component::{WindowExt as _, input::{Input, InputState}};

// Both the input and the one-time focus guard belong to this opening.
let input = cx.new(|cx| InputState::new(window, cx).placeholder("URL"));
let initial_focus = Cell::new(true);
window.open_dialog(cx, move |dialog, window, cx| {
    if initial_focus.replace(false) {
        input.focus_handle(cx).focus(window, cx);
    }
    dialog.title("Import").child(Input::new(&input))
});
Source

fn open_alert_dialog<F>(&mut self, cx: &mut App, build: F)
where F: Fn(AlertDialog, &mut Window, &mut App) -> AlertDialog + 'static,

Opens an AlertDialog.

This is a convenience method for opening an alert dialog with opinionated defaults. The footer buttons are center-aligned and include an icon based on the variant.

The builder follows the same rendering contract as WindowExt::open_dialog: it may run again when the dialog layer is rebuilt. Keep it cheap and create persistent entities before opening, not inside the builder.

§Examples
ⓘ
use gpui_kit::component::{AlertDialog, alert::AlertVariant};

window.open_alert_dialog(cx, |alert, _, _| {
    alert.warning()
        .title("Unsaved Changes")
        .description("You have unsaved changes. Are you sure you want to leave?")
        .show_cancel(true)
});
Source

fn has_active_dialog(&mut self, cx: &mut App) -> bool

Return true, if there is an active Dialog.

Source

fn close_dialog(&mut self, cx: &mut App)

Closes the last active Dialog.

Source

fn close_all_dialogs(&mut self, cx: &mut App)

Closes all active Dialogs.

Source

fn push_notification(&mut self, note: impl Into<Notification>, cx: &mut App)

Pushes a notification to the notification list.

Source

fn remove_notification<T: Sized + 'static>(&mut self, cx: &mut App)

Removes all notifications whose id matches T, including ones registered with either Notification::id or Notification::id1 (any key).

Source

fn remove_notification1<T: Sized + 'static>( &mut self, key: impl Into<ElementId>, cx: &mut App, )

Removes a single notification matching the given type T and key (paired with Notification::id1).

Source

fn clear_notifications(&mut self, cx: &mut App)

Clears all notifications.

Source

fn notifications(&mut self, cx: &mut App) -> Rc<Vec<Entity<Notification>>>

Returns number of notifications.

Source

fn focused_input(&mut self, cx: &mut App) -> Option<AnyInputState>

Return the currently focused input state.

Covers Input, Textarea, Editor and OtpInput, use AnyInputState::as_input and friends to get the concrete state. A registration whose focus handle is no longer focused (e.g. the input was removed from the tree while focused) is treated as None.

Source

fn has_focused_input(&mut self, cx: &mut App) -> bool

Returns true if there is a focused Input entity.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementations on Foreign Types§

Source§

impl WindowExt for Window

Source§

fn open_sheet<F>(&mut self, cx: &mut App, build: F)
where F: Fn(Sheet, &mut Window, &mut App) -> Sheet + 'static,

Source§

fn open_sheet_at<F>(&mut self, placement: Placement, cx: &mut App, build: F)
where F: Fn(Sheet, &mut Window, &mut App) -> Sheet + 'static,

Source§

fn has_active_sheet(&mut self, cx: &mut App) -> bool

Source§

fn close_sheet(&mut self, cx: &mut App)

Source§

fn open_dialog<F>(&mut self, cx: &mut App, build: F)
where F: Fn(Dialog, &mut Window, &mut App) -> Dialog + 'static,

Source§

fn open_alert_dialog<F>(&mut self, cx: &mut App, build: F)
where F: Fn(AlertDialog, &mut Window, &mut App) -> AlertDialog + 'static,

Source§

fn has_active_dialog(&mut self, cx: &mut App) -> bool

Source§

fn close_dialog(&mut self, cx: &mut App)

Source§

fn close_all_dialogs(&mut self, cx: &mut App)

Source§

fn push_notification(&mut self, note: impl Into<Notification>, cx: &mut App)

Source§

fn remove_notification<T: Sized + 'static>(&mut self, cx: &mut App)

Source§

fn remove_notification1<T: Sized + 'static>( &mut self, key: impl Into<ElementId>, cx: &mut App, )

Source§

fn clear_notifications(&mut self, cx: &mut App)

Source§

fn notifications(&mut self, cx: &mut App) -> Rc<Vec<Entity<Notification>>>

Source§

fn has_focused_input(&mut self, cx: &mut App) -> bool

Source§

fn focused_input(&mut self, cx: &mut App) -> Option<AnyInputState>

Implementors§