-
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
Add RichTextBuilder #1520
Add RichTextBuilder #1520
Conversation
😅 I forgot cargo fmt and cargo test. |
Maybe I should add methods like |
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.
Cool this looks good to me, I have a few little tweaks but overall happy to take this patch! :)
druid/src/text/rich_text.rs
Outdated
/// # use druid::text::{RichTextBuilder, Attribute}; | ||
/// let mut rich_text = RichTextBuilder::new(); | ||
/// rich_text.push("Hello World").underline(true); | ||
/// let rich_text = rich_text.build(); |
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 slightly richer example:
/// # use druid::text::{RichTextBuilder, Attribute}; | |
/// let mut rich_text = RichTextBuilder::new(); | |
/// rich_text.push("Hello World").underline(true); | |
/// let rich_text = rich_text.build(); | |
/// # use druid::text::{Attribute, RichTextBuilder}; | |
/// # use druid::FontWeight; | |
/// let mut builder = RichTextBuilder::new(); | |
/// builder.push("Hello "); | |
/// builder.push("World!").weight(FontWeight::Bold); | |
/// let rich_text = rich_text.build(); |
druid/src/text/rich_text.rs
Outdated
Self::default() | ||
} | ||
|
||
/// Add string to the end of text and `AttributesAdder` for the added string. |
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.
/// Add string to the end of text and `AttributesAdder` for the added string. | |
/// Append a `&str` to the end of the text. | |
/// | |
/// This method returns a [`AttributesAddr`] that can be used to style the newly | |
/// added string slice. |
druid/src/text/rich_text.rs
Outdated
/// Get the `AttributesAdder` for the range. | ||
pub fn range(&mut self, range: Range<usize>) -> AttributesAdder { |
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'd give this a slightly more verbose name:
/// Get the `AttributesAdder` for the range. | |
pub fn range(&mut self, range: Range<usize>) -> AttributesAdder { | |
/// Get an [`AttributesAdder`] for the given range. | |
/// | |
/// This can be used to modify styles for a given range after it has been added. | |
pub fn add_attributes_for_range(&mut self, range: Range<usize>) -> AttributesAdder { |
also changed |
I think squashing is a good idea 😅. Please add instructions to setup hooks on windows |
not sure what this is referring to :) |
this doesn't work for windows. |
@maan2003 hm I don't now much about this, but maybe search for "git hooks on windows" and see what's involved? would be happy to take a PR that updates those docs. |
I have decided to move
RichText
into a separate module not sure if it is better to keep it insidestorage