Skip to content

Commit

Permalink
Update Label masked char (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee authored Jul 24, 2024
1 parent 22a15c7 commit d63e256
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions crates/ui/src/label.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use gpui::{
div, prelude::FluentBuilder, Div, IntoElement, ParentElement, RenderOnce, SharedString, Styled,
WindowContext,
div, prelude::FluentBuilder, rems, Div, IntoElement, ParentElement, RenderOnce, SharedString,
Styled, WindowContext,
};

use crate::{h_flex, theme::ActiveTheme};
use crate::theme::ActiveTheme;

#[derive(Default)]
pub enum TextAlign {
Expand All @@ -25,7 +25,7 @@ pub struct Label {
impl Label {
pub fn new(label: impl Into<SharedString>) -> Self {
Self {
base: div(),
base: div().line_height(rems(1.25)),
label: label.into(),
multiple_lines: true,
align: TextAlign::default(),
Expand Down Expand Up @@ -55,6 +55,8 @@ impl Styled for Label {
}
}

const MASKED: &'static str = "•";

impl RenderOnce for Label {
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
let text = if !self.multiple_lines {
Expand All @@ -64,12 +66,12 @@ impl RenderOnce for Label {
};

let text_display = if self.marked {
"*".repeat(text.chars().count())
MASKED.repeat(text.chars().count())
} else {
text.to_string()
};

h_flex()
div()
.map(|this| match self.align {
TextAlign::Left => this.justify_start(),
TextAlign::Center => this.justify_center(),
Expand Down

0 comments on commit d63e256

Please sign in to comment.