Skip to content
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

Merged
merged 1 commit into from
Sep 25, 2020
Merged

Conversation

cmyr
Copy link
Member

@cmyr cmyr commented Sep 18, 2020

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.

@cmyr cmyr added the S-needs-review waits for review label Sep 19, 2020
@cmyr cmyr force-pushed the arcstr-in-labeltext branch from 7530005 to e101e2b Compare September 23, 2020 16:13
@cmyr cmyr force-pushed the arcstr-in-labeltext branch 2 times, most recently from 5291c12 to b6e7216 Compare September 24, 2020 20:31
Copy link
Collaborator

@luleyleo luleyleo left a 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.

Comment on lines 40 to 49
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,
},
Copy link
Collaborator

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.

Comment on lines 56 to 47
#[doc(hidden)]
pub struct Dynamic<T> {
Copy link
Collaborator

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.

@@ -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;
Copy link
Collaborator

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 &*

Suggested change
let changed = new.as_str() != &*self.resolved;
let changed = new.as_str() != self.resolved.as_ref();

Copy link
Member Author

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
Comment on lines 60 to 63
- Contexts' `text()` methods return `&mut PietText` instead of cloning ([#1205] by [@cmyr])
- `LocalizedString` and `LabelText` use `ArcStr` instead of String ([#1245] by [@cmyr])
Copy link
Collaborator

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?

Copy link
Member Author

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.
@cmyr cmyr force-pushed the arcstr-in-labeltext branch from b6e7216 to 067323c Compare September 25, 2020 13:26
@cmyr cmyr merged commit 7a3251b into master Sep 25, 2020
@cmyr cmyr deleted the arcstr-in-labeltext branch September 25, 2020 14:02
@maan2003 maan2003 removed the S-needs-review waits for review label May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants