Add support for a font-metrics property to Text/TextInput. (#6452)

The struct held provides access to the design metrics of the font scaled
to the font pixel size used by the element.

ChangeLog: Slint Language: Added font-metrics property to `Text` and `TextInput`.

Closes #6047
This commit is contained in:
Simon Hausmann 2024-10-05 17:00:46 +02:00 committed by GitHub
parent b41b389e55
commit 0b028bfb6f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
36 changed files with 742 additions and 55 deletions

View file

@ -899,6 +899,8 @@ fn embed_resource(
units_per_em,
ascent,
descent,
x_height,
cap_height,
glyphs,
weight,
italic,
@ -998,6 +1000,8 @@ fn embed_resource(
.units_per_em = {units_per_em},
.ascent = {ascent},
.descent = {descent},
.x_height = {x_height},
.cap_height = {cap_height},
.glyphs = slint::cbindgen_private::Slice<slint::cbindgen_private::BitmapGlyphs>{{ {glyphsets_var}, {glyphsets_size} }},
.weight = {weight},
.italic = {italic},
@ -3542,6 +3546,15 @@ fn compile_builtin_function_call(
panic!("internal error: invalid args to ItemMemberFunction {:?}", arguments)
}
}
BuiltinFunction::ItemFontMetrics => {
if let [llr::Expression::PropertyReference(pr)] = arguments {
let item_rc = access_item_rc(pr, ctx);
let window = access_window_field(ctx);
format!("slint_cpp_text_item_fontmetrics(&{window}.handle(), &{item_rc})")
} else {
panic!("internal error: invalid args to ItemFontMetrics {:?}", arguments)
}
}
BuiltinFunction::ItemAbsolutePosition => {
if let [llr::Expression::PropertyReference(pr)] = arguments {
let item_rc = access_item_rc(pr, ctx);