Extend tooltip to take meta + kb

This commit is contained in:
Nate Butler 2023-11-14 12:59:53 -05:00
parent 5ae96e4eb6
commit 251b4640c6
2 changed files with 63 additions and 13 deletions

View file

@ -1,32 +1,57 @@
use gpui::{div, Div, ParentElement, Render, SharedString, Styled, ViewContext};
use gpui::{div, Component, Div, ParentElement, Render, SharedString, Styled, ViewContext};
use theme2::ActiveTheme;
use crate::StyledExt;
use crate::{h_stack, v_stack, Label, LabelColor, StyledExt};
use super::keybinding;
#[derive(Clone, Debug)]
pub struct TextTooltip {
title: SharedString,
meta: Option<SharedString>,
keybinding: Option<SharedString>,
}
impl TextTooltip {
pub fn new(title: impl Into<SharedString>) -> Self {
Self {
title: title.into(),
meta: None,
keybinding: None,
}
}
pub fn meta(mut self, meta: impl Into<SharedString>) -> Self {
self.meta = Some(meta.into());
self
}
pub fn keybinding(mut self, keybinding: impl Into<SharedString>) -> Self {
self.keybinding = Some(keybinding.into());
self
}
}
impl Render for TextTooltip {
type Element = Div<Self>;
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
div()
v_stack()
.elevation_2(cx)
.font("Zed Sans")
.text_ui()
.text_ui_sm()
.text_color(cx.theme().colors().text)
.py_1()
.px_2()
.child(self.title.clone())
.child(h_stack().child(self.title.clone()).when_some(
self.keybinding.clone(),
|this, keybinding| {
this.justify_between()
.child(Label::new(keybinding).color(LabelColor::Muted))
},
))
.when_some(self.meta.clone(), |this, meta| {
this.child(Label::new(meta).color(LabelColor::Muted))
})
}
}