Move PopoverButton
into ui
(#25724)
This PR moves the `PopoverButton` component into the `ui` crate. The `popover_button` crate only depended on `ui`, so there doesn't seem to be a need for it to live in its own crate and add another step in the crate graph. Release Notes: - N/A
This commit is contained in:
parent
3505a17452
commit
da22f21dec
11 changed files with 13 additions and 47 deletions
|
@ -19,6 +19,7 @@ mod modal;
|
|||
mod navigable;
|
||||
mod numeric_stepper;
|
||||
mod popover;
|
||||
mod popover_button;
|
||||
mod popover_menu;
|
||||
mod radio;
|
||||
mod right_click_menu;
|
||||
|
@ -56,6 +57,7 @@ pub use modal::*;
|
|||
pub use navigable::*;
|
||||
pub use numeric_stepper::*;
|
||||
pub use popover::*;
|
||||
pub use popover_button::*;
|
||||
pub use popover_menu::*;
|
||||
pub use radio::*;
|
||||
pub use right_click_menu::*;
|
||||
|
|
57
crates/ui/src/components/popover_button.rs
Normal file
57
crates/ui/src/components/popover_button.rs
Normal file
|
@ -0,0 +1,57 @@
|
|||
use gpui::{AnyView, Corner, Entity, ManagedView};
|
||||
|
||||
use crate::{prelude::*, PopoverMenu, PopoverMenuHandle, PopoverTrigger};
|
||||
|
||||
pub trait TriggerablePopover: ManagedView {
|
||||
fn menu_handle(
|
||||
&mut self,
|
||||
window: &mut Window,
|
||||
cx: &mut gpui::Context<Self>,
|
||||
) -> PopoverMenuHandle<Self>;
|
||||
}
|
||||
|
||||
pub struct PopoverButton<T, B, F> {
|
||||
selector: Entity<T>,
|
||||
button: B,
|
||||
tooltip: F,
|
||||
corner: Corner,
|
||||
}
|
||||
|
||||
impl<T, B, F> PopoverButton<T, B, F> {
|
||||
pub fn new(selector: Entity<T>, corner: Corner, button: B, tooltip: F) -> Self
|
||||
where
|
||||
F: Fn(&mut Window, &mut App) -> AnyView + 'static,
|
||||
{
|
||||
Self {
|
||||
selector,
|
||||
button,
|
||||
tooltip,
|
||||
corner,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: TriggerablePopover, B: PopoverTrigger + ButtonCommon, F> RenderOnce
|
||||
for PopoverButton<T, B, F>
|
||||
where
|
||||
F: Fn(&mut Window, &mut App) -> AnyView + 'static,
|
||||
{
|
||||
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let menu_handle = self
|
||||
.selector
|
||||
.update(cx, |selector, cx| selector.menu_handle(window, cx));
|
||||
|
||||
PopoverMenu::new("popover-button")
|
||||
.menu({
|
||||
let selector = self.selector.clone();
|
||||
move |_window, _cx| Some(selector.clone())
|
||||
})
|
||||
.trigger_with_tooltip(self.button, self.tooltip)
|
||||
.anchor(self.corner)
|
||||
.with_handle(menu_handle)
|
||||
.offset(gpui::Point {
|
||||
x: px(0.0),
|
||||
y: px(-2.0),
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue