mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-19 18:41:56 +03:00
use the right click event for buttons (#3432)
Previously we used mouse down Release Notes: - N/A
This commit is contained in:
commit
396ecefa4f
@ -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
|
||||
|
@ -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<Rc<dyn Fn(&MouseDownEvent, &mut WindowContext)>>,
|
||||
click_handler: Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext)>>,
|
||||
icon: Option<Icon>,
|
||||
icon_position: Option<IconPosition>,
|
||||
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
|
||||
}
|
||||
|
@ -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<Rc<dyn Fn(&MouseDownEvent, &mut WindowContext) + 'static>>,
|
||||
on_toggle: Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
|
||||
) -> impl Element {
|
||||
match (toggle.is_toggleable(), toggle.is_toggled()) {
|
||||
(false, _) => div(),
|
||||
|
@ -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<Box<dyn Fn(&mut WindowContext) -> AnyView + 'static>>,
|
||||
on_mouse_down: Option<Box<dyn Fn(&MouseDownEvent, &mut WindowContext) + 'static>>,
|
||||
on_click: Option<Box<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -177,7 +177,7 @@ pub struct ListItem {
|
||||
toggle: Toggle,
|
||||
inset: bool,
|
||||
on_click: Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
|
||||
on_toggle: Option<Rc<dyn Fn(&MouseDownEvent, &mut WindowContext) + 'static>>,
|
||||
on_toggle: Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
|
||||
on_secondary_mouse_down: Option<Rc<dyn Fn(&MouseDownEvent, &mut WindowContext) + 'static>>,
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user