-
Notifications
You must be signed in to change notification settings - Fork 567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use ArcStr in LocalizedString and LabelText #1245
Conversation
7530005
to
e101e2b
Compare
5291c12
to
b6e7216
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -310,8 +316,8 @@ impl<T: Data> Label<T> { | |||
impl<T> Dynamic<T> { | |||
fn resolve(&mut self, data: &T, env: &Env) -> bool { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah totally if AsRef
is available, I thought this was only available via deref. :)
CHANGELOG.md
Outdated
- 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This diff looks weird… Did you delete the #1205
entry intentionally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!
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.