Skip to main content

gpui_component/dialog/
title.rs

1use gpui::{
2    AnyElement, App, IntoElement, ParentElement, RenderOnce, StyleRefinement, Styled, Window,
3    relative,
4};
5use gpui_base::DialogTitle as BaseDialogTitle;
6
7use crate::StyledExt as _;
8
9/// Title element for a dialog header.
10#[derive(IntoElement)]
11pub struct DialogTitle {
12    base: BaseDialogTitle,
13    style: StyleRefinement,
14    children: Vec<AnyElement>,
15}
16
17impl DialogTitle {
18    pub fn new() -> Self {
19        Self {
20            base: BaseDialogTitle::new(),
21            style: StyleRefinement::default(),
22            children: vec![],
23        }
24    }
25}
26
27impl ParentElement for DialogTitle {
28    fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>) {
29        self.children.extend(elements);
30    }
31}
32
33impl Styled for DialogTitle {
34    fn style(&mut self) -> &mut StyleRefinement {
35        &mut self.style
36    }
37}
38
39impl RenderOnce for DialogTitle {
40    fn render(self, _: &mut Window, _: &mut App) -> impl IntoElement {
41        self.base
42            .text_base()
43            .font_semibold()
44            .line_height(relative(1.))
45            .refine_style(&self.style)
46            .children(self.children)
47    }
48}