-
Notifications
You must be signed in to change notification settings - Fork 52
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
Could glyph_brush_layout::SectionText
be generic over text instead of consuming a str
?
#129
Comments
It's possible layout could be generic over a |
The good news is that yous seem to already have a Open to a PR where i give this a go? |
Yep have a bash |
Something like this passes tests: /// A type which can yield characters for layout.
pub trait CharacterRun {
fn char_indices(&self) -> std::str::CharIndices<'_>;
}
impl<'a> CharacterRun for &'a str {
fn char_indices(&self) -> std::str::CharIndices<'_> {
str::char_indices(self)
}
}
/// Text to layout together using a font & scale.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SectionText<'a, C: CharacterRun = &'a str> {
/// Text to render
pub text: C,
/// Position on screen to render text, in pixels from top-left. Defaults to (0, 0).
pub scale: PxScale,
/// Font id to use for this section.
///
/// It must be a valid id in the `FontMap` used for layout calls.
/// The default `FontId(0)` should always be valid.
pub font_id: FontId,
pub marker: std::marker::PhantomData<&'a C>,
} The downside being you now need to specify SectionText {
text: "hello ",
scale: PxScale::from(20.0),
font_id: FontId(0),
..SectionText::default()
}, wdyt? Should I continue with this approach? |
Friendly ping :) Are you okay with the above approach? |
Hey, sorry for the delay. I think the best way to test any approach is to raise a pr to try to get it working. The immediate issues with this approach is that the current line break logic (ie Getting backward compatibility should be easier. We can keep |
Context: A multi-line text input or a text editor - the text in question is rarely stored as a
&'a str
, because such a representation is inefficient for insert operations. Instead something like a Rope would be used.My immediate thought is that it would be nice for glyph_brush to consume an iterator representing text (like
ropey::iter::Chars
).Wdyt is the right approach for layout here without spraying the heap with
str
?The text was updated successfully, but these errors were encountered: