feat: apply declarative render rule across components
This commit is contained in:
+33
-32
@@ -1,7 +1,7 @@
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::prelude::FluentBuilder;
|
||||
use gpui::{
|
||||
Animation, AnimationExt as _, AnyElement, App, Bounds, BoxShadow, DispatchPhase, ElementId,
|
||||
Entity, InteractiveElement as _, IntoElement, KeyDownEvent, MouseButton, MouseDownEvent,
|
||||
@@ -127,6 +127,9 @@ impl MenuItem {
|
||||
}
|
||||
}
|
||||
|
||||
// MenuItem is a data builder, not an element, adopt the combinators explicitly.
|
||||
impl FluentBuilder for MenuItem {}
|
||||
|
||||
/// Menu chrome styles.
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct MenuChrome {
|
||||
@@ -288,7 +291,16 @@ impl RenderOnce for Menu {
|
||||
.clone()
|
||||
.unwrap_or_else(|| SharedString::from(self.id.to_string()));
|
||||
|
||||
let mut wrapper = div()
|
||||
let items = if self.open {
|
||||
match self.items {
|
||||
Some(build) => Rc::from(build(window, cx)),
|
||||
None => Rc::from([]),
|
||||
}
|
||||
} else {
|
||||
Rc::from([])
|
||||
};
|
||||
|
||||
div()
|
||||
.relative()
|
||||
.child(
|
||||
canvas(
|
||||
@@ -335,36 +347,25 @@ impl RenderOnce for Menu {
|
||||
)
|
||||
.when_some(self.trigger, |wrapper, trigger| {
|
||||
wrapper.child(trigger(window, cx))
|
||||
});
|
||||
|
||||
let items = if self.open {
|
||||
match self.items {
|
||||
Some(build) => Rc::from(build(window, cx)),
|
||||
None => Rc::from([]),
|
||||
}
|
||||
} else {
|
||||
Rc::from([])
|
||||
};
|
||||
|
||||
if let Some(panel) = anchored_menu_panel(
|
||||
window,
|
||||
cx,
|
||||
&self.id,
|
||||
self.open,
|
||||
items,
|
||||
self.initial_selection,
|
||||
false,
|
||||
self.on_change,
|
||||
fallback_label,
|
||||
self.open_at,
|
||||
&trigger_bounds,
|
||||
&chrome,
|
||||
enter_duration,
|
||||
) {
|
||||
wrapper = wrapper.child(panel);
|
||||
}
|
||||
|
||||
wrapper
|
||||
})
|
||||
.when_some(
|
||||
anchored_menu_panel(
|
||||
window,
|
||||
cx,
|
||||
&self.id,
|
||||
self.open,
|
||||
items,
|
||||
self.initial_selection,
|
||||
false,
|
||||
self.on_change,
|
||||
fallback_label,
|
||||
self.open_at,
|
||||
&trigger_bounds,
|
||||
&chrome,
|
||||
enter_duration,
|
||||
),
|
||||
|wrapper, panel| wrapper.child(panel),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user