Skip to content
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

Make several type signatures more permissive of downstream Extra st… #162

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions glyph-brush/src/glyph_brush.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,9 @@ where
/// Should not generally be necessary, see [caching behaviour](#caching-behaviour).
pub fn keep_cached_custom_layout<'a, S, G>(&mut self, section: S, custom_layout: &G)
where
S: Into<Cow<'a, Section<'a>>>,
S: Into<Cow<'a, Section<'a, X>>>,
G: GlyphPositioner,
X: 'a,
{
if !self.cache_glyph_positioning {
return;
Expand All @@ -393,7 +394,8 @@ where
/// Should not generally be necessary, see [caching behaviour](#caching-behaviour).
pub fn keep_cached<'a, S>(&mut self, section: S)
where
S: Into<Cow<'a, Section<'a>>>,
S: Into<Cow<'a, Section<'a, X>>>,
X: 'a,
{
let section = section.into();
let layout = section.layout;
Expand Down Expand Up @@ -829,7 +831,8 @@ mod glyph_brush_test {
let font_b = FontRef::try_from_slice(include_bytes!("../../fonts/Exo2-Light.otf")).unwrap();
let unqueued_glyph = font_a.glyph_id('c').with_scale(50.0);

let mut brush = GlyphBrushBuilder::using_fonts(vec![font_a, font_b]).build();
let mut brush: GlyphBrush<_, (), _> =
GlyphBrushBuilder::using_fonts(vec![font_a, font_b]).build();

let section = Section::default()
.add_text(Text::new("a "))
Expand Down
14 changes: 7 additions & 7 deletions glyph-brush/src/glyph_calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub trait GlyphCruncher<F: Font = FontArc, X: Clone = Extra> {
/// use glyph_brush::{ab_glyph::FontArc, GlyphCalculatorBuilder, GlyphCruncher, Section, Text};
///
/// let dejavu = FontArc::try_from_slice(include_bytes!("../../fonts/DejaVuSans.ttf")).unwrap();
/// let glyphs = GlyphCalculatorBuilder::using_font(dejavu).build();
/// let glyphs = GlyphCalculatorBuilder::using_font(dejavu).build::<()>();
///
/// let section = Section::default().add_text(Text::new("Hello glyph_brush"));
///
Expand Down Expand Up @@ -354,7 +354,7 @@ impl<F: Font, H: BuildHasher> GlyphCalculatorBuilder<F, H> {
}

#[derive(Debug, Clone, PartialEq)]
pub(crate) struct GlyphedSection<X = Extra> {
pub(crate) struct GlyphedSection<X> {
pub bounds: Rect,
pub glyphs: Vec<SectionGlyph>,
pub extra: Vec<X>,
Expand Down Expand Up @@ -383,7 +383,7 @@ mod test {

#[test]
fn glyph_bounds() {
let glyphs = GlyphCalculatorBuilder::using_font(MONO_FONT.clone()).build();
let glyphs = GlyphCalculatorBuilder::using_font(MONO_FONT.clone()).build::<Extra>();
let mut glyphs = glyphs.cache_scope();

let scale = PxScale::from(16.0);
Expand Down Expand Up @@ -411,7 +411,7 @@ mod test {

#[test]
fn glyph_bounds_respect_layout_bounds() {
let glyphs = GlyphCalculatorBuilder::using_font(MONO_FONT.clone()).build();
let glyphs = GlyphCalculatorBuilder::using_font(MONO_FONT.clone()).build::<Extra>();
let mut glyphs = glyphs.cache_scope();

let section = Section::default()
Expand Down Expand Up @@ -481,7 +481,7 @@ mod test {
/// Issue #87
#[test]
fn glyph_bound_section_bound_consistency() {
let calc = GlyphCalculatorBuilder::using_font(OPEN_SANS_LIGHT.clone()).build();
let calc = GlyphCalculatorBuilder::using_font(OPEN_SANS_LIGHT.clone()).build::<()>();
let mut calc = calc.cache_scope();

let section =
Expand All @@ -506,7 +506,7 @@ mod test {
/// Issue #87
#[test]
fn glyph_bound_section_bound_consistency_trailing_space() {
let calc = GlyphCalculatorBuilder::using_font(OPEN_SANS_LIGHT.clone()).build();
let calc = GlyphCalculatorBuilder::using_font(OPEN_SANS_LIGHT.clone()).build::<()>();
let mut calc = calc.cache_scope();

let section =
Expand All @@ -532,7 +532,7 @@ mod test {
/// error between the calculated glyph_bounds bounds & those used during layout.
#[test]
fn glyph_bound_section_bound_consistency_floating_point() {
let calc = GlyphCalculatorBuilder::using_font(MONO_FONT.clone()).build();
let calc = GlyphCalculatorBuilder::using_font(MONO_FONT.clone()).build::<()>();
let mut calc = calc.cache_scope();

let section = Section::default().add_text(Text::new("Eins Zwei Drei Vier Funf"));
Expand Down
2 changes: 1 addition & 1 deletion glyph-brush/src/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl From<&VariedSection<'_>> for SectionGeometry {
impl<'a> From<&VariedSection<'a>> for crate::Section<'a> {
#[inline]
fn from(s: &VariedSection<'a>) -> Self {
crate::Section::default()
crate::Section::<Extra>::default()
.with_layout(s.layout)
.with_bounds(s.bounds)
.with_screen_position(s.screen_position)
Expand Down
6 changes: 4 additions & 2 deletions glyph-brush/src/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl<X: Clone> Section<'_, X> {
}
}

impl Default for Section<'static, Extra> {
impl<X> Default for Section<'static, X> {
#[inline]
fn default() -> Self {
Section::new()
Expand Down Expand Up @@ -196,12 +196,14 @@ impl<'a, X> Text<'a, X> {
}
}

impl<'a> Text<'a, Extra> {
impl<'a, X: Default> Text<'a, X> {
#[inline]
pub fn new(text: &'a str) -> Self {
Text::default().with_text(text)
}
}

impl<'a> Text<'a, Extra> {
#[inline]
pub fn with_color<C: Into<Color>>(mut self, color: C) -> Self {
self.extra.color = color.into();
Expand Down