refactor: impl Styled for Text
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use crate::app;
|
||||
use gpui::{ParentElement, Styled, div};
|
||||
use gpui::{ParentElement, Refineable as _, Styled, div};
|
||||
|
||||
#[derive(gpui::IntoElement)]
|
||||
pub(crate) struct Text {
|
||||
@@ -10,7 +10,7 @@ pub(crate) struct Text {
|
||||
text_size: Option<gpui::AbsoluteLength>,
|
||||
text_color: Option<gpui::Hsla>,
|
||||
line_height: gpui::DefiniteLength,
|
||||
styled: Option<Box<dyn Fn(gpui::Div) -> gpui::Div>>,
|
||||
style: gpui::StyleRefinement,
|
||||
}
|
||||
|
||||
pub(crate) trait TextContent: gpui::IntoElement {}
|
||||
@@ -28,7 +28,13 @@ pub(crate) fn text(content: impl TextContent) -> Text {
|
||||
text_size: None,
|
||||
text_color: None,
|
||||
line_height: gpui::relative(1.5),
|
||||
styled: None,
|
||||
style: gpui::StyleRefinement::default(),
|
||||
}
|
||||
}
|
||||
|
||||
impl Styled for Text {
|
||||
fn style(&mut self) -> &mut gpui::StyleRefinement {
|
||||
&mut self.style
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,11 +158,6 @@ impl Text {
|
||||
self.line_height(gpui::rems(2.5))
|
||||
}
|
||||
|
||||
pub(crate) fn styled(mut self, styled: impl Fn(gpui::Div) -> gpui::Div + 'static) -> Self {
|
||||
self.styled = Some(Box::new(styled));
|
||||
self
|
||||
}
|
||||
|
||||
pub(crate) fn centered(mut self) -> Self {
|
||||
self.text_align = gpui::TextAlign::Center;
|
||||
self
|
||||
@@ -176,9 +177,7 @@ impl gpui::RenderOnce for Text {
|
||||
if let Some(text_size) = self.text_size {
|
||||
div = div.text_size(text_size);
|
||||
}
|
||||
if let Some(styled) = self.styled {
|
||||
div = styled(div);
|
||||
}
|
||||
div.style().refine(&self.style);
|
||||
div
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user