Skip to content

Commit

Permalink
Do not require Copy for text StyleSheet::Style
Browse files Browse the repository at this point in the history
For most widgets, `Style` only requires `Default`. A few require
`Clone`. Only this one requires `Copy`.

Some of the types in the default theme has a custom variant requiring
`Box<dyn Trait>`, or `Rc<dyn Trait>` to provide `Clone`, but this isn't
possible if `Copy` is required.

It would be good to also address the inconsistency of requiring `Clone`
in some places and not others.

This removes `style/src/text.rs` which is unused in this branch and thus
confusing. If there's a reason to keep it, that can be removed from the
change.
  • Loading branch information
ids1024 committed Apr 27, 2023
1 parent c31ab8e commit 07c64bc
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 24 deletions.
6 changes: 3 additions & 3 deletions core/src/widget/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ where
&self.content,
self.size,
self.font,
theme.appearance(self.style),
theme.appearance(self.style.clone()),
self.horizontal_alignment,
self.vertical_alignment,
);
Expand Down Expand Up @@ -233,7 +233,7 @@ where
horizontal_alignment: self.horizontal_alignment,
vertical_alignment: self.vertical_alignment,
font: self.font,
style: self.style,
style: self.style.clone(),
}
}
}
Expand Down Expand Up @@ -261,7 +261,7 @@ where
/// The style sheet of some text.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
type Style: Default + Copy;
type Style: Default + Clone;

/// Produces the [`Appearance`] of some text.
fn appearance(&self, style: Self::Style) -> Appearance;
Expand Down
20 changes: 0 additions & 20 deletions style/src/text.rs

This file was deleted.

2 changes: 1 addition & 1 deletion style/src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ impl scrollable::StyleSheet for Theme {
}

/// The style of text.
#[derive(Clone, Copy, Default)]
#[derive(Clone, Default)]
pub enum Text {
/// The default style.
#[default]
Expand Down

0 comments on commit 07c64bc

Please sign in to comment.