Update Label masked char (#67)
This commit is contained in:
parent
22a15c7dcc
commit
d63e256f19
1 changed files with 8 additions and 6 deletions
|
|
@ -1,9 +1,9 @@
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, prelude::FluentBuilder, Div, IntoElement, ParentElement, RenderOnce, SharedString, Styled,
|
div, prelude::FluentBuilder, rems, Div, IntoElement, ParentElement, RenderOnce, SharedString,
|
||||||
WindowContext,
|
Styled, WindowContext,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{h_flex, theme::ActiveTheme};
|
use crate::theme::ActiveTheme;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub enum TextAlign {
|
pub enum TextAlign {
|
||||||
|
|
@ -25,7 +25,7 @@ pub struct Label {
|
||||||
impl Label {
|
impl Label {
|
||||||
pub fn new(label: impl Into<SharedString>) -> Self {
|
pub fn new(label: impl Into<SharedString>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
base: div(),
|
base: div().line_height(rems(1.25)),
|
||||||
label: label.into(),
|
label: label.into(),
|
||||||
multiple_lines: true,
|
multiple_lines: true,
|
||||||
align: TextAlign::default(),
|
align: TextAlign::default(),
|
||||||
|
|
@ -55,6 +55,8 @@ impl Styled for Label {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MASKED: &'static str = "•";
|
||||||
|
|
||||||
impl RenderOnce for Label {
|
impl RenderOnce for Label {
|
||||||
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
||||||
let text = if !self.multiple_lines {
|
let text = if !self.multiple_lines {
|
||||||
|
|
@ -64,12 +66,12 @@ impl RenderOnce for Label {
|
||||||
};
|
};
|
||||||
|
|
||||||
let text_display = if self.marked {
|
let text_display = if self.marked {
|
||||||
"*".repeat(text.chars().count())
|
MASKED.repeat(text.chars().count())
|
||||||
} else {
|
} else {
|
||||||
text.to_string()
|
text.to_string()
|
||||||
};
|
};
|
||||||
|
|
||||||
h_flex()
|
div()
|
||||||
.map(|this| match self.align {
|
.map(|this| match self.align {
|
||||||
TextAlign::Left => this.justify_start(),
|
TextAlign::Left => this.justify_start(),
|
||||||
TextAlign::Center => this.justify_center(),
|
TextAlign::Center => this.justify_center(),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue