core: implement fluent builder for data builders

This commit is contained in:
2026-11-15 19:43:37 +07:00
parent 3fe4ac4427
commit fd6a8c0342
9 changed files with 39 additions and 9 deletions
+4 -1
View File
@@ -8,7 +8,7 @@
use std::cell::RefCell; use std::cell::RefCell;
use std::rc::Rc; use std::rc::Rc;
use gpui::prelude::FluentBuilder as _; use gpui::prelude::FluentBuilder;
use gpui::{ use gpui::{
App, Bounds, Context, ElementId, Entity, InteractiveElement as _, IntoElement, KeyBinding, App, Bounds, Context, ElementId, Entity, InteractiveElement as _, IntoElement, KeyBinding,
MouseButton, MouseDownEvent, ParentElement as _, Pixels, Render, Role, ScrollHandle, MouseButton, MouseDownEvent, ParentElement as _, Pixels, Render, Role, ScrollHandle,
@@ -183,6 +183,9 @@ where
} }
} }
// Combobox is a data builder, not an element, adopt the combinators explicitly.
impl<T> FluentBuilder for Combobox<T> where T: Clone + PartialEq + 'static {}
/// The stateful combobox. /// The stateful combobox.
pub struct ComboboxState<T> pub struct ComboboxState<T>
where where
+7 -1
View File
@@ -2,7 +2,7 @@
use std::rc::Rc; use std::rc::Rc;
use gpui::prelude::FluentBuilder as _; use gpui::prelude::FluentBuilder;
use gpui::{ use gpui::{
AnyElement, App, Context, ElementId, Entity, InteractiveElement as _, IntoElement, KeyBinding, AnyElement, App, Context, ElementId, Entity, InteractiveElement as _, IntoElement, KeyBinding,
MouseButton, ParentElement as _, Render, Role, ScrollHandle, SharedString, MouseButton, ParentElement as _, Render, Role, ScrollHandle, SharedString,
@@ -87,6 +87,9 @@ impl Command {
} }
} }
// Command is a data builder, not an element, adopt the combinators explicitly.
impl FluentBuilder for Command {}
/// Filters and ranks the commands for a query. /// Filters and ranks the commands for a query.
pub type CommandMatcher = Rc<dyn Fn(&str, &[Command]) -> Vec<Command>>; pub type CommandMatcher = Rc<dyn Fn(&str, &[Command]) -> Vec<Command>>;
/// Runs the chosen command. /// Runs the chosen command.
@@ -148,6 +151,9 @@ impl CommandPalette {
} }
} }
// CommandPalette is a data builder, not an element, adopt the combinators explicitly.
impl FluentBuilder for CommandPalette {}
/// The stateful palette. /// The stateful palette.
pub struct CommandPaletteState { pub struct CommandPaletteState {
id: ElementId, id: ElementId,
+4 -1
View File
@@ -1,4 +1,4 @@
use gpui::prelude::FluentBuilder as _; use gpui::prelude::FluentBuilder;
use gpui::{ use gpui::{
App, ElementId, InteractiveElement as _, IntoElement, ParentElement as _, RenderOnce, Role, App, ElementId, InteractiveElement as _, IntoElement, ParentElement as _, RenderOnce, Role,
SharedString, StatefulInteractiveElement as _, Styled as _, Toggled, Window, div, SharedString, StatefulInteractiveElement as _, Styled as _, Toggled, Window, div,
@@ -67,6 +67,9 @@ where
} }
} }
// Radio is a data builder, not an element, adopt the combinators explicitly.
impl<V> FluentBuilder for Radio<V> {}
/// Group of radio buttons. /// Group of radio buttons.
#[derive(IntoElement)] #[derive(IntoElement)]
#[must_use] #[must_use]
+4 -1
View File
@@ -1,6 +1,6 @@
use std::rc::Rc; use std::rc::Rc;
use gpui::prelude::FluentBuilder as _; use gpui::prelude::FluentBuilder;
use gpui::{ use gpui::{
AnimationExt as _, App, Bounds, ElementId, Entity, InteractiveElement as _, IntoElement, AnimationExt as _, App, Bounds, ElementId, Entity, InteractiveElement as _, IntoElement,
KeyDownEvent, ParentElement as _, Point, RenderOnce, Role, SharedString, SpringAnimation, KeyDownEvent, ParentElement as _, Point, RenderOnce, Role, SharedString, SpringAnimation,
@@ -60,6 +60,9 @@ where
} }
} }
// SegmentedOption is a data builder, not an element, adopt the combinators explicitly.
impl<T> FluentBuilder for SegmentedOption<T> {}
/// A pill strip of mutually exclusive choices. /// A pill strip of mutually exclusive choices.
#[derive(IntoElement)] #[derive(IntoElement)]
#[must_use] #[must_use]
+4 -1
View File
@@ -1,6 +1,6 @@
use std::rc::Rc; use std::rc::Rc;
use gpui::prelude::FluentBuilder as _; use gpui::prelude::FluentBuilder;
use gpui::{ use gpui::{
App, ElementId, InteractiveElement as _, IntoElement, KeyDownEvent, ParentElement as _, App, ElementId, InteractiveElement as _, IntoElement, KeyDownEvent, ParentElement as _,
RenderOnce, Role, SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _,
@@ -61,6 +61,9 @@ where
} }
} }
// SelectOption is a data builder, not an element, adopt the combinators explicitly.
impl<T> FluentBuilder for SelectOption<T> {}
/// A control that shows the chosen value and opens a menu of the choices. /// A control that shows the chosen value and opens a menu of the choices.
#[derive(IntoElement)] #[derive(IntoElement)]
#[must_use] #[must_use]
+4 -1
View File
@@ -3,7 +3,7 @@
use std::rc::Rc; use std::rc::Rc;
use std::time::Duration; use std::time::Duration;
use gpui::prelude::FluentBuilder as _; use gpui::prelude::FluentBuilder;
use gpui::{ use gpui::{
Animation, AnimationExt as _, App, Context, ElementId, Entity, InteractiveElement as _, Animation, AnimationExt as _, App, Context, ElementId, Entity, InteractiveElement as _,
IntoElement, ParentElement as _, RenderOnce, Role, SharedString, IntoElement, ParentElement as _, RenderOnce, Role, SharedString,
@@ -100,6 +100,9 @@ impl Toast {
} }
} }
// Toast is a data builder, not an element, adopt the combinators explicitly.
impl FluentBuilder for Toast {}
/// One raised toast, with its identity in the store. /// One raised toast, with its identity in the store.
#[derive(Clone)] #[derive(Clone)]
pub struct ToastEntry { pub struct ToastEntry {
+4 -1
View File
@@ -1,6 +1,6 @@
use std::rc::Rc; use std::rc::Rc;
use gpui::prelude::FluentBuilder as _; use gpui::prelude::FluentBuilder;
use gpui::{ use gpui::{
AnyElement, App, ElementId, FocusHandle, InteractiveElement as _, IntoElement, KeyDownEvent, AnyElement, App, ElementId, FocusHandle, InteractiveElement as _, IntoElement, KeyDownEvent,
ParentElement as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, ParentElement as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _,
@@ -65,6 +65,9 @@ impl ListItem {
} }
} }
// ListItem is a data builder, not an element, adopt the combinators explicitly.
impl FluentBuilder for ListItem {}
/// A single-selection list. /// A single-selection list.
#[derive(IntoElement)] #[derive(IntoElement)]
#[must_use] #[must_use]
+4 -1
View File
@@ -5,7 +5,7 @@
use std::rc::Rc; use std::rc::Rc;
use gpui::prelude::FluentBuilder as _; use gpui::prelude::FluentBuilder;
use gpui::{ use gpui::{
AnyElement, App, ElementId, FocusHandle, InteractiveElement as _, IntoElement, KeyDownEvent, AnyElement, App, ElementId, FocusHandle, InteractiveElement as _, IntoElement, KeyDownEvent,
ParentElement as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, ParentElement as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _,
@@ -120,6 +120,9 @@ impl SidebarEntry {
} }
} }
// SidebarEntry is a data builder, not an element, adopt the combinators explicitly.
impl FluentBuilder for SidebarEntry {}
/// A sidebar. /// A sidebar.
#[derive(IntoElement)] #[derive(IntoElement)]
#[must_use] #[must_use]
+4 -1
View File
@@ -1,6 +1,6 @@
use std::rc::Rc; use std::rc::Rc;
use gpui::prelude::FluentBuilder as _; use gpui::prelude::FluentBuilder;
use gpui::{ use gpui::{
AnyElement, App, ElementId, FocusHandle, InteractiveElement as _, IntoElement, KeyDownEvent, AnyElement, App, ElementId, FocusHandle, InteractiveElement as _, IntoElement, KeyDownEvent,
ParentElement as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, ParentElement as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _,
@@ -81,6 +81,9 @@ impl TreeItem {
} }
} }
// TreeItem is a data builder, not an element, adopt the combinators explicitly.
impl FluentBuilder for TreeItem {}
/// A tree. /// A tree.
#[derive(IntoElement)] #[derive(IntoElement)]
#[must_use] #[must_use]