diff --git a/crates/search2/src/search_bar.rs b/crates/search2/src/search_bar.rs index 1a7456f41c462626e5d6bb78e9e4749735e067e6..f5a9a8c8f7b45ade744c35ed3c9b6bc9aa122595 100644 --- a/crates/search2/src/search_bar.rs +++ b/crates/search2/src/search_bar.rs @@ -1,4 +1,4 @@ -use gpui::{IntoElement, MouseDownEvent, WindowContext}; +use gpui::{ClickEvent, IntoElement, WindowContext}; use ui::{Button, ButtonVariant, IconButton}; use crate::mode::SearchMode; @@ -6,7 +6,7 @@ use crate::mode::SearchMode; pub(super) fn render_nav_button( icon: ui::Icon, _active: bool, - on_click: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static, + on_click: impl Fn(&ClickEvent, &mut WindowContext) + 'static, ) -> impl IntoElement { // let tooltip_style = cx.theme().tooltip.clone(); // let cursor_style = if active { @@ -21,7 +21,7 @@ pub(super) fn render_nav_button( pub(crate) fn render_search_mode_button( mode: SearchMode, is_active: bool, - on_click: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static, + on_click: impl Fn(&ClickEvent, &mut WindowContext) + 'static, ) -> Button { let button_variant = if is_active { ButtonVariant::Filled diff --git a/crates/ui2/src/components/button.rs b/crates/ui2/src/components/button.rs index 02902a4b64800e22128d89c5048c1aefc03c5867..fbe5b951fa116b70ebcc50d34154cb15b26c4492 100644 --- a/crates/ui2/src/components/button.rs +++ b/crates/ui2/src/components/button.rs @@ -1,9 +1,7 @@ -use std::rc::Rc; - use gpui::{ - DefiniteLength, Div, Hsla, IntoElement, MouseButton, MouseDownEvent, - StatefulInteractiveElement, WindowContext, + ClickEvent, DefiniteLength, Div, Hsla, IntoElement, StatefulInteractiveElement, WindowContext, }; +use std::rc::Rc; use crate::prelude::*; use crate::{h_stack, Color, Icon, IconButton, IconElement, Label, LineHeightStyle}; @@ -67,7 +65,7 @@ impl ButtonVariant { #[derive(IntoElement)] pub struct Button { disabled: bool, - click_handler: Option>, + click_handler: Option>, icon: Option, icon_position: Option, label: SharedString, @@ -118,7 +116,7 @@ impl RenderOnce for Button { } if let Some(click_handler) = self.click_handler.clone() { - button = button.on_mouse_down(MouseButton::Left, move |event, cx| { + button = button.on_click(move |event, cx| { click_handler(event, cx); }); } @@ -168,10 +166,7 @@ impl Button { self } - pub fn on_click( - mut self, - handler: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static, - ) -> Self { + pub fn on_click(mut self, handler: impl Fn(&ClickEvent, &mut WindowContext) + 'static) -> Self { self.click_handler = Some(Rc::new(handler)); self } diff --git a/crates/ui2/src/components/disclosure.rs b/crates/ui2/src/components/disclosure.rs index e0d7b1c5192611b9b2690601aaca77d6e1f89736..6206a2edd883f5abb959c9a00bde1824dc28a309 100644 --- a/crates/ui2/src/components/disclosure.rs +++ b/crates/ui2/src/components/disclosure.rs @@ -1,12 +1,12 @@ use std::rc::Rc; -use gpui::{div, Element, IntoElement, MouseDownEvent, ParentElement, WindowContext}; +use gpui::{div, ClickEvent, Element, IntoElement, ParentElement, WindowContext}; use crate::{Color, Icon, IconButton, IconSize, Toggle}; pub fn disclosure_control( toggle: Toggle, - on_toggle: Option>, + on_toggle: Option>, ) -> impl Element { match (toggle.is_toggleable(), toggle.is_toggled()) { (false, _) => div(), diff --git a/crates/ui2/src/components/icon_button.rs b/crates/ui2/src/components/icon_button.rs index 2ccda3ea0e531d2ff643b1b95dcf5309c8167205..cdaec6a7701a64ca4cb651933cbd8b9cac67ffeb 100644 --- a/crates/ui2/src/components/icon_button.rs +++ b/crates/ui2/src/components/icon_button.rs @@ -1,5 +1,5 @@ use crate::{h_stack, prelude::*, Icon, IconElement, IconSize}; -use gpui::{prelude::*, Action, AnyView, Div, MouseButton, MouseDownEvent, Stateful}; +use gpui::{prelude::*, Action, AnyView, ClickEvent, Div, Stateful}; #[derive(IntoElement)] pub struct IconButton { @@ -11,7 +11,7 @@ pub struct IconButton { state: InteractionState, selected: bool, tooltip: Option AnyView + 'static>>, - on_mouse_down: Option>, + on_click: Option>, } impl RenderOnce for IconButton { @@ -57,9 +57,8 @@ impl RenderOnce for IconButton { .color(icon_color), ); - if let Some(click_handler) = self.on_mouse_down { - button = button.on_mouse_down(MouseButton::Left, move |event, cx| { - cx.stop_propagation(); + if let Some(click_handler) = self.on_click { + button = button.on_click(move |event, cx| { click_handler(event, cx); }) } @@ -85,7 +84,7 @@ impl IconButton { state: InteractionState::default(), selected: false, tooltip: None, - on_mouse_down: None, + on_click: None, } } @@ -124,11 +123,8 @@ impl IconButton { self } - pub fn on_click( - mut self, - handler: impl 'static + Fn(&MouseDownEvent, &mut WindowContext), - ) -> Self { - self.on_mouse_down = Some(Box::new(handler)); + pub fn on_click(mut self, handler: impl 'static + Fn(&ClickEvent, &mut WindowContext)) -> Self { + self.on_click = Some(Box::new(handler)); self } diff --git a/crates/ui2/src/components/list.rs b/crates/ui2/src/components/list.rs index f3e75f272dcbe14b59df0eb790881c153db5f933..aa61c8333e50508db0357fb28c91533e46d84650 100644 --- a/crates/ui2/src/components/list.rs +++ b/crates/ui2/src/components/list.rs @@ -177,7 +177,7 @@ pub struct ListItem { toggle: Toggle, inset: bool, on_click: Option>, - on_toggle: Option>, + on_toggle: Option>, on_secondary_mouse_down: Option>, children: SmallVec<[AnyElement; 2]>, } @@ -234,7 +234,7 @@ impl ListItem { pub fn on_toggle( mut self, - on_toggle: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static, + on_toggle: impl Fn(&ClickEvent, &mut WindowContext) + 'static, ) -> Self { self.on_toggle = Some(Rc::new(on_toggle)); self