Skip to content

Commit

Permalink
Add method for getting a label's text
Browse files Browse the repository at this point in the history
  • Loading branch information
cmyr committed Apr 8, 2020
1 parent caa62a8 commit 682fe08
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions druid/src/widget/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ impl<T: Data> Label<T> {
self.text = LabelText::Specific(text.into());
}

/// Returns this label's current text.
pub fn text(&self) -> &str {
self.text.display_text()
}

/// Set the text color.
///
/// The argument can be either a `Color` or a [`Key<Color>`].
Expand Down Expand Up @@ -193,6 +198,15 @@ impl<T: Data> LabelText<T> {
}
}

/// Return the current resolved text.
pub fn display_text(&self) -> &str {
match self {
LabelText::Specific(s) => s.as_str(),
LabelText::Localized(s) => s.localized_str(),
LabelText::Dynamic(s) => s.resolved.as_str(),
}
}

/// Update the localization, if necessary.
/// This ensures that localized strings are up to date.
///
Expand Down

0 comments on commit 682fe08

Please sign in to comment.