Vendor the native UI kit as crates/ui

- crates/ui holds the theme, icons, components, data widgets, editor surfaces, layout, and utilities; cargo feature gates are gone.
- One merged icon set of 154 SVGs where the app file wins every duplicate name, served by a single rust-embed Assets source.
- IconRole grows the 25 app glyphs, so assets::CustomIconName and crates/assets are deleted.
- ui::init owns the theme and key bindings that desktop used to bind in three calls.
- docs/gpui-native-kit-gaps.md becomes docs/ui-gaps.md; the icon gap is closed.
This commit is contained in:
2026-11-17 09:36:20 +07:00
parent ad6e00b4b9
commit d795dc6e32
287 changed files with 28142 additions and 590 deletions
+143
View File
@@ -0,0 +1,143 @@
//! A scrollable container with an overlay scrollbar.
use gpui::prelude::FluentBuilder as _;
use gpui::{
App, ElementId, InteractiveElement as _, IntoElement, ParentElement, RenderOnce, ScrollHandle,
SharedString, StatefulInteractiveElement as _, Styled, Window, div,
};
use crate::components::common::StyledExt;
use crate::components::scrollbar::{Scrollbar, ScrollbarVisibility};
/// Which directions the content scrolls in.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub enum ScrollAxes {
/// Vertical only; the default.
#[default]
Vertical,
/// Horizontal only.
Horizontal,
/// Both directions.
Both,
}
/// A scrollable container with an overlay scrollbar.
#[derive(IntoElement)]
#[must_use]
pub struct ScrollArea {
id: ElementId,
handle: Option<ScrollHandle>,
axes: ScrollAxes,
visibility: ScrollbarVisibility,
a11y_label: Option<SharedString>,
style: gpui::StyleRefinement,
children: Vec<gpui::AnyElement>,
}
impl ParentElement for ScrollArea {
fn extend(&mut self, children: impl IntoIterator<Item = gpui::AnyElement>) {
self.children.extend(children);
}
}
impl Styled for ScrollArea {
fn style(&mut self) -> &mut gpui::StyleRefinement {
&mut self.style
}
}
impl ScrollArea {
/// Creates a vertically scrolling area.
pub fn new<I>(id: I) -> Self
where
I: Into<ElementId>,
{
Self {
id: id.into(),
handle: None,
axes: ScrollAxes::Vertical,
visibility: ScrollbarVisibility::default(),
a11y_label: None,
style: gpui::StyleRefinement::default(),
children: Vec::new(),
}
}
/// Sets which directions the content scrolls in.
pub fn axes(mut self, axes: ScrollAxes) -> Self {
self.axes = axes;
self
}
/// Overrides when the scrollbar shows, instead of the platform default.
pub fn visibility(mut self, visibility: ScrollbarVisibility) -> Self {
self.visibility = visibility;
self
}
/// Scrolls with a handle held on the owning view.
pub fn handle(mut self, handle: ScrollHandle) -> Self {
self.handle = Some(handle);
self
}
/// Overrides the accessibility label of the container.
pub fn accessibility_label<L>(mut self, label: L) -> Self
where
L: Into<SharedString>,
{
self.a11y_label = Some(label.into());
self
}
}
impl RenderOnce for ScrollArea {
fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement {
let mut pane_style = self.style.clone();
pane_style.padding = Default::default();
let pane = div()
.id(self.id.clone())
.overflow_hidden()
.when(self.axes != ScrollAxes::Horizontal, |area| {
area.overflow_y_scroll()
})
.when(self.axes != ScrollAxes::Vertical, |area| {
area.overflow_x_scroll()
})
.when_some(self.handle.clone(), |area, handle| {
area.track_scroll(&handle)
})
.when_some(self.a11y_label, |area, label| area.aria_label(label))
.on_scroll(|_, _, cx| {
// Keep wheel events from scrolling an outer scroll area too.
cx.stop_propagation();
})
.refine_style(&pane_style)
.children(self.children);
div()
.relative()
.refine_style(&self.style)
.child(pane.into_any_element())
.when_some(self.handle, |wrapper, handle| {
let id = self.id.clone();
wrapper
.when(self.axes != ScrollAxes::Horizontal, |wrapper| {
wrapper.child(
Scrollbar::vertical((id.clone(), "v-scrollbar"), handle.clone())
.visibility(self.visibility)
.into_any_element(),
)
})
.when(self.axes != ScrollAxes::Vertical, |wrapper| {
wrapper.child(
Scrollbar::horizontal((id, "h-scrollbar"), handle)
.visibility(self.visibility)
.into_any_element(),
)
})
})
}
}