diff --git a/.gitignore b/.gitignore index 1e7caa9..3795acf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,11 @@ Cargo.lock target/ +/debian/.debhelper/ +/debian/libltk-dev/ +/debian/libltk-doc/ +/debian/ltk-theme-default/ +/debian/debhelper-build-stamp +/debian/files +/debian/*.substvars +/debian/*.debhelper +/debian/*.debhelper.log diff --git a/src/widget/rich_text/mod.rs b/src/widget/rich_text/mod.rs index f438140..9cb0058 100644 --- a/src/widget/rich_text/mod.rs +++ b/src/widget/rich_text/mod.rs @@ -39,6 +39,7 @@ pub struct RichText pub( crate ) color: Color, pub( crate ) link_color: Color, pub( crate ) font: Option<( String, u16, FontStyle )>, + pub( crate ) face: Option>, pub( crate ) align: TextAlign, pub( crate ) links: Vec>, } @@ -56,6 +57,7 @@ impl RichText color: Color::WHITE, link_color: Color::rgb( 0.20, 0.50, 0.95 ), font: None, + face: None, align: TextAlign::Left, links: Vec::new(), } @@ -120,8 +122,19 @@ impl RichText canvas.resolve_font( self.size ) } + /// Draw and measure with `face`, a font the caller loaded itself, instead of a theme family. + pub fn face( mut self, face: Arc ) -> Self + { + self.face = Some( face ); + self + } + fn resolve_font( &self, canvas: &Canvas ) -> Option> { + if let Some( face ) = &self.face + { + return Some( face.clone() ); + } self.font.as_ref().map( |( family, weight, style )| canvas.font_for( family, *weight, *style ) ) } @@ -213,6 +226,7 @@ impl RichText color: self.color, link_color: self.link_color, font: self.font, + face: self.face, align: self.align, links: self.links.into_iter().map( |l| LinkSpan { start: l.start, end: l.end, msg: f( l.msg ) } ).collect(), } diff --git a/src/widget/text/mod.rs b/src/widget/text/mod.rs index 8ecde1a..dd7e94b 100644 --- a/src/widget/text/mod.rs +++ b/src/widget/text/mod.rs @@ -51,6 +51,8 @@ pub struct Text /// the active theme's font registry on every draw. `None` keeps /// the canvas default font (Sora Regular in `ltk-theme-default`). pub( crate ) font: Option<( String, u16, FontStyle )>, + /// A caller-supplied face that takes precedence over [`Self::font`]. + pub( crate ) face: Option>, /// Multiplier applied to the font's natural line height when wrapping /// onto multiple lines. `1.0` (default) uses the font-declared leading; /// values above `1.0` open up the gap between wrapped lines. @@ -72,6 +74,7 @@ impl Text wrap: false, truncate: true, font: None, + face: None, line_height: 1.0, } } @@ -103,6 +106,14 @@ impl Text self } + /// Draw and measure with `face`, a font the caller loaded itself (a host + /// that resolves its own system families), instead of a theme family. + pub fn face( mut self, face: Arc ) -> Self + { + self.face = Some( face ); + self + } + /// Shorthand for [`Self::font`] when the desired override is just /// a weight on the default Sora family (the family `ltk-theme- /// default` declares). @@ -162,6 +173,10 @@ impl Text fn resolve_font( &self, canvas: &Canvas ) -> Option> { + if let Some( face ) = &self.face + { + return Some( face.clone() ); + } self.font.as_ref().map( |( family, weight, style )| { canvas.font_for( family, *weight, *style )