Merged
Conversation
cmyr
commented
Sep 28, 2020
druid/src/text/layout.rs
Outdated
| /// Create a new `TextLayout` with the provided text. | ||
| /// | ||
| /// This is useful when the text is not died to application data. | ||
| pub fn with_text(text: impl Into<T>) -> Self { |
Member
Author
There was a problem hiding this comment.
maybe rename this? with_ seems to suggest a builder method.
Collaborator
There was a problem hiding this comment.
I think from_ would be appropriate here? (It consumes the text, right?)
raphlinus
approved these changes
Sep 29, 2020
Contributor
raphlinus
left a comment
There was a problem hiding this comment.
Looks good. I can see a few things that might change long term, but nothing that I would consider blocking now.
This isn't actually used anywhere in this commit; it's just an implementation of the types for representing text attributes and storing them in spans.
This adds a TextStorage trait for types that... store text. On top of this, it implements a RichText type, that is a string and a set of style spans. This type is currently immutable, in the sense that it cannot be edited. Editing is something that we would definitely like, at some point, but it expands the scope of this work significantly, and at the very least should be a separate patch.
Member
Author
|
I think there is still some stuff wrong with this PR but I'll open issues for those things, and I think getting it in will unblock some other stuff. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a pair of commits that allow for the creation of a rich text object, that can be displayed in a
RawLabelor anything else that uses aTextLayoutobject.I don't love this code, but it at least covers the simple case, and I think it is worth checkpointing.
Details: for each annotation type, we maintain a sorted vec of non-overlapping spans. The annotation types in druid are slightly different from what is available in piet; in particular in druid we support
FontDescriptoras well as (where possible)KeyOrValue. Druid annotations can be added in any order (not restricted to non-descending start order) and then when we rebuild the layout we resolve them to piet spans and construct the actual layout object.stuff I don't like:
TextLayout, not on theRichText; this should probably change in some way, so that if you're usingRichTextwe ignore anything set on the label itself.You can play with this at
examples/text.rs: