T05 buttons and actions: groups, toggles, segmented, confirm, copy, share, bars, sheet, quick actions

This commit is contained in:
ZacharyZhang-NY committed 2026-09-25 03:51:34 -04:00
1 parent 77bcd5be07
commit 817da41c22
29 files changed
+2659 -151

No files matched your search

+42 -2
View File
@@ -1,6 +1,6 @@
use gpui::{
AnyElement, App, Div, FocusHandle, InteractiveElement, IntoElement, ParentElement, RenderOnce,
StyleRefinement, Styled, Window, actions, div,
AnyElement, App, Div, Entity, FocusHandle, InteractiveElement, IntoElement, ParentElement,
RenderOnce, StyleRefinement, Styled, Window, actions, div,
};
use crate::theme::ActiveTheme;
@@ -94,3 +94,43 @@ fn step(scope: &FocusHandle, trap: bool, forward: bool, window: &mut Window, cx:
window.focus(&origin);
}
}
/// Focus an overlay holds while open, and what it held before.
pub(crate) struct Takeover {
pub focus: FocusHandle,
previous: Option<FocusHandle>,
taken: bool,
}
/// Keyed focus for an overlay; focused on its first render.
pub(crate) fn take_focus(
key: impl Into<gpui::ElementId>,
window: &mut Window,
cx: &mut App,
) -> Entity<Takeover> {
let state = window.use_keyed_state(key, cx, |_, cx| Takeover {
focus: cx.focus_handle(),
previous: None,
taken: false,
});
if !state.read(cx).taken {
let previous = window.focused(cx);
window.focus(&state.read(cx).focus.clone());
state.update(cx, |takeover, _| {
takeover.previous = previous;
takeover.taken = true;
});
}
state
}
/// Returns focus to whatever held it before the overlay opened.
pub(crate) fn give_back(state: &Entity<Takeover>, window: &mut Window, cx: &App) {
match state.read(cx).previous.clone() {
Some(previous) => {
window.focus(&previous);
log::info!("focus: handed back after an overlay");
}
None => log::info!("focus: overlay closed, nothing was focused before"),
}
}
+1
View File
@@ -11,6 +11,7 @@ mod tooltip;
pub use backdrop::{Backdrop, Place};
pub use divider::Divider;
pub use focus::{FocusNext, FocusPrev, FocusRing, FocusScope};
pub(crate) use focus::{give_back, take_focus};
pub use ghost::DragGhost;
pub use icon::{Icon, IconName};
pub use image::Image;