Text and RichText take a font face the host loaded itself, for hosts that resolve their own system families
`Text` and `RichText` could only draw in a theme family, named by `(family, weight, style)` and resolved through the active theme's font registry, or in the canvas default. A host that finds its fonts elsewhere could not use them: rustdroid draws Android's sans-serif, which is Roboto looked up through fontconfig, so that an app's text keeps the widths it was designed with, and those faces are not in any ltk theme. Both widgets gain `face( Arc<FontFace> )`. A face given this way takes precedence over `font` in `resolve_font`, so it is used for drawing and for measuring alike, and `RichText::map` carries it over. Without it nothing changes. .gitignore lists what a Debian package build leaves under debian/: the debhelper directories and logs, the staged package trees of libltk-dev, libltk-doc and ltk-theme-default, the build stamp, debian/files and the substvars.
This commit is contained in:
@@ -39,6 +39,7 @@ pub struct RichText<Msg: Clone>
|
||||
pub( crate ) color: Color,
|
||||
pub( crate ) link_color: Color,
|
||||
pub( crate ) font: Option<( String, u16, FontStyle )>,
|
||||
pub( crate ) face: Option<Arc<FontFace>>,
|
||||
pub( crate ) align: TextAlign,
|
||||
pub( crate ) links: Vec<LinkSpan<Msg>>,
|
||||
}
|
||||
@@ -56,6 +57,7 @@ impl<Msg: Clone> RichText<Msg>
|
||||
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<Msg: Clone> RichText<Msg>
|
||||
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<FontFace> ) -> Self
|
||||
{
|
||||
self.face = Some( face );
|
||||
self
|
||||
}
|
||||
|
||||
fn resolve_font( &self, canvas: &Canvas ) -> Option<Arc<FontFace>>
|
||||
{
|
||||
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<Msg: Clone> RichText<Msg>
|
||||
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(),
|
||||
}
|
||||
|
||||
@@ -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<Arc<FontFace>>,
|
||||
/// 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<FontFace> ) -> 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<Arc<FontFace>>
|
||||
{
|
||||
if let Some( face ) = &self.face
|
||||
{
|
||||
return Some( face.clone() );
|
||||
}
|
||||
self.font.as_ref().map( |( family, weight, style )|
|
||||
{
|
||||
canvas.font_for( family, *weight, *style )
|
||||
|
||||
Reference in New Issue
Block a user