From 4f785cb28bf87327e82ca17c7d3cd29d196f91a2 Mon Sep 17 00:00:00 2001 From: Avi Weinstock Date: Tue, 21 Feb 2023 03:43:16 -0500 Subject: [PATCH 1/2] Make several type signatures more permissive of downstream `Extra` structs. --- glyph-brush/src/glyph_brush.rs | 6 ++++-- glyph-brush/src/legacy.rs | 2 +- glyph-brush/src/section.rs | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/glyph-brush/src/glyph_brush.rs b/glyph-brush/src/glyph_brush.rs index 3f87c11..f694787 100644 --- a/glyph-brush/src/glyph_brush.rs +++ b/glyph-brush/src/glyph_brush.rs @@ -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>>, + S: Into>>, G: GlyphPositioner, + X: 'a, { if !self.cache_glyph_positioning { return; @@ -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>>, + S: Into>>, + X: 'a, { let section = section.into(); let layout = section.layout; diff --git a/glyph-brush/src/legacy.rs b/glyph-brush/src/legacy.rs index 8e69d28..5abdc08 100644 --- a/glyph-brush/src/legacy.rs +++ b/glyph-brush/src/legacy.rs @@ -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::::default() .with_layout(s.layout) .with_bounds(s.bounds) .with_screen_position(s.screen_position) diff --git a/glyph-brush/src/section.rs b/glyph-brush/src/section.rs index 510177c..0e1263a 100644 --- a/glyph-brush/src/section.rs +++ b/glyph-brush/src/section.rs @@ -40,7 +40,7 @@ impl Section<'_, X> { } } -impl Default for Section<'static, Extra> { +impl Default for Section<'static, X> { #[inline] fn default() -> Self { Section::new() @@ -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>(mut self, color: C) -> Self { self.extra.color = color.into(); From 5f4c8a90cf053308aa85bb4c21795244b87f8273 Mon Sep 17 00:00:00 2001 From: Alex Butler Date: Tue, 21 Feb 2023 10:17:53 +0000 Subject: [PATCH 2/2] Fix compilation --- glyph-brush/src/glyph_brush.rs | 3 ++- glyph-brush/src/glyph_calculator.rs | 14 +++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/glyph-brush/src/glyph_brush.rs b/glyph-brush/src/glyph_brush.rs index f694787..83be2fe 100644 --- a/glyph-brush/src/glyph_brush.rs +++ b/glyph-brush/src/glyph_brush.rs @@ -831,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 ")) diff --git a/glyph-brush/src/glyph_calculator.rs b/glyph-brush/src/glyph_calculator.rs index 8f8725d..1d7256d 100644 --- a/glyph-brush/src/glyph_calculator.rs +++ b/glyph-brush/src/glyph_calculator.rs @@ -106,7 +106,7 @@ pub trait GlyphCruncher { /// 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")); /// @@ -354,7 +354,7 @@ impl GlyphCalculatorBuilder { } #[derive(Debug, Clone, PartialEq)] -pub(crate) struct GlyphedSection { +pub(crate) struct GlyphedSection { pub bounds: Rect, pub glyphs: Vec, pub extra: Vec, @@ -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::(); let mut glyphs = glyphs.cache_scope(); let scale = PxScale::from(16.0); @@ -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::(); let mut glyphs = glyphs.cache_scope(); let section = Section::default() @@ -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 = @@ -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 = @@ -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"));