-
Notifications
You must be signed in to change notification settings - Fork 568
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
Basic rich text #1255
Basic rich text #1255
Conversation
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 { |
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 rename this? with_
seems to suggest a builder method.
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 think from_
would be appropriate here? (It consumes the text, right?)
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.
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.
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 is a pair of commits that allow for the creation of a rich text object, that can be displayed in a
RawLabel
or anything else that uses aTextLayout
object.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
FontDescriptor
as 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 usingRichText
we ignore anything set on the label itself.You can play with this at
examples/text.rs
: