Skip to content

Commit

Permalink
Add Section::from(text) impls
Browse files Browse the repository at this point in the history
  • Loading branch information
alexheretic committed Feb 21, 2023
1 parent 3852109 commit 8d0b230
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions glyph-brush/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Allow `Text::new` to work with any `X` type. **This may break usage**, however it will hopefully be non-breaking in practice as the compiler should always be able to infer this.
* Add `Section::builder` for more flexible `X`/"extra" type usage than `Section::default`.
* Add more flexible `X` type usage to `GlyphBrush::keep_cached`.
* Add `Section::from(text)` & `Section::from(vec![text])` conversions.
* Update `GlyphCruncher::glyphs`, `GlyphCruncher::glyph_bounds` docs.

# v0.7.6
Expand Down
15 changes: 15 additions & 0 deletions glyph-brush/src/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,27 @@ impl<'a, X> Section<'a, X> {
}

impl Section<'_, ()> {
/// Return a `SectionBuilder` to fluently build up a `Section`.
#[inline]
pub fn builder() -> SectionBuilder {
<_>::default()
}
}

impl<'a, X> From<Text<'a, X>> for Section<'a, X> {
#[inline]
fn from(text: Text<'a, X>) -> Self {
Section::builder().add_text(text)
}
}

impl<'a, X> From<Vec<Text<'a, X>>> for Section<'a, X> {
#[inline]
fn from(text: Vec<Text<'a, X>>) -> Self {
Section::builder().with_text(text)
}
}

impl<'a, X> Section<'a, X> {
#[inline]
pub fn with_screen_position<P: Into<(f32, f32)>>(mut self, position: P) -> Self {
Expand Down
2 changes: 2 additions & 0 deletions glyph-brush/src/section/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use crate::{Section, Text};
use glyph_brush_layout::{BuiltInLineBreaker, Layout};

/// [`Section`] builder.
///
/// Usage can avoid generic `X` type issues as it's not mentioned until text is involved.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SectionBuilder {
/// Position on screen to render text, in pixels from top-left. Defaults to (0, 0).
Expand Down

0 comments on commit 8d0b230

Please sign in to comment.