impl Clone for LabelText
//! A label widget.
use std::ops::{Deref, DerefMut};
+use std::sync::Arc;
use druid_shell::Cursor;
@@ -120,6 +121,7 @@ pub enum LineBreaking {
/// [`ArcStr`]: ../type.ArcStr.html
/// [`LocalizedString`]: ../struct.LocalizedString.html
/// [`Label`]: struct.Label.html
+#[derive(Clone)]
pub enum LabelText<T> {
/// Localized string that will be resolved through `Env`.
Localized(LocalizedString<T>),
@@ -131,12 +133,14 @@ pub enum LabelText<T> {
}
/// Text that is computed dynamically.
+#[derive(Clone)]
pub struct Dynamic<T> {
- f: Box<dyn Fn(&T, &Env) -> String>,
+ f: Arc<dyn Fn(&T, &Env) -> String>,
resolved: ArcStr,
}
/// Static text.
+#[derive(Debug, Clone)]
pub struct Static {
/// The text.
string: ArcStr,
@@ -676,7 +680,7 @@ impl<T> From<LocalizedString<T>> for LabelText<T> {
impl<T, F: Fn(&T, &Env) -> String + 'static> From<F> for LabelText<T> {
fn from(src: F) -> LabelText<T> {
- let f = Box::new(src);
+ let f = Arc::new(src);
LabelText::Dynamic(Dynamic {
f,
resolved: ArcStr::from(""),
