mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-03 05:12:55 +00:00
Rust: Don't get the default font size through the root component
Planning for multi-component support
This commit is contained in:
parent
a00e3361ac
commit
4cc6337c42
5 changed files with 19 additions and 13 deletions
|
|
@ -533,6 +533,7 @@ fn gen_corelib(
|
||||||
"slint_windowrc_set_logical_size",
|
"slint_windowrc_set_logical_size",
|
||||||
"slint_windowrc_set_physical_size",
|
"slint_windowrc_set_physical_size",
|
||||||
"slint_windowrc_color_scheme",
|
"slint_windowrc_color_scheme",
|
||||||
|
"slint_windowrc_default_font_size",
|
||||||
"slint_windowrc_dispatch_pointer_event",
|
"slint_windowrc_dispatch_pointer_event",
|
||||||
"slint_windowrc_dispatch_key_event",
|
"slint_windowrc_dispatch_key_event",
|
||||||
"slint_windowrc_dispatch_event",
|
"slint_windowrc_dispatch_event",
|
||||||
|
|
|
||||||
|
|
@ -221,6 +221,11 @@ public:
|
||||||
cbindgen_private::slint_register_bitmap_font(&inner, &font);
|
cbindgen_private::slint_register_bitmap_font(&inner, &font);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline float default_font_size() const
|
||||||
|
{
|
||||||
|
return cbindgen_private::slint_windowrc_default_font_size(&inner);
|
||||||
|
}
|
||||||
|
|
||||||
/// \private
|
/// \private
|
||||||
const cbindgen_private::WindowAdapterRcOpaque &handle() const { return inner; }
|
const cbindgen_private::WindowAdapterRcOpaque &handle() const { return inner; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2528,7 +2528,6 @@ fn access_window_field(ctx: &EvaluationContext) -> String {
|
||||||
/// let access = access_member(...);
|
/// let access = access_member(...);
|
||||||
/// format!("{access}(...)")
|
/// format!("{access}(...)")
|
||||||
/// ```
|
/// ```
|
||||||
|
|
||||||
fn access_member(reference: &llr::PropertyReference, ctx: &EvaluationContext) -> String {
|
fn access_member(reference: &llr::PropertyReference, ctx: &EvaluationContext) -> String {
|
||||||
fn in_native_item(
|
fn in_native_item(
|
||||||
ctx: &EvaluationContext,
|
ctx: &EvaluationContext,
|
||||||
|
|
@ -3076,15 +3075,10 @@ fn compile_builtin_function_call(
|
||||||
|
|
||||||
match function {
|
match function {
|
||||||
BuiltinFunction::GetWindowScaleFactor => {
|
BuiltinFunction::GetWindowScaleFactor => {
|
||||||
let window = access_window_field(ctx);
|
format!("{}.scale_factor()", access_window_field(ctx))
|
||||||
format!("{}.scale_factor()", window)
|
|
||||||
}
|
}
|
||||||
BuiltinFunction::GetWindowDefaultFontSize => {
|
BuiltinFunction::GetWindowDefaultFontSize => {
|
||||||
let window_item_name = ident(&ctx.public_component.item_tree.root.items[0].name);
|
format!("{}.default_font_size()", access_window_field(ctx))
|
||||||
format!(
|
|
||||||
"{}->{}.default_font_size.get()",
|
|
||||||
ctx.generator_state.root_access, window_item_name
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
BuiltinFunction::AnimationTick => "slint::cbindgen_private::slint_animation_tick()".into(),
|
BuiltinFunction::AnimationTick => "slint::cbindgen_private::slint_animation_tick()".into(),
|
||||||
BuiltinFunction::Debug => {
|
BuiltinFunction::Debug => {
|
||||||
|
|
|
||||||
|
|
@ -2582,11 +2582,8 @@ fn compile_builtin_function_call(
|
||||||
quote!(sp::WindowInner::from_pub(#window_adapter_tokens.window()).scale_factor())
|
quote!(sp::WindowInner::from_pub(#window_adapter_tokens.window()).scale_factor())
|
||||||
}
|
}
|
||||||
BuiltinFunction::GetWindowDefaultFontSize => {
|
BuiltinFunction::GetWindowDefaultFontSize => {
|
||||||
let window_item_name = ident(&ctx.public_component.item_tree.root.items[0].name);
|
let window_adapter_tokens = access_window_adapter_field(ctx);
|
||||||
let root_access = &ctx.generator_state;
|
quote!(sp::WindowInner::from_pub(#window_adapter_tokens.window()).window_item().unwrap().as_pin_ref().default_font_size().get())
|
||||||
let root_component_id = inner_component_id(&ctx.public_component.item_tree.root);
|
|
||||||
let item_field = access_component_field_offset(&root_component_id, &window_item_name);
|
|
||||||
quote!((#item_field + sp::WindowItem::FIELD_OFFSETS.default_font_size).apply_pin(#root_access.as_pin_ref()).get().get())
|
|
||||||
}
|
}
|
||||||
BuiltinFunction::AnimationTick => {
|
BuiltinFunction::AnimationTick => {
|
||||||
quote!(sp::animation_tick())
|
quote!(sp::animation_tick())
|
||||||
|
|
|
||||||
|
|
@ -1476,6 +1476,15 @@ pub mod ffi {
|
||||||
.map_or(ColorScheme::Unknown, |x| x.color_scheme())
|
.map_or(ColorScheme::Unknown, |x| x.color_scheme())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the default-font-size property of the WindowItem
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn slint_windowrc_default_font_size(
|
||||||
|
handle: *const WindowAdapterRcOpaque,
|
||||||
|
) -> f32 {
|
||||||
|
let window_adapter = &*(handle as *const Rc<dyn WindowAdapter>);
|
||||||
|
window_adapter.window().0.window_item().unwrap().as_pin_ref().default_font_size().get()
|
||||||
|
}
|
||||||
|
|
||||||
/// Dispatch a key pressed or release event
|
/// Dispatch a key pressed or release event
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn slint_windowrc_dispatch_key_event(
|
pub unsafe extern "C" fn slint_windowrc_dispatch_key_event(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue