diff --git a/crates/ui/src/label.rs b/crates/ui/src/label.rs index ec4030fe..823e4048 100644 --- a/crates/ui/src/label.rs +++ b/crates/ui/src/label.rs @@ -1,12 +1,24 @@ -use gpui::{div, Div, IntoElement, ParentElement, RenderOnce, SharedString, Styled, WindowContext}; +use gpui::{ + div, prelude::FluentBuilder, Div, IntoElement, ParentElement, RenderOnce, SharedString, Styled, + WindowContext, +}; -use crate::theme::ActiveTheme; +use crate::{h_flex, theme::ActiveTheme}; + +#[derive(Default)] +pub enum TextAlign { + #[default] + Left, + Center, + Right, +} #[derive(IntoElement)] pub struct Label { base: Div, label: SharedString, multiple_lines: bool, + align: TextAlign, } impl Label { @@ -15,6 +27,7 @@ impl Label { base: div(), label: label.into(), multiple_lines: true, + align: TextAlign::default(), } } @@ -22,6 +35,11 @@ impl Label { self.multiple_lines = true; self } + + pub fn text_align(mut self, align: TextAlign) -> Self { + self.align = align; + self + } } impl Styled for Label { @@ -38,7 +56,12 @@ impl RenderOnce for Label { self.label }; - div() + h_flex() + .map(|this| match self.align { + TextAlign::Left => this.justify_start(), + TextAlign::Center => this.justify_center(), + TextAlign::Right => this.justify_end(), + }) .text_color(cx.theme().foreground) .child(self.base.child(text)) }