Text and RichText take a font face the host loaded itself, for hosts that resolve their own system families
CI / build + test (push) Canceled after 0s
CI / cargo audit (push) Canceled after 0s

`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:
2026-10-18 18:01:18 +02:00
parent ef6847b12c
commit 4c7e73d492
3 changed files with 38 additions and 0 deletions
+15
View File
@@ -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 )