WIP
This commit is contained in:
parent
58f9ef99f7
commit
fc5ec47cc8
3 changed files with 218 additions and 247 deletions
|
@ -1,8 +1,8 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use gpui::{rems, MouseButton};
|
||||
use gpui::{rems, MouseButton, VisualContext};
|
||||
|
||||
use crate::{h_stack, prelude::*};
|
||||
use crate::{h_stack, prelude::*, TextTooltip};
|
||||
use crate::{ClickHandler, Icon, IconColor, IconElement};
|
||||
|
||||
struct IconButtonHandlers<V: 'static> {
|
||||
|
@ -22,6 +22,7 @@ pub struct IconButton<V: 'static> {
|
|||
color: IconColor,
|
||||
variant: ButtonVariant,
|
||||
state: InteractionState,
|
||||
tooltip: Option<SharedString>,
|
||||
handlers: IconButtonHandlers<V>,
|
||||
}
|
||||
|
||||
|
@ -33,6 +34,7 @@ impl<V: 'static> IconButton<V> {
|
|||
color: IconColor::default(),
|
||||
variant: ButtonVariant::default(),
|
||||
state: InteractionState::default(),
|
||||
tooltip: None,
|
||||
handlers: IconButtonHandlers::default(),
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +59,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,
|
||||
|
@ -103,6 +110,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