Titlebar project menu double click (#3784)

This addresses a bug where popover menus in the titlebar were rendered
only after a 2nd click. The first click was creating the View which the
second one then rendered.
In addition to this, `PopoverMenu::menu` function argument can now
return an `Option<View<T>>` instead of `View<T>` as the creation of the
menu can fail (as it might in case of git popover).

Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz
2023-12-22 17:18:12 +01:00
committed by GitHub
parent 172e434bec
commit dc1ed3c39d
6 changed files with 67 additions and 126 deletions
+6 -4
View File
@@ -18,19 +18,19 @@ pub struct PopoverMenu<M: ManagedView> {
Box<
dyn FnOnce(
Rc<RefCell<Option<View<M>>>>,
Option<Rc<dyn Fn(&mut WindowContext) -> View<M> + 'static>>,
Option<Rc<dyn Fn(&mut WindowContext) -> Option<View<M>> + 'static>>,
) -> AnyElement
+ 'static,
>,
>,
menu_builder: Option<Rc<dyn Fn(&mut WindowContext) -> View<M> + 'static>>,
menu_builder: Option<Rc<dyn Fn(&mut WindowContext) -> Option<View<M>> + 'static>>,
anchor: AnchorCorner,
attach: Option<AnchorCorner>,
offset: Option<Point<Pixels>>,
}
impl<M: ManagedView> PopoverMenu<M> {
pub fn menu(mut self, f: impl Fn(&mut WindowContext) -> View<M> + 'static) -> Self {
pub fn menu(mut self, f: impl Fn(&mut WindowContext) -> Option<View<M>> + 'static) -> Self {
self.menu_builder = Some(Rc::new(f));
self
}
@@ -42,7 +42,9 @@ impl<M: ManagedView> PopoverMenu<M> {
.when_some(builder, |el, builder| {
el.on_click({
move |_, cx| {
let new_menu = (builder)(cx);
let Some(new_menu) = (builder)(cx) else {
return;
};
let menu2 = menu.clone();
let previous_focus_handle = cx.focused();