Merge branch 'main' into element-types
This commit is contained in:
commit
5dda105182
31 changed files with 1154 additions and 1029 deletions
|
@ -1,6 +1,6 @@
|
|||
use crate::{h_stack, prelude::*};
|
||||
use crate::{ClickHandler, Icon, IconColor, IconElement};
|
||||
use gpui::{prelude::*, rems, MouseButton};
|
||||
use crate::{ClickHandler, Icon, IconColor, IconElement, TextTooltip};
|
||||
use gpui::{prelude::*, MouseButton, VisualContext};
|
||||
use std::sync::Arc;
|
||||
|
||||
struct IconButtonHandlers<V: 'static> {
|
||||
|
@ -20,6 +20,7 @@ pub struct IconButton<V: 'static> {
|
|||
color: IconColor,
|
||||
variant: ButtonVariant,
|
||||
state: InteractionState,
|
||||
tooltip: Option<SharedString>,
|
||||
handlers: IconButtonHandlers<V>,
|
||||
}
|
||||
|
||||
|
@ -31,6 +32,7 @@ impl<V: 'static> IconButton<V> {
|
|||
color: IconColor::default(),
|
||||
variant: ButtonVariant::default(),
|
||||
state: InteractionState::default(),
|
||||
tooltip: None,
|
||||
handlers: IconButtonHandlers::default(),
|
||||
}
|
||||
}
|
||||
|
@ -55,6 +57,11 @@ impl<V: 'static> IconButton<V> {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn tooltip(mut self, tooltip: impl Into<SharedString>) -> Self {
|
||||
self.tooltip = Some(tooltip.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn on_click(
|
||||
mut self,
|
||||
handler: impl 'static + Fn(&mut V, &mut ViewContext<V>) + Send + Sync,
|
||||
|
@ -86,9 +93,7 @@ impl<V: 'static> IconButton<V> {
|
|||
.id(self.id.clone())
|
||||
.justify_center()
|
||||
.rounded_md()
|
||||
// todo!("Where do these numbers come from?")
|
||||
.py(rems(0.21875))
|
||||
.px(rems(0.375))
|
||||
.p_1()
|
||||
.bg(bg_color)
|
||||
.hover(|style| style.bg(bg_hover_color))
|
||||
.active(|style| style.bg(bg_active_color))
|
||||
|
@ -101,6 +106,11 @@ impl<V: 'static> IconButton<V> {
|
|||
});
|
||||
}
|
||||
|
||||
if let Some(tooltip) = self.tooltip.clone() {
|
||||
button =
|
||||
button.tooltip(move |_, cx| cx.build_view(|cx| TextTooltip::new(tooltip.clone())));
|
||||
}
|
||||
|
||||
button
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue