110 lines
2.7 KiB
Rust
110 lines
2.7 KiB
Rust
use crate::app;
|
|
use gpui::{ParentElement, Refineable as _, Styled, div};
|
|
|
|
#[derive(gpui::IntoElement)]
|
|
pub(crate) struct Text {
|
|
content: gpui::AnyElement,
|
|
style: gpui::StyleRefinement,
|
|
}
|
|
|
|
pub(crate) trait TextContent: gpui::IntoElement {}
|
|
|
|
impl TextContent for &'static str {}
|
|
impl TextContent for String {}
|
|
impl TextContent for gpui::SharedString {}
|
|
|
|
pub(crate) fn text(content: impl TextContent) -> Text {
|
|
Text {
|
|
content: content.into_any_element(),
|
|
style: gpui::StyleRefinement::default()
|
|
.font_weight(gpui::FontWeight::NORMAL)
|
|
.opacity(1.)
|
|
.text_align(gpui::TextAlign::Left)
|
|
.line_height(gpui::relative(1.5)),
|
|
}
|
|
}
|
|
|
|
impl Styled for Text {
|
|
fn style(&mut self) -> &mut gpui::StyleRefinement {
|
|
&mut self.style
|
|
}
|
|
}
|
|
|
|
impl Text {
|
|
pub(crate) fn leading_none(self) -> Self {
|
|
self.line_height(gpui::relative(1.0))
|
|
}
|
|
|
|
pub(crate) fn leading_tight(self) -> Self {
|
|
self.line_height(gpui::relative(1.25))
|
|
}
|
|
|
|
pub(crate) fn leading_snug(self) -> Self {
|
|
self.line_height(gpui::relative(1.375))
|
|
}
|
|
|
|
pub(crate) fn leading_normal(self) -> Self {
|
|
self.line_height(gpui::relative(1.5))
|
|
}
|
|
|
|
pub(crate) fn leading_relaxed(self) -> Self {
|
|
self.line_height(gpui::relative(1.625))
|
|
}
|
|
|
|
pub(crate) fn leading_loose(self) -> Self {
|
|
self.line_height(gpui::relative(2.0))
|
|
}
|
|
|
|
pub(crate) fn leading_3(self) -> Self {
|
|
self.line_height(gpui::rems(0.75))
|
|
}
|
|
|
|
pub(crate) fn leading_4(self) -> Self {
|
|
self.line_height(gpui::rems(1.0))
|
|
}
|
|
|
|
pub(crate) fn leading_5(self) -> Self {
|
|
self.line_height(gpui::rems(1.25))
|
|
}
|
|
|
|
pub(crate) fn leading_6(self) -> Self {
|
|
self.line_height(gpui::rems(1.5))
|
|
}
|
|
|
|
pub(crate) fn leading_7(self) -> Self {
|
|
self.line_height(gpui::rems(1.75))
|
|
}
|
|
|
|
pub(crate) fn leading_8(self) -> Self {
|
|
self.line_height(gpui::rems(2.0))
|
|
}
|
|
|
|
pub(crate) fn leading_9(self) -> Self {
|
|
self.line_height(gpui::rems(2.25))
|
|
}
|
|
|
|
pub(crate) fn leading_10(self) -> Self {
|
|
self.line_height(gpui::rems(2.5))
|
|
}
|
|
}
|
|
|
|
impl gpui::RenderOnce for Text {
|
|
fn render(self, _window: &mut gpui::Window, cx: &mut gpui::App) -> impl gpui::IntoElement {
|
|
let theme = app::current_theme(cx);
|
|
|
|
let mut div = div().child(self.content);
|
|
div.style().refine(&self.style);
|
|
|
|
if div.style().text.as_ref().and_then(|it| it.color).is_none() {
|
|
// if no text color override, use theme text color
|
|
div = div.text_color(theme.colors.text);
|
|
}
|
|
|
|
if div.style().border_color.as_ref().is_none() {
|
|
div = div.border_color(theme.colors.border);
|
|
}
|
|
|
|
div
|
|
}
|
|
}
|