Use ArcStr in LocalizedString and LabelText#1245
Conversation
7530005 to
e101e2b
Compare
5291c12 to
b6e7216
Compare
luleyleo
left a comment
There was a problem hiding this comment.
A few nits, but seems like a good change.
druid/src/widget/label.rs
Outdated
| Static { | ||
| /// The text. | ||
| string: ArcStr, | ||
| /// Whether or not the `resolved` method has been called yet. | ||
| /// | ||
| /// We want to return `true` from that method when it is first called, | ||
| /// so that callers will know to retrieve the text. This matches | ||
| /// the behaviour of the other variants. | ||
| resolved: bool, | ||
| }, |
There was a problem hiding this comment.
Maybe move this into its own Static struct the way we did with Dynamic? Then we could hide the resolved field.
druid/src/widget/label.rs
Outdated
| #[doc(hidden)] | ||
| pub struct Dynamic<T> { |
There was a problem hiding this comment.
Not really related to this PR, but I think it is a bit irritating that Dynamic is doc(hidden). It makes the LabelText documentation slightly weird, because Dynamic looks like a broken link.
druid/src/widget/label.rs
Outdated
| let new = (self.f)(data, env); | ||
| let changed = new != self.resolved; | ||
| self.resolved = new; | ||
| let changed = new.as_str() != &*self.resolved; |
There was a problem hiding this comment.
I usually prefer as_ref over &*
| let changed = new.as_str() != &*self.resolved; | |
| let changed = new.as_str() != self.resolved.as_ref(); |
There was a problem hiding this comment.
ah totally if AsRef is available, I thought this was only available via deref. :)
| - `Movement::RightOfLine` to `Movement::NextLineBreak`, and `Movement::LeftOfLine` to `Movement::PrecedingLineBreak`. ([#1092] by [@sysint64]) | ||
| - `AnimFrame` was moved from `lifecycle` to `event` ([#1155] by [@jneem]) | ||
| - Contexts' `text()` methods return `&mut PietText` instead of cloning ([#1205] by [@cmyr]) | ||
| - `LocalizedString` and `LabelText` use `ArcStr` instead of String ([#1245] by [@cmyr]) |
There was a problem hiding this comment.
This diff looks weird… Did you delete the #1205 entry intentionally?
This lets us share our text between druid and the piet layout object, and starts the process of moving us away from using String where possible. This was motivated by explorations around making Label optionally work as a `Widget<ArcStr>`, and using lens-like adapters to generate that text from some other data types as needed; this would be a small improvement of the label API.
b6e7216 to
067323c
Compare
This lets us share our text between druid and the piet layout
object, and starts the process of moving us away from using String
where possible.
This was motivated by explorations around making Label optionally work
as a
Widget<ArcStr>, and using lens-like adapters to generatethat text from some other data types as needed; this would be a small
improvement of the label API.